Dynamodb hard
To model 'Followers/Following' relationships in a social app, an engineer uses a GSI with 'Inverted Keys' (Adjacency List). Why is this more efficient than using a JSON array of UserIDs?
- A It allows the application to use the `JOIN` command in the SDK.
- B Infinite Scalability: A JSON array is limited by the 400KB item limit (approx 10,000 IDs). An Adjacency List stores each relationship as a separate item, allowing a user to have millions of followers that can be paginated and queried efficiently via the GSI.
- C It reduces the write cost because indexes are updated in a background low-priority queue.
- D JSON arrays in DynamoDB are not searchable via Query.
Answer: B. Infinite Scalability: A JSON array is limited by the 400KB item limit (approx 10,000 IDs). An Adjacency List stores each relationship as a separate item, allowing a user to have millions of followers that can be paginated and queried efficiently via the GSI.
In many-to-many modeling, 'List' attributes are a scaling trap ($O(N)$ write cost and 400KB size limit). The Adjacency List pattern transforms relationships into 'Items'. By swapping PK/SK in a GSI, you can query both 'Who am I following?' (Base Table) and 'Who follows me?' (GSI) using high-performance paginated queries regardless of count.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- DynamoDB has a strict 400KB limit on the size of a single item. What is the recommended design pattern if you need to store larger documents (e.g., 5MB PDFs)?
- What is the primary role of the 'Partition Key' in ensuring DynamoDB's infinite horizontal scalability?
- Why is the `Query` operation generally preferred over `Scan` for production workloads in DynamoDB?
- DynamoDB is a 'fully managed' serverless database. What is a primary operational benefit of this model for an engineering team?
- In 'Provisioned Capacity' mode, how is the performance budget of a DynamoDB table defined?
- When would an architect choose to implement DAX (DynamoDB Accelerator) in front of an existing DynamoDB table?