All sheets / Architecture
System Design
A framework for design rounds plus the building blocks and numbers to reach for.
Interview framework (45 min)
- Requirements (5 min): functional, non-functional (scale, latency, availability, consistency).
- Estimates (3 min): users, QPS (avg & peak), storage/year, bandwidth.
- API (5 min): endpoints, request/response.
- High-level design (10 min): clients → LB → services → data stores → async workers.
- Deep dive (15 min): data model, bottlenecks, scaling, failure modes.
- Wrap up: trade-offs, monitoring, what you'd do next.
Back-of-envelope
| Quantity | Value |
|---|---|
| Seconds/day | ~86,400 ≈ 10^5 |
| 1M req/day | ~12 QPS |
| 100M req/day | ~1,200 QPS |
| Peak | 2–3x average |
| L1 / RAM / SSD / disk seek | 1 ns / 100 ns / 100 µs / 10 ms |
| Same-DC round trip | ~0.5 ms |
| Cross-continent | ~150 ms |
| 1 char / int / UUID | 1 B / 4–8 B / 16 B |
Availability
| SLA | Downtime / year | / month |
|---|---|---|
| 99% | 3.65 days | 7.2 h |
| 99.9% | 8.76 h | 43.8 min |
| 99.99% | 52.6 min | 4.4 min |
| 99.999% | 5.26 min | 26 s |
Serial dependencies multiply: two 99.9% services in series ≈ 99.8%.
CAP & consistency
- CAP: on a network partition, choose Consistency or Availability.
- PACELC: else (no partition) choose Latency or Consistency.
- Strong vs eventual vs read-your-writes vs causal consistency.
- Quorum:
R + W > Ngives strong reads (e.g., N=3, W=2, R=2).
Scaling building blocks
- Load balancer (L4/L7): round robin, least connections, consistent hashing; health checks.
- Stateless services + horizontal scaling; session in Redis/JWT.
- Cache: CDN → app cache (Redis) → DB cache.
- DB: read replicas, sharding (hash/range/geo), partitioning, denormalization.
- Async: queues to absorb spikes; workers process later.
- Consistent hashing: minimal key movement when nodes change; virtual nodes for balance.
Caching
| Strategy | How |
|---|---|
| Cache-aside | app reads cache, on miss loads DB & populates (most common) |
| Read-through | cache loads from DB itself |
| Write-through | write cache + DB synchronously |
| Write-back | write cache, flush to DB later (fast, risk of loss) |
- Eviction: LRU, LFU, TTL. Invalidate on write or short TTLs.
- Stampede: request coalescing, locks, jittered TTLs, stale-while-revalidate.
Rate limiting
- Token bucket (bursts allowed), leaky bucket (smooth), fixed window, sliding window log/counter.
- Store counters in Redis (
INCR+EXPIRE); return429withRetry-After.
Data store choice
| Need | Store |
|---|---|
| Relational, transactions, ad-hoc queries | Postgres / MySQL |
| Key-value at scale, known patterns | DynamoDB / Cassandra |
| Cache, counters, leaderboards | Redis |
| Search, fuzzy text | OpenSearch / Elasticsearch |
| Blobs, media | S3 |
| Analytics | Redshift / BigQuery / ClickHouse |
| Time series | Timestream / Prometheus / InfluxDB |
Classic designs: key ideas
- URL shortener: base62 of ID (or hash), KV store, 301/302, cache hot links.
- News feed: fan-out on write for most users, fan-out on read for celebrities.
- Chat: WebSockets, message store partitioned by conversation, presence via heartbeats.
- Rate limiter: token bucket in Redis at the gateway.
- Notification system: queue per channel, templates, retries, idempotency, user prefs.
- CI/CD platform: job queue, ephemeral runners, artifact store, log streaming, secrets vault.
- Feature flag service: rules in DB, streamed to SDKs, local evaluation, CDN-cached configs.
Reliability checklist
Redundancy across AZs, health checks + auto-healing, backups + tested restore, graceful degradation, idempotency, timeouts/retries/circuit breakers, observability + alerts on SLOs, runbooks.