Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

System Design Cheat Sheet

Interview Framework (45 min)

1. Requirements (5 min)     → Functional + Non-functional + Constraints
2. Estimation (3 min)       → QPS, storage, bandwidth
3. High-Level Design (10 min) → Core components + data flow
4. Deep Dive (20 min)       → Critical paths, bottlenecks, trade-offs
5. Wrap Up (7 min)          → Monitoring, failure modes, scaling

Back-of-Envelope Numbers

ResourceLatencyThroughput
L1 cache0.5 ns-
L2 cache7 ns-
RAM100 ns-
SSD150 μs100K IOPS
HDD10 ms200 IOPS
Same DC network0.5 ms-
Cross-continent150 ms-
TimeSeconds
1 day86,400
1 month2.6M
1 year31.5M
1 million users × 10 reads/day = ~116 QPS
1 KB × 1M/day = 1 GB/day = ~365 GB/year

Scaling Patterns

PatternWhenTrade-off
VerticalSimple, early stageSingle point of failure
HorizontalNeed redundancy/throughputComplexity, consistency
Database ShardingWrite-heavy, large dataCross-shard queries hard
Read ReplicasRead-heavyReplication lag
CachingRepeated readsCache invalidation
CDNStatic content, globalCost, cache staleness
Async (Queues)Bursty trafficEventual consistency

Caching Strategies

StrategyWrite PathRead PathConsistency
Cache-asideApp → DB, invalidate cacheApp → Cache → DBEventual
Write-throughApp → Cache → DBApp → CacheStrong
Write-backApp → Cache → (async) DBApp → CacheRisk of loss
Refresh-aheadBackground refreshApp → CacheNear real-time

Load Balancing

L4 (Transport): TCP/UDP level, fast, no content inspection
L7 (Application): HTTP level, content-aware, routing by path/header

Algorithms: Round Robin, Weighted, Least Connections, IP Hash, Consistent Hash
Health Checks: Active (periodic probe) + Passive (error monitoring)

Availability Math

99.9%  = 8.76 hours/year downtime
99.99% = 52.6 min/year downtime
99.999% = 5.26 min/year downtime

Serial:  A_total = A1 × A2 × A3
Parallel: A_total = 1 - (1-A1)(1-A2)

Consistency Patterns

PatternLatencyConsistencyUse Case
StrongHighLinearizableBanking, inventory
EventualLowConvergesSocial media, feeds
Read-your-writesLowPer-userUser profiles
Monotonic readsLowNo going backTimelines

Data Storage Choices

NeedChoice
ACID, relationsPostgreSQL, MySQL
Massive writes, wide columnsCassandra, HBase
Document storeMongoDB, DynamoDB
Key-value (fast)Redis, Memcached
GraphNeo4j, Dgraph
SearchElasticsearch
Time seriesInfluxDB, TimescaleDB
Object/blobS3, GCS

Common Design Patterns

CQRS: Separate read/write models
Event Sourcing: Store events, not state
Saga: Distributed transactions with compensating actions
Circuit Breaker: Fail fast on downstream failures
Bulkhead: Isolate critical resources
Rate Limiting: Token bucket, sliding window, leaky bucket

API Design

REST: Resources, HTTP verbs, stateless
gRPC: Protobuf, streaming, internal services
GraphQL: Client-driven queries, single endpoint

Versioning: URL path (/v1/), header, query param
Pagination: Cursor-based (stable), Offset-based (simple)
Rate Limiting: Per-user, per-IP, token bucket

Checklist Before Wrapping Up

  • Handle failures (what if X goes down?)
  • Data consistency model explained
  • Monitoring and alerting discussed
  • Security considerations (auth, encryption)
  • Cost estimation roughed out
  • Future scaling path mentioned