The Decision Framework
Advanced DynamoDB modeling is not about memorizing patterns — it is about matching the right pattern to the right problem. Here is a practical decision guide:
Use Adjacency Lists when:
- You have Many-to-Many relationships (social graphs, permissions, enrollments).
- You need to traverse relationships in both directions.
- You want to fetch an entity and its relationships in a single query.
Use Inverted Index (GSI with flipped keys) when:
- You need to traverse a relationship in the reverse direction.
- The forward direction is served by the main table's PK/SK.
- Example: "Who follows Alice?" when the main table answers "Who does Alice follow?"
Use Write Sharding when:
- A single Partition Key receives more than ~800 writes/second (leave headroom below the 1,000 WCU limit).
- The hot key is predictable (a known popular item, a leaderboard entry, a live event counter).
- You can tolerate client-side aggregation on reads.
Use Sparse Indexes when:
- You need to query a small, dynamic subset of items (open orders, pending jobs, flagged content).
- The subset membership changes over time (items enter and leave the subset).
- A full table scan or a fat GSI would be prohibitively expensive.
The Patterns Are Composable
Real-world DynamoDB schemas often combine multiple patterns. A social platform might use:
- Adjacency lists for the follower graph.
- Inverted index to answer "who follows me?".
- Write sharding for celebrity accounts with millions of followers writing simultaneously.
- Sparse indexes to surface only accounts currently flagged for review.
The skill is recognizing which problem each pattern solves and applying them in combination without creating conflicting access patterns.
When asked "design a DynamoDB schema for X", interviewers are evaluating whether you start from access patterns, not from entities. The correct approach: (1) list every query the application needs to support, (2) design PK/SK to serve the most frequent queries directly, (3) add GSIs for secondary access patterns, (4) apply sharding or sparse indexes where the base design has hot spots or expensive scans. Saying "I'd start by listing the access patterns" immediately signals senior-level DynamoDB fluency.