System Design
4. Database FundamentalsAnimated
Primary Keys
A column that uniquely identifies each row.
The idea
The primary key is unique and not null. It is how rows are located and referenced.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- client
- gateway / proxy
- service
- cache
- data store
- queue / stream
Presentation tier: the browser shows the interface.
- step:
- 1/4
- at:
- Browser
1/9
The green dot is a request moving through the system.
Step by step
- 1Choose a unique identifier
- 2The database indexes it automatically
- 3Other tables reference it
- 4Lookups by key are fast
Where it is used
Every table.
Watch out for
Natural keys such as emails can change. Prefer a stable surrogate id.