Models
The template library
24 access-pattern designs. Pick one and it resolves into a real table on the engine, with its access patterns ready to run and the cost of each one read out beside the data.
Search covers what a model teaches, not only what it is called.
Start here
The primary key answers every read. No secondary index, nothing to keep in sync.
- URL Shortenergeneral
A hash-only table keyed by short code, the classic key-value lookup.
key value lookup
- Feature Flagsconfig
Flag values per environment, read one at a time or all at once.
composite key · item collection · key value lookup
- Web Sessionsauth
Server-side sessions keyed by token, expired by the database.
time to live · key value lookup
- Idempotency Keyspayments
A conditional write that makes a retried request safe.
conditional write · uniqueness · key value lookup
- Account & Settingsuser-data
Two entity types under one key, told apart by the sort key.
type discriminator · item collection · co location
- SaaS Multi-Tenantsaas
Organisations and their members in one table, isolated by partition.
item collection · tenant isolation
- Customer Orderscommerce
A customer's order history, newest first, in one partition.
item collection · time ordered collection · one to many
- Product Autocompletesearch
Type-ahead from a sort key, without a search service.
prefix read · item collection
Working designs
The shapes most production tables take: a collection with an order, a second way in, a write that has to be safe.
- Notifications Feedsocial
A per-user feed read a page at a time, with unread as a sparse marker.
pagination · item collection · sparse attribute
- Sensor Readingsiot
Append-only device telemetry, read by time window and expired by TTL.
time series · time ordered collection · time to live
- Change & Audit Logcompliance
An append-only history beside the current state it explains.
append only log · optimistic locking · item collection
- Folder Treestorage
A file hierarchy encoded in the sort key, so a subtree is one read.
hierarchical key · prefix read · item collection
- Work Ordersfield-service
Several query dimensions packed into one sort key, with no index.
composite sort key · prefix read · item collection
- Support Ticket Queuehelpdesk
A worklist that maintains itself, because closing a ticket leaves the index.
sparse index · secondary index · worklist
- Stock Countercommerce
A counter that decrements atomically and refuses to go negative.
atomic counter · conditional write · guarded decrement
- Game Leaderboardsocial
Per-game high scores, ranked with a secondary index on score.
secondary index · sorted query
The hard ones
Several techniques interacting - transactions, sharded writes, geohashing, many-to-many - where a wrong key is expensive to undo.
- Fleet Registrylogistics
Two attributes that must both be unique, enforced with lock items.
uniqueness · lock item · conditional write
- Shared Config Documentcollaboration
One item per document, and what happens as it approaches 400 KB.
item size limit · partial update · vertical partitioning
- Account Ledgerfintech
Money moved between two accounts, or not moved at all.
multi item transaction · double entry · guarded decrement
- Trending Counteranalytics
One hot count, spread across shards so no single key takes the load.
write sharding · scatter gather · atomic counter
- Store Locatorgeo
Finding what is nearby, using a geohash as a sort key.
geohash · proximity search · secondary index
- Contacts CRMsales
One index answering two different questions.
gsi overloading · generic key · secondary index
- Commerce Capstonecommerce
Four entity types, one table, no joins and no scans.
single table design · type discriminator · gsi overloading · sparse index · item collection
- Maintainers & Projectsgeneral
A many-to-many between people and projects, read from either side.
adjacency list · inverted index · secondary index