Deep Dive Toolkit

Techniques for the deep-dive half of the interview.

  1. 1 Optimistic, Pessimistic & Distributed Locking "Holding a seat is a single conditional update: set it to HELD where it's still AVAILABLE. If it updates zero rows, someone else got it. That's optimistic, so nothing blocks while thousands of users browse. For the money transfer I'll use a short transaction that locks both account rows in id ord... 5 min read
  2. 2 Bloom Filter "Before fetching a URL, the frontier checks a Bloom filter of crawled URLs. With 10 bits per URL we get about 1% false positives, so 10 billion URLs fit in about 12 GB across a few servers. If the filter says not seen, we crawl without touching the database; if it says maybe, we confirm against t... 4 min read
  3. 3 Partitioning / Sharding Basics "At 9,000 writes per second one primary isn't enough, so I'll shard orders by hash of user_id. That keeps 'my orders' on one shard and spreads writes evenly. I'll hash into 1,024 virtual partitions mapped to machines, so adding capacity means moving whole partitions. Order IDs carry the partition... 4 min read
  4. 4 Consistent Hashing "Keys are assigned with consistent hashing: servers and keys hash onto a ring and each key goes to the next server clockwise. Each server has about 150 virtual nodes so load is even and a failure spreads across everyone. Adding a node moves only about 1/N of keys, instead of nearly all of them wi... 5 min read
  5. 5 Rate Limiting Algorithms "I'll rate limit at the API gateway with a token bucket per API key: refill rate is the plan's average, capacity is the allowed burst. Tokens and last-refill time live in Redis and are updated in one Lua script, so concurrent gateways can't both take the last token. Over the limit returns 429 wit... 5 min read
  6. 6 Idempotency & Deduplication "Clients retry on timeouts, so the charge endpoint takes an idempotency key that the app creates once per tap. The server inserts the key under a unique constraint in the same transaction as the charge, and stores the response. A retry with the same key gets the stored response. We pass the key t... 5 min read
  7. 7 Backpressure & Circuit Breaker "Every downstream call has a timeout and its own connection pool, so a slow Recommendations service can't take all our threads. Each dependency sits behind a circuit breaker that opens at 50% failures and fails fast, and while it's open we serve cached popular items. Each instance caps in-flight ... 5 min read
  8. 8 TTL, Expiration & Cleanup "Sessions live in Redis with a 30-day TTL that slides on activity, so memory only holds live sessions. Reset tokens are rows with an expires_at, and every lookup checks it, so an expired token never works even before the cleanup job runs. Login history is partitioned by month and we drop partitio... 4 min read