Animated, interactive diagrams for the hardest database concepts. Click, step through, and build intuition — not just definitions.
Keys are hashed onto a ring. Each node owns keys clockwise until the next node. Adding/removing a node only moves ~1/N of the keys — not a full reshuffle.
PostgreSQL never overwrites data. Each transaction sees a consistent snapshot of the DB from when it started. Readers never block writers, writers never block readers.
When a hot key expires, thousands of requests simultaneously miss the cache and pile onto the database. Watch the two strategies side-by-side.
In any distributed system, network partitions happen. The real tradeoff during a partition is: do you stay consistent (and reject reads) or stay available (and serve stale data)?
A B-Tree is a balanced tree where every leaf is at the same depth. Searches always take O(log N) steps regardless of data distribution. This is the default index in every major database.
A deadlock occurs when transactions form a circular wait. The database detects the cycle in the wait-for graph and kills one transaction (the victim) to break it.
Writes go to the primary and asynchronously stream to replicas via WAL (Write-Ahead Log). During that lag window, reads from replicas may see stale data.
Different isolation levels protect against different anomalies. MVCC alone does not guarantee serializability. Step through each anomaly to see exactly when and why data goes wrong.
Sharding distributes data across nodes by a partition key. The wrong key creates hotspots — one shard handles disproportionate load while others idle. Choose keys with high cardinality and uniform distribution.
The WAL ensures durability: every change is written to an append-only log BEFORE modifying data pages. On crash, the database replays the WAL from the last checkpoint to recover committed transactions.
When a transaction spans multiple shards, single-node deadlock detection and ACID guarantees break down. You need a coordination protocol — each with real tradeoffs in latency, availability, and failure modes.