Data consistency at scale
Concurrency, locking, reservations, caching and sharding tasks from real high-traffic systems.
- Versioned Store with Optimistic Locking Stop silent overwrites between editors: every update must name the version it was based on.
- Flash-Sale Reservations Without Overselling Hold stock for 10 minutes, enforce a per-customer limit, survive client retries and never oversell.
- Find Deadlocked Transactions Given who-waits-for-whom edges from a lock monitor, report the transactions stuck in a deadlock cycle.
- Row Lock Manager with Deadlock Detection Build the core of a database lock manager: grant, queue, release in FIFO order, and abort on deadlock.
- Read-Your-Writes Replica Router Send reads to a replica only when it already has the user's latest write — otherwise use the primary.
- Sharded Counter for a Hot Row Spread increments of a viral post's like counter over several slots and measure the lock waits.
- Consistent Hash Ring for Shard Routing Route keys to shards on a hash ring with virtual nodes, so adding a shard only moves a slice of keys.
- Single-Flight Cache Loader When a hot key expires, let one request load it while everyone else waits — instead of a thundering herd.
- Cache with Version-Checked Sets Prevent the cache-aside stale-set race: a slow reader must not re-cache an old value after an invalidation.
- Write-Behind View Counter with Safe Flushes Buffer view counts and flush them in batches that survive crashes and are never applied twice.
- Two Checkouts, One Item Left Predict what a read-modify-write checkout does when two requests interleave.
- The Stale Cache Set A slow cache-aside reader and a writer race. What ends up in the cache?
- Read Committed vs Repeatable Read A report reads a balance twice while a deposit commits in between. What does each isolation level see?