Cheat sheet · System Design, Step by Step

System Design cheat sheet

The numbers, formulas, trade-offs and standard fixes from the whole series, in the order you use them in a design interview: requirements, estimates, building blocks, data, reliability, security, deployment.

Read the full series →

blogs · jp-blogs.vercel.app/cheatsheets/series/system-design

The 5-step frameworkLesson 59 →

  1. Requirements (5-8 min): 3-5 use cases, measurable non-functional needs (scale, latency, availability, consistency), what is out of scope.
  2. Estimation (3-5): average and peak QPS, storage, bandwidth, cache. End with "so this means...".
  3. API and data (5-8): endpoints or events, entities, access patterns, storage choice, IDs.
  4. High-level design (10-15): client, DNS/CDN, LB, gateway, services, cache / DB / storage / queue. Walk each use case through it.
  5. Deep dives (10-15): bottlenecks, failures, consistency, hot keys, security, monitoring.
  6. Wrap-up (2-5): trade-offs, risks, next steps.

Tip: Start simple, put numbers on everything, say each trade-off out loud, and never stay silent.

Numbers to knowLesson 10 →

OperationRough time
L1 cache / RAM read~1 ns / ~100 ns
SSD random read~16-100 µs
Round trip in one data centre~0.5 ms
Indexed DB query / Redis GET~1-10 ms / < 1 ms
HDD seek~2-10 ms
Cross-continent round trip~100-250 ms
1 day
86,400 s, call it 100k
1 month / 1 year
~2.6M s / ~31.5M s
1M requests/day
~12 per second
Peak
2-10x average (3x if unsure)
One app server
hundreds to a few thousand req/s
One SQL DB / one Redis
1k-10k+ queries/s / ~100k ops/s

Formulas and the ninesLesson 9 →

Avg QPS  = requests/day / 86,400
Storage  = items/day x size x years
Bandwidth= QPS x response size
Servers  = peak QPS / QPS per server
           (+ headroom)
Little   = in flight = rate x time
Avail.   = MTBF / (MTBF + MTTR)
Series   = A x B x C (lower)
Parallel = 1 - (1-A)(1-B)
Quorum   = W + R > N
Base62   = 62^len (6: 56.8B, 7: 3.5T)
AvailabilityDown / yearDown / month
99%~3.65 days~7.3 h
99.9%~8.8 h~43.8 min
99.99%~52.6 min~4.4 min
99.999%~5.3 min~26 s

Tip: Use p99, not averages: the slow tail is common at scale. Three 99.9% services in series give ~99.7%. Faster recovery (MTTR) is the cheapest nine.

Request path: HTTP, load balancer, CDNLesson 12 →

BalancerL4L7
SeesIP and portFull HTTP request
Routes by URL/headerNoYes
Speed / AWSFaster / NLBSlightly slower / ALB
  • Algorithms: round robin, least connections, power of two choices, consistent hashing. Keep health checks shallow.
  • GET, PUT, DELETE are idempotent, POST is not. 502 bad gateway, 503 unavailable, 504 gateway timeout. TLS 1.3 takes 1 round trip.
  • API gateway = reverse proxy plus auth, rate limits, routing. BFF = one API per client type.
  • CDN: Cache-Control sets lifetime, hashed file names avoid stale files, an origin shield protects the origin.

CachingLesson 16 →

  • Cache-aside is the safe default: read cache, load on miss and fill, delete the key on write, TTL on everything.
  • Hit ratio 95% to 99% cuts backend load 5x. Evict with LRU or LFU. Read critical values (price at checkout, balance) from the source.
ProblemFix
Stampede (many misses)Lock, stale-while-revalidate, early refresh
Avalanche (mass expiry)TTL jitter
Penetration (missing data)Cache "not found", Bloom filter
Hot keyLocal cache, key replication

Choosing a database, ACIDLesson 21 →

NeedUse
Transactions, flexible queriesPostgreSQL / MySQL (default, plus Redis)
Huge write-heavy, time-orderedCassandra / ScyllaDB
Simple key lookups at scaleDynamoDB / key-value
RelationshipsGraph DB
Full-text search / analyticsElasticsearch / warehouse
Isolation levelDirtyNon-rep.Phantom
Read UncommittedYesYesYes
Read CommittedNoYesYes
Repeatable ReadNoNoDepends
SerializableNoNoNo

Watch out: Lost update and write skew need UPDATE ... SET x = x - 1 WHERE x > 0, FOR UPDATE, a unique constraint, or Serializable plus retry.

Indexes, replication, shardingLesson 25 →

StructureGood atHow
B-treeReads, rangesSorted pages, updated in place
LSM-treeWritesAppend, then compact; Bloom filters
  • Multi-column index helps only from its left prefix. Check with EXPLAIN ANALYZE. Fix N+1 with a join.
  • Replication (availability, read scale): async is fast but can lose writes and lag. Read your own writes from the leader.
  • Sharding (write scale, size): range, hash, directory or geo. A good shard key is even, matches queries, rarely changes.
  • hash % N moves most keys. Consistent hashing (ring plus virtual nodes) moves ~1/N.

Watch out: Replication is not a backup: replicas copy deletes and corruption at once.

CAP and consistency modelsLesson 27 →

  • In a partition you pick consistency (refuse) or availability (answer, maybe stale). PACELC: otherwise, latency or consistency.
  • Choose consistency for money, stock, uniqueness. Choose availability for feeds, likes, catalogues.
ModelPromise
LinearizableActs like one copy; costs latency
CausalCause is seen before effect
SessionRead-your-writes, monotonic reads
EventualCopies agree later

APIs and real timeLesson 34 →

ChoiceBest forWatch
RESTSimple, public APIsRight status codes, no 200 on error
gRPCInternal callsSet deadlines; needs L7 balancing
GraphQLVaried clientsN+1 (DataLoader), cost limits
SSEFeeds, notificationsOne way only
WebSocketChat, gamesGateways, heartbeats, replay
  • Idempotency key: unique constraint plus saved response, so a retried POST does not charge twice.
  • Cursor pagination stays stable as data changes; offset only for small lists. Add fields, never break clients.

Queues, Kafka, deliveryLesson 37 →

DeliveryRiskUse
At-most-onceLoss (ack first)Rarely
At-least-onceDuplicatesDefault
Effectively-onceNone, if idempotentAt-least-once + dedup
  • Queue: one consumer gets each message. Pub/sub: every subscriber gets a copy.
  • Kafka: the key picks the partition, order holds only within one. One consumer per partition per group. Watch lag. Use acks=all.
  • Outbox fixes the dual write (DB updated, event lost). Failing jobs: transient retries only, then a DLQ.

Resilience and rate limitingLesson 41 →

delay = random(0,
  min(cap, base * 2^attempt))

Exponential backoff with full jitter.

  • Timeout on every call. Retry only transient, idempotent errors, 2-3 attempts, at one layer (attempts multiply per layer).
  • Circuit breaker: closed, open (fail fast), half-open (test calls). Bulkhead = separate pools. Shed load with 503 + Retry-After.
Rate limiterTrade-off
Fixed windowSimple; double burst at the boundary
Sliding logExact; one entry per request
Sliding counterApproximate; two counters
Token bucketBursts plus average rate; API favourite
Leaky bucketSmooth output for fragile downstreams

Tip: Share counters in Redis with an atomic Lua script. Return 429 + Retry-After. Fail open for general limits, closed for login and OTP.

Backups, SLOs, observabilityLesson 47 →

DR strategyRPORTO
Backup and restoreHoursHours to days
Pilot lightMinutesTens of minutes
Warm standbySeconds-minutesMinutes
Active-active~0~0 to minutes
  • Backups: 3-2-1 rule, immutable copies, PITR (base backup + WAL), test restores.
  • SLI = good events / valid events. SLO = target. SLA = looser promise. Error budget = 1 - SLO.
  • Burn rate 14.4x (1.44% errors vs 0.1% allowed) spends the 30-day budget in ~2 days: page. Alert on symptoms.
  • Golden signals: latency, traffic, errors, saturation. Logs say what, metrics say how much, traces say where.

Security checklistLesson 49 →

  • AuthN is who you are, AuthZ is what you may do. Hash passwords with Argon2id or bcrypt; offer MFA or passkeys.
  • Cookies: HttpOnly; Secure; SameSite. JWTs are signed, not encrypted: pin the algorithm, check exp/aud/iss, short life, rotating refresh.
  • OAuth: Auth Code + PKCE for users, Client Credentials for services. OIDC adds the ID token for login.
ThreatDefence
IDOR / broken accessCheck every object; deny by default
InjectionParameterised queries, output encoding
SSRFAllow-lists, block internal and metadata IPs
Leaked secretRotate now; secrets manager; scanning

Architecture and deploymentLesson 58 →

  • Monolith first, then modular monolith, then microservices when teams demand it. Migrate with the strangler fig. Avoid the distributed monolith.
  • Containers: version tags (not latest), non-root, no secrets. Kubernetes: readiness vs liveness, requests/limits, spread across 3 zones (150% of peak).
StrategyIdea
RollingGradual, no downtime
Blue-greenInstant switch and rollback; 2x resources
CanaryFew users first; smallest blast radius
ShadowCopied traffic, no user impact

Tip: Feature flags separate deploy from release. Change schemas with expand-and-contract.

Case studies in one lineLesson 60 →

SystemCore idea
URL shortener7-char Base62, Redis cache, shard by code, 302 + async analytics
Rate limiterGateway + Redis Cluster + Lua; 429 with headers
NotificationsAsync, priority lanes (OTP first), dedup, provider failover
ChatWebSocket gateways + pub/sub; store first, then deliver; sequence numbers
News feedHybrid fan-out; cache post IDs; batch hydration; cursors

Tip: Shortener: 100M new/month is ~40 writes/s and ~3,800 reads/s (100:1); 12B URLs fit in 7 Base62 characters.

Interview one-linersLesson 69 →

QuestionShort answer
1M requests/day per second?~12 average (÷ 86,400); peak 2-10x
Downtime at 99.9%?~43.8 min a month, ~8.8 h a year
Replication, sharding, backups?Availability + reads; writes + size; go back in time
W + R > N?Quorum: a read always meets the latest write
At-least-once means?Duplicates happen, so consumers must be idempotent
Feed fan-out?Hybrid: push normal authors, pull celebrities
Top API vulnerability?IDOR: check access to each object
Monolith or microservices?Monolith first; split when teams and scale demand

A cheat sheet is a reminder, not a teacher. Each card links to the lesson that explains it step by step.