The pattern library
What does your
application need to ask?
Start with a question. Explore the keys, run the requests, and take the model into your own application.
Search covers what a model teaches, not only what it is called.
Exploring semantic search? Try the vector lab →
Start here
The primary key answers every read. No secondary index, nothing to keep in sync.
- key value lookup
Where does this short link go?
A hash-only table keyed by short code, the classic key-value lookup.
- PK
- <code>
- composite key
Which features are enabled here?
Flag values per environment, read one at a time or all at once.
- PK
- ENV#<env>
- SK
- FLAG#<key>
- time to live
Who owns this session?
Server-side sessions keyed by token, expired by the database.
- PK
- SESSION#<token>
- conditional write
Have we handled this request already?
A conditional write that makes a retried request safe.
- PK
- IDEMPOTENCY#<key>
- type discriminator
What are this account’s preferences?
Two entity types under one key, told apart by the sort key.
- PK
- USER#<userId>
- SK
- ACCOUNT
- item collection
What belongs to this tenant?
Organisations and their members in one table, isolated by partition.
- PK
- ORG#<orgId>
- SK
- ORG#<orgId>
- item collection
What did this customer order?
A customer's order history, newest first, in one partition.
- PK
- CUSTOMER#<customerId>
- SK
- ORDER#<placedOn>#<orderId>
- prefix read
Which products start with this?
Type-ahead from a sort key, without a search service.
- PK
- CATEGORY#<categoryId>
- SK
- NAME#<normalisedName>
- vector index
What else is like this item?
Recommendations with no embedding call on the read path.
- PK
- PRODUCT#<productId>
Working designs
The shapes most production tables take: a collection with an order, a second way in, a write that has to be safe.
- pagination
What’s new for this user?
A per-user feed read a page at a time, with unread as a sparse marker.
- PK
- USER#<userId>
- SK
- NOTIF#<createdOn>#<notificationId>
- time series
What did this sensor report?
Append-only device telemetry, read by time window and expired by TTL.
- PK
- DEVICE#<deviceId>
- SK
- TS#<takenAtIso>
- vector index
Which machines are behaving like this one?
Which machines are behaving like this one, across five channels at once.
- PK
- SITE#<site>
- SK
- MACHINE#<machineId>
- append only log
What happened, and when?
An append-only history beside the current state it explains.
- PK
- RESOURCE#<resourceId>
- SK
- CURRENT
- hierarchical key
What’s inside this folder?
A file hierarchy encoded in the sort key, so a subtree is one read.
- PK
- DRIVE#<driveId>
- SK
- PATH#<fullPath>
- composite sort key
Which jobs need attention?
Several query dimensions packed into one sort key, with no index.
- PK
- REGION#<regionId>
- SK
- STATUS#<status>#<scheduledOn>#<orderId>
- sparse index
Which ticket should we pick up next?
A worklist that maintains itself, because closing a ticket leaves the index.
- PK
- TICKET#<ticketId>
- atomic counter
Can we fulfil this order?
A counter that decrements atomically and refuses to go negative.
- PK
- PRODUCT#<sku>
- SK
- STOCK
- secondary index
Who’s at the top?
Per-game high scores, ranked with a secondary index on score.
- PK
- GAME#<gameId>
- SK
- PLAYER#<playerId>
- vector index
What should this agent remember?
One conversation log, read two ways: by recency and by meaning.
- PK
- SESSION#<sessionId>
- SK
- TS#<sentAtIso>
- vector index
Which passages answer this question?
Find one chunk by meaning, then read its neighbours by key.
- PK
- DOC#<docId>
- SK
- CHUNK#<seq>
- vector index
Which approved colour is this one?
The nearest approved colour to one a designer pasted, in a space where distance means difference.
- PK
- PALETTE#<paletteId>
- SK
- TOKEN#<tokenName>
The hard ones
Several techniques interacting - transactions, sharded writes, geohashing, many-to-many - where a wrong key is expensive to undo.
- uniqueness
What’s happening across the fleet?
Two attributes that must both be unique, enforced with lock items.
- PK
- VEHICLE#<vehicleId>
- item size limit
Has this configuration changed?
One item per document, and what happens as it approaches 400 KB.
- PK
- DOC#<docId>
- SK
- SECTION#<sectionId>
- multi item transaction
What moved through this account?
Money moved between two accounts, or not moved at all.
- PK
- ACCOUNT#<accountId>
- SK
- BALANCE
- write sharding
What’s getting attention?
One hot count, spread across shards so no single key takes the load.
- PK
- TREND#<topic>#<shardId>
- geohash
Which stores are nearby?
Finding what is nearby, using a geohash as a sort key.
- PK
- PLACE#<placeId>
- vector index
Which store is actually nearest?
The same 'what is near me' question as the geohash, answered by a vector index.
- PK
- PLACE#<placeId>
- gsi overloading
How do I find this contact?
One index answering two different questions.
- PK
- CONTACT#<contactId>
- SK
- PROFILE
- single table design
How does the whole shop fit together?
Four entity types, one table, no joins and no scans.
- PK
- CUSTOMER#<customerId>
- SK
- ORDER#<placedOn>#<orderId>
- adjacency list
Who maintains this project?
A many-to-many between people and projects, read from either side.
- PK
- PERSON#<personId>
- SK
- PROJECT#<projectId>
- vector index
Which matching tickets belong to us?
Search one tenant's incidents by meaning, filtered on what you declared.
- PK
- TENANT#<tenantId>
- SK
- INCIDENT#<incidentId>
- vector index
What’s like this, and in stock?
A vector index and a GSI on one table, answering different questions.
- PK
- CATEGORY#<category>
- SK
- PRODUCT#<productId>