Amazon DynamoDB Tutorial 0/30 lessons ~6 min read Lesson 8

    Access-Pattern-First Data Modeling

    Relational design starts with entities and normalisation, then writes queries.

    Course progress0%
    Focus
    11 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    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 patternKey design
    1Get customer profile by idGetItem PK=CUSTOMER#id, SK=PROFILE
    2List a customer's orders, newest firstQuery PK=CUSTOMER#id, SK begins_with ORDER#, descending
    3Get an order with its line itemsQuery PK=ORDER#id
    4Get product by idGetItem PK=PRODUCT#id, SK=PRODUCT
    5List orders by status for the warehouseGSI (Module 3)
    6Look up customer by email at loginGSI or uniqueness item (Module 3 / Module 5)

    Step-by-step explanation

    1. Interview product owners and read the UI flows; write each read and write as a sentence.
    2. Mark the inputs available at request time — those are your candidate key values.
    3. Group patterns that return related data together; they are candidates for one item collection.
    4. Assign base-table keys to the hottest patterns; leave the rest for secondary indexes.
    5. Estimate volume per pattern to spot hot keys before they exist.
    6. 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:

    ts
    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.

    2 questions
    1IntermediateQuestionWhy can't you add access patterns later as easily as in SQL?+

    Answer

    SQL can answer new questions with new queries and joins over normalised tables. DynamoDB only answers efficiently the questions its keys and indexes were designed for. New patterns may need a new GSI, a backfill of new attributes, or a data migration.
    2AdvancedQuestionWhat do you do with access patterns that need ad-hoc filtering or aggregation?+

    Answer

    Serve them outside the main table: export to S3 for Athena, stream changes to OpenSearch for search, or maintain pre-computed aggregates updated by Streams.

    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.

    Ready to mark this lesson complete?Track your journey across the entire course.