← All cheat sheets
🏗️

System Design

Estimation numbers, caching, CAP, and the building-block one-liners.

Numbers to know

Seconds/day86,400 ≈ 10⁵
1 million writes/day≈ 12 writes/sec
Read:write ratio (typical)~100:1 for social/feeds
SSD read~100 µs · Memory read ~100 ns · Network RTT (same DC) ~0.5 ms
Char ≈ 1 byte1 KB ≈ short post · 1 MB ≈ small image

Caching strategies

Cache stampede fix: lock/single-flight on miss, or stagger TTLs.

StrategyHowTrade-off
Cache-asideApp reads cache, on miss loads DB & fills cacheMost common; stale risk → use TTL
Write-throughWrite to cache + DB synchronouslyConsistent, slower writes
Write-backWrite cache, flush to DB laterFast writes, data-loss risk

CAP & consistency

  • CAP: under a network partition you pick Consistency OR Availability.
  • CP (HBase, Zookeeper) — reject some requests to stay consistent.
  • AP (Cassandra, DynamoDB) — always answer, may serve stale data.
  • Models: strong > read-your-writes > monotonic > eventual.

SQL vs NoSQL

SQLNoSQL
SchemaFixed, relationalFlexible / denormalized
ScaleVertical (+ read replicas, sharding)Horizontal by design
Best forTransactions, joins, integrityHigh write throughput, simple access by key

Building blocks (one-liners)

  • Load balancer: spread traffic across stateless instances (L4 = transport, L7 = HTTP-aware).
  • CDN: cache static assets near users; pull (lazy) vs push.
  • Queue (Kafka/SQS): decouple producers/consumers, absorb spikes, async work.
  • Sharding: partition data by key (consistent hashing avoids mass re-shuffle).
  • Replication: copies for read scale + failover (leader-follower).
SDE-2 Launchpad · System Design cheat sheet