Amazon DynamoDB Data Modeling: Start with Access Patterns
Design DynamoDB tables from concrete access patterns with a worked orders example, a global secondary index, capacity estimates, and a throttling failure.
Start with the requests the application must answer, then choose the base key and index. One orders example works through capacity assumptions and the back-pressure risk a status-based GSI can create.
Amazon DynamoDB Data Modeling: Start with Access Patterns
DynamoDB table design starts with the reads and writes an application needs. Here, customer order history and an operations queue drive the keys, index, and first capacity estimate. For the work that begins after the model is in place, see the DynamoDB operations guide.
Start with an access-pattern worksheet
Write down the requests before choosing attributes or indexes. Include the response shape, expected item sizes, request rate, and whether a stale read is acceptable. AWS’s DynamoDB data-modeling guide also starts from the use case before moving to keys and indexes.
| Request | Query shape to support | What to decide |
|---|---|---|
| Show a customer’s recent orders | Customer partition key; order timestamp range and descending order | Page size, time range, read consistency |
| List pending orders created during a time window | Status partition key; created-time range on an index | Expected skew, fields the operations view needs, index write rate |
Check that a key identifies the requested items and that a sort-key condition narrows the result. Also record whether the application can tolerate eventual consistency. A Query requires a partition-key value and can use the sort key to refine the result. AWS Query documentation describes the key-condition rules.
Work through an orders table
The examples below are illustrative. AWS documentation was checked on 2026-11-04. The capacity sketch assumes a table in us-east-1 and is not an AWS quota or price. Replace every rate and item-size assumption with measurements from your workload.
Choose the table keys
Use a composite primary key so one customer’s orders share a partition-key value and sort by their creation time:
PK:CUSTOMER#<customerId>SK:ORDER#<UTC timestamp at fixed millisecond precision>#<orderId>
An order might look like this:
{
"PK": "CUSTOMER#c123",
"SK": "ORDER#2026-11-04T09:30:00.000Z#o789",
"OrderId": "o789",
"CustomerId": "c123",
"CreatedAt": "2026-11-04T09:30:00.000Z",
"Status": "PENDING",
"Total": 129.99,
"GSI1PK": "STATUS#PENDING",
"GSI1SK": "2026-11-04T09:30:00.000Z"
}
The primary key handles the first request. A query for recent orders can use the customer key, an order prefix, and descending sort order:
{
"TableName": "Orders",
"KeyConditionExpression": "PK = :customer AND begins_with(SK, :prefix)",
"ExpressionAttributeValues": {
":customer": { "S": "CUSTOMER#c123" },
":prefix": { "S": "ORDER#" }
},
"ScanIndexForward": false,
"Limit": 5
}
The application can paginate the results instead of loading the customer’s full history at once. The sort key puts the UTC timestamp before the order ID, so entries for the same customer are ordered by creation time.
Add an index for pending work
Customer history cannot answer “show pending orders across all customers” efficiently. Add a global secondary index named OrdersByStatusAndTime:
GSI1PK:STATUS#PENDINGGSI1SK:<UTC timestamp at fixed millisecond precision>- Project the order ID, customer ID, and total needed by the operations view.
Set these GSI key attributes only while an order is pending. Items without the index key attributes do not appear in this sparse index; remove them when an order leaves the pending state. A query on the index can match GSI1PK = STATUS#PENDING and constrain GSI1SK to a time range. Global secondary indexes use a different key schema from the base table and can project selected attributes. AWS’s GSI guide covers index queries, projections, and consistency.
The operations query uses the index partition key and a sort-key range:
{
"TableName": "Orders",
"IndexName": "OrdersByStatusAndTime",
"KeyConditionExpression": "GSI1PK = :status AND GSI1SK BETWEEN :from AND :to",
"ExpressionAttributeValues": {
":status": { "S": "STATUS#PENDING" },
":from": { "S": "2026-11-01T00:00:00.000Z" },
":to": { "S": "2026-11-04T23:59:59.999Z" }
}
}
GSI reads are eventually consistent. If the operations screen needs a just-written order immediately, use another path for that confirmation rather than assuming the index has already caught up.
Estimate capacity from the example workload
These are planning calculations, not guaranteed service throughput. The AWS read/write guide defines capacity rounding: read sizes round to 4 KB and write sizes to 1 KB; an eventually consistent read uses half the read units of a strongly consistent read. A Query is calculated from the combined size of items read. See AWS read and write capacity consumption and the GSI capacity guidance.
Assume:
- 100 new orders per second. Each base-table item is at most 1 KB.
- Each new order is pending and creates an index entry at most 1 KB.
- A customer-history query reads five 2 KB items, and the application makes 20 such queries per second.
- A pending-orders query reads ten index entries of 0.5 KB each, at five queries per second. The 0.5 KB estimate is the total index-entry size, including keys, projected attributes, and index overhead.
- Both query paths use eventually consistent reads. The estimate excludes headroom, retries, status transitions, and other writes.
| Operation | Calculation | Initial estimate |
|---|---|---|
| Base-table order writes | 100 writes/s × 1 WCU for each item up to 1 KB | 100 WCU/s |
| GSI insertions | 100 index entries/s × 1 WCU for each entry up to 1 KB | 100 WCU/s on the GSI |
| Customer history | 5 × 2 KB = 10 KB; round to 12 KB; 0.5 RCU per 4 KB = 1.5 RCU/query; × 20 queries/s | 30 RCU/s on the table |
| Pending queue | 10 × 0.5 KB = 5 KB; round to 8 KB; 0.5 RCU per 4 KB = 1 RCU/query; × 5 queries/s | 5 RCU/s on the GSI |
The base table and GSI have separate provisioned throughput settings. Index entries add write consumption when an item enters, leaves, or changes in the index. These estimates omit such transitions, so they are only a starting point. For a stable, measured workload, evaluate provisioned capacity for the table and index separately. For a workload whose traffic is harder to predict, compare on-demand mode. AWS’s provisioned capacity guide and on-demand capacity guide explain the tradeoffs. Confirm settings with load tests and actual consumed-capacity metrics; don’t treat this sketch as a final setting.
Failure case: the GSI key is too concentrated
Suppose customer keys spread base-table writes across many customers, but a busy period sends most new orders into STATUS#PENDING. That’s the catch: a status key is convenient for queries, but a surge can concentrate nearly every new order on one GSI partition-key value. If the index cannot absorb its write activity, DynamoDB can throttle writes to the base table even when the base table itself has capacity. AWS documents this as GSI write back-pressure. AWS also recommends designing for uniform activity across table and index keys in its partition-key design guidance.
One option is to shard the GSI partition key, for example STATUS#PENDING#<bucket>, with the bucket derived consistently from an order or customer ID. This spreads writes but makes an operations query fan out across buckets and merge results by time. Choose the bucket scheme from measured write distribution and the query’s latency budget. If the operation is dispatching work rather than browsing it, a dedicated queue may fit better than making a table index serve both roles.
Continue from design into operations
This article focuses on keys, query shapes, index projection, and first-pass capacity math. The DynamoDB operations guide covers capacity tuning and autoscaling, retry procedures, DAX, Streams and TTL, Global Tables, backups, restore drills, and runbooks. For cross-database context, read NoSQL database models and the database design roadmap. The database monitoring guide covers monitoring patterns; the operations companion maps those ideas to DynamoDB throttling and index metrics.
Conclusion
The practical test is whether every request maps to a key condition and whether each index earns its write path. If the workload changes, revisit the worksheet before adding another index.
Category
Related Posts
DynamoDB Operations: Capacity, Backups, and Recovery
Choose a DynamoDB capacity mode, diagnose throttling, and plan backup and recovery steps with current AWS guidance for your workload.
NoSQL Databases: Document, Key-Value, Column-Family, Graph
Explore NoSQL database types, CAP theorem implications, and when to choose MongoDB, Cassandra, DynamoDB, or graph databases over relational systems.
Document Databases: MongoDB and CouchDB Data Modeling
Compare MongoDB and CouchDB data modeling, transactions, consistency settings, and replication behavior with relational databases.