Access-Pattern-First Data Modeling
Relational design starts with entities and normalisation, then writes queries.
Introduction
Relational design starts with entities and normalisation, then writes queries. DynamoDB design runs the other way: list every way the application reads and writes data, then choose keys so each pattern becomes one efficient request.
In this lesson you will build the access-pattern table for the course's e-commerce application. That table is the specification every later lesson implements.
Purpose of this lesson
You will learn to gather access patterns, describe each one precisely (inputs, sort order, filters, volume), and map them to key designs before writing any code.
Understanding the topic
Describe each access pattern with:
- Who calls it — which screen, API, or job.
- Inputs known at request time — these become key values.
- Result shape — one item, a list, or a list with related entities.
- Sort order and limits — for example newest first, 20 per page.
- Frequency and latency target — which patterns are hot and must be single-request.
| # | Access pattern | Key design |
|---|---|---|
| 1 | Get customer profile by id | GetItem PK=CUSTOMER#id, SK=PROFILE |
| 2 | List a customer's orders, newest first | Query PK=CUSTOMER#id, SK begins_with ORDER#, descending |
| 3 | Get an order with its line items | Query PK=ORDER#id |
| 4 | Get product by id | GetItem PK=PRODUCT#id, SK=PRODUCT |
| 5 | List orders by status for the warehouse | GSI (Module 3) |
| 6 | Look up customer by email at login | GSI or uniqueness item (Module 3 / Module 5) |
Step-by-step explanation
- Interview product owners and read the UI flows; write each read and write as a sentence.
- Mark the inputs available at request time — those are your candidate key values.
- Group patterns that return related data together; they are candidates for one item collection.
- Assign base-table keys to the hottest patterns; leave the rest for secondary indexes.
- Estimate volume per pattern to spot hot keys before they exist.
- Review the table with the team and keep it in the repository next to the code.
Informative example
Keep the access-pattern spec in code so tests can check that every pattern is implemented:
export const accessPatterns = [{ id: 1, name: "getCustomer", op: "GetItem", key: "PK=CUSTOMER#<id>, SK=PROFILE" },{ id: 2, name: "listCustomerOrders", op: "Query", key: "PK=CUSTOMER#<id>, SK begins_with ORDER#", order: "desc" },{ id: 3, name: "getOrderWithLines", op: "Query", key: "PK=ORDER#<id>" },{ id: 4, name: "getProduct", op: "GetItem", key: "PK=PRODUCT#<id>, SK=PRODUCT" },{ id: 5, name: "listOrdersByStatus", op: "Query", index: "GSI1", key: "GSI1PK=STATUS#<status>" },{ id: 6, name: "findCustomerByEmail", op: "Query", index: "GSI2", key: "GSI2PK=EMAIL#<email>" },] as const;for (const p of accessPatterns) console.log(`${p.id}. ${p.name} -> ${p.op}`);
Output
1. getCustomer -> GetItem 2. listCustomerOrders -> Query 3. getOrderWithLines -> Query 4. getProduct -> GetItem 5. listOrdersByStatus -> Query 6. findCustomerByEmail -> Query
Decision framework
- If a pattern needs a value you do not know at request time, it needs a different key or an index.
- If a pattern is rare and offline (monthly report), export to S3 and use Athena rather than adding an index.
- If patterns change weekly, DynamoDB may not be the right primary store for that data.
Best practices
- Write access patterns before creating the table.
- Name every pattern and give it a test.
- Prefer GetItem and Query; treat Scan as a maintenance tool.
Common mistakes
- Starting from an ER diagram and creating one table per entity.
- Forgetting write patterns — uniqueness checks and counters shape keys too.
- Leaving pagination and sort order out of the spec.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1IntermediateQuestionWhy can't you add access patterns later as easily as in SQL?+
Answer
2AdvancedQuestionWhat do you do with access patterns that need ad-hoc filtering or aggregation?+
Answer
Hands-on exercise
Hands-on: extend the access-pattern table with three patterns of your own (for example “list reviews for a product, newest first”, “get the latest cart for a customer”, “list orders shipped on a date”). For each, write the operation, the key condition, and whether it needs an index.
Summary
DynamoDB modeling starts with a precise list of access patterns. Each pattern names its inputs, result shape, order, and volume, and maps to a GetItem, Query, or index.