Why this matters
- VaultCommerce order history needs "all orders for user X, newest first" — composite key
PK=USER#X,SK=ORDER#timestampsatisfies that in one Query. - Table scans read every partition and burn RCUs — acceptable only for small admin exports, never for customer-facing APIs.
- Hot partition keys (everyone writing
PK=FLASH_SALE) throttle the whole shard regardless of table size.
Partition key: USER#42Routes to shard
Items in partition
ORDER#2026-001Sort key
ORDER#2026-002Sort key
PROFILESort key
Design queries first
VaultCommerce access patterns
- Get order by user + order id —
GetItemonPK=USER#42,SK=ORDER#2026-0042. - List recent orders for user —
Query PK=USER#42,SK begins_with ORDER#,ScanIndexForward=false. - Record idempotency token —
PutItemwith conditionattribute_not_exists(PK). - Admin export (rare) —
Scanwith filter (last resort, off-peak only).
import boto3
from boto3.dynamodb.conditions import Key
table = boto3.resource("dynamodb").Table("VaultCommerceOrders")
def recent_orders(user_id: int, limit: int = 20):
return table.query(
KeyConditionExpression=Key("PK").eq(f"USER#{user_id}")
& Key("SK").begins_with("ORDER#"),
ScanIndexForward=False,
Limit=limit,
)["Items"]
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 2 sections
- Query vs Scan
- Capacity units
Test yourself
Answer these before moving on — recall is what makes it stick.