Single-TableKey OverloadingAdjacency ListHierarchicalComposite KeysAccess Patterns

Primary Key & Single-Table Design

The most important skill in DynamoDB. Every other decision — indexes, capacity, performance — flows from your primary key design.

50 min read9 sections
01

Access Pattern Analysis

In , you model entities first and figure out queries later. In DynamoDB, you do the opposite: list every query your application needs first, then design your table to serve them.

🔑 The Required First Step

Before creating a DynamoDB table, write down every access pattern. For each: what are the inputs? What is returned? How frequently is it called? If a pattern cannot be served efficiently by your key design, you must either add a or reconsider the model.

Example: E-Commerce Application

access-patterns.txttext
Access Pattern Analysis:
─────────────────────────────────────────────────────────────
Pattern                          | Input        | Frequency
─────────────────────────────────────────────────────────────
Get user profile                 | userId       | High
Get all orders for a user        | userId       | High
Get specific order               | orderId      | Medium
Get orders by date range         | userId+dates | Medium
Get all items in an order        | orderId      | Medium
Get user's recent 10 orders      | userId       | High
Find orders by status (pending)  | status       | Low (admin)
─────────────────────────────────────────────────────────────

Key Design Decision:
  PK = USER#<userId>
  SK = USER#<userId>         → user profile
  SK = ORDER#<timestamp>#<orderId> → orders (sorted by time)
  
  GSI1: PK = ORDER#<orderId>, SK = ITEM#<itemId> → order items
📐

The Architect's Blueprint

You wouldn't build a house and then decide where the plumbing goes. In DynamoDB, your access patterns are the blueprint. The table design is the house built to serve those patterns. Changing the blueprint after construction means demolishing and rebuilding — that's why access pattern analysis comes first, always.

1 / 9