read latency under 100ms
DB indexes + Cache the read path (e.g. Redis, cache-aside)
DB read is ~30ms; Redis ~1ms. At 90% hit rate the mean drops 10ร.
Deep divePattern recognition, like LeetCode - but for system design. Hear a signal in the requirements, reach for the right architecture.
Every entry below is a phrase you might hear an interviewer say (or that you should say to confirm requirements), paired with the canonical pattern it points to. Click any topic link to drill into the deep-dive.
How fast a single request is served - read latency, write latency, perceived speed.
read latency under 100ms
DB indexes + Cache the read path (e.g. Redis, cache-aside)
DB read is ~30ms; Redis ~1ms. At 90% hit rate the mean drops 10ร.
Deep diveSame data fetched many times between writes
Cache (cache-aside is the default)
Read-heavy workloads are exactly what caches were built for; load shedding matters more than latency at scale.
Deep diveResult can be a few seconds stale
Users are from different regions
CDN for static assets + regional read replicas
Cross-continent RTT is ~150ms; edge POPs cut that to ~20ms.
Deep diveReal-time push to clients (chat, live cursors)
WebSockets
Bidirectional, low overhead after handshake. SSE if it's one-way; polling is wasteful.
Deep diveMobile screen needs data from 5 services
Backend-for-Frontend (BFF) aggregation
5 mobile RTTs over cell network = 750ms+. One server-side fan-out collapses to 1 RTT.
Deep diveFree-form text search has to feel instant
Inverted index (Elasticsearch, or Postgres full-text search)
`LIKE '%foo%'` is a full table scan; an inverted index is sub-millisecond.
Deep diveWork that doesn't need to complete before responding to the user.
Send confirmation email after checkout
Async queue (SQS / RabbitMQ / Kafka) + worker
Don't block the checkout response on a slow downstream. Emails are best-effort, durable in the queue, retry-on-failure.
Deep diveGenerate thumbnails / re-encode video on upload
Trigger on upload โ enqueue โ worker pool
Heavy compute that can take seconds-to-minutes shouldn't hold the upload connection open.
Deep diveService A places an order; B, C, D should react
Event-driven architecture (use pub/sub (e.g. Kafka) to publish OrderPlaced, consumers react)
Decouples producer from consumers; A doesn't need to know who listens.
Deep diveSpiky traffic - must not drop requests during a spike
Queue as a buffer + workers consume at fixed rate
Queue absorbs the spike; workers smooth processing and apply backpressure.
Deep diveService writes to DB AND must publish an event
Outbox pattern (write business row + outbox row in one transaction) or CDC (Change Data Capture)
Dual-writes (DB + Kafka in app code) drift on partial failure. Outbox guarantees both committed atomically.
Deep diveMulti-step workflow across services that may need rollback
Saga pattern (sequence of local txns + compensations)
Distributed transactions (2PC) block under coordinator failure. Sagas trade atomicity for liveness.
Deep diveWhether reads see writes immediately, eventually, or somewhere in between.
Money / inventory / safety-critical writes
Strong consistency + DB transactions + locks + idempotency
Bank balances, last-seat-on-flight, payment idempotency - no room for "almost atomic."
Deep diveUser edits profile, reloads, must see the new value
Read-your-writes (sticky to primary, or version stamps)
Read replica lag breaks the user's mental model. Stick that user's reads to the primary for N seconds after a write.
Deep diveRecommendations can be a few seconds stale
Eventual consistency (read replicas, async events)
Pick consistency per operation. Strong consistency everywhere is expensive and unnecessary.
Deep diveWhat happens during a network partition?
Decide CP vs AP per workload
Banking โ CP (reject writes during partition). Social feed โ AP (accept, reconcile later).
Deep diveTwo users hit Buy on the last seat at the same time
Row-level lock (`SELECT FOR UPDATE`) or optimistic locking (`UPDATE ... WHERE qty > 0 AND version = $oldVersion`)
Race conditions on shared state need either a lock or an atomic compare-and-set.
Deep diveClient retries on timeout - must not double-charge
Idempotency key on the request
Server stores key + cached response; retries with the same key return the cached result.
Deep diveHandling more users, more requests, more data.
Single Postgres can't take 200K QPS
Tune queries โ cache โ read replicas โ shard (in that order)
Most "DB is overloaded" is a missing index. Sharding is a major complexity jump - earn it.
Deep diveWrite-heavy workload at petabyte scale (activity feeds, IoT, logs)
Wide-column store with LSM-tree (Cassandra)
LSM appends are sequential and 10โ100ร faster than B-tree updates for sustained ingest.
Deep diveService is at 80% CPU on a single instance
Scale horizontally (LB + stateless service + shared state in Redis)
Vertical hits a ceiling and is a SPoF. Stateless + LB scales linearly.
Deep diveAdding a cache node remaps almost all keys
Consistent hashing (with virtual nodes)
`hash % N` shifts ~80% on NโN+1; consistent hashing moves only ~K/N.
Deep divePublic API; one user is hammering an expensive endpoint
Rate limiting (token bucket, distributed via Redis)
Protects backend; gives fair-share between tenants; predictable failure mode (429 + Retry-After).
Deep diveTwitter timelines for 200M DAU including celebrities with 100M followers
Hybrid fan-out (push for normal users, pull for celebrities)
Push-only writes 100M timeline entries per celebrity tweet. Pull-only is too slow for users following thousands.
Deep diveDon't lose data; survive failures.
99.99% uptime target
Multi-AZ deployment + auto-failover + health checks
99.9 = 8.7 hrs/year, 99.99 = 53 min/year. Eliminate single points of failure first.
Deep diveService A fails - must not cascade into a B/C/D outage
Circuit breaker + timeout + bulkhead
Without it, slow downstream queues up requests in A and starves the whole system.
Deep diveWorker crashed mid-message - message must not be lost
At-least-once queue (Kafka, SQS) + idempotent consumers
Visibility timeout returns the message; consumer dedupes by event ID.
Deep diveNeed a complete audit trail of every change
Event sourcing or CDC
Append-only event log = full history; current state derived by replay.
Deep diveWrites must be durable across regions
Synchronous cross-region replication
Async loses recent writes on regional failure. Sync is slower but lossless - pick based on RPO.
Deep diveRecognize the data-access shape; pick the index/store that fits it.
Find drivers/restaurants/users near point X
Geospatial index (Redis GEO for in-memory, PostGIS for relational)
Naive distance scan is a full-table scan; geohash/quadtree/R-tree make it O(log n).
Deep diveFree-form text search with relevance / fuzzy / autocomplete
Inverted index (Elasticsearch, or Postgres full-text search at <100GB)
Relational `LIKE` doesn't scale and has no relevance scoring or fuzzy matching.
Deep diveInfinite-scroll feed; page 1000 takes 8 seconds
Cursor (keyset) pagination
Offset scans+discards N rows. Cursor is O(1) at any depth and stable under inserts.
Deep diveStructured data with relationships - orders, payments, users
Relational DB (Postgres)
Joins, ACID, ad-hoc queries. Holds up to ~10TB and ~100K QPS. Don't reach for NoSQL by reflex.
Deep diveSchema-flexible documents with nested fields
Document store (MongoDB, DynamoDB document mode)
When the shape varies meaningfully per item and you don't need cross-document joins.
Deep diveSub-millisecond key lookups, sessions, leaderboards
Key-value store (Redis, DynamoDB KV)
Opaque-blob-by-key with O(1) access; Redis adds rich data structures (sets, sorted sets, streams).
Deep divePhotos, videos, attachments, large user uploads.
Users upload profile photos / videos / attachments
Object storage (S3) + metadata in DB
Never put bytes in Postgres BLOBs - bloats the DB, slows backups, wastes cache.
Deep dive10K concurrent uploads of 50MB files saturating our app servers
Pre-signed URLs - browser PUTs directly to S3
Your server only generates the signed URL; bytes never touch it.
Deep diveStatic images and JS bundles slow for global users
CDN (Cloudflare / CloudFront / Fastly)
Edge POPs serve cached assets close to the user; cuts latency 5โ10ร.
Deep divePick the right contract for who's calling.
Public API for third-party developers
REST + JSON (URL versioning, idempotency keys, cursor pagination)
Universal tooling, browser-friendly, HTTP caching, every language has an HTTP client.
Deep diveService-to-service in a polyglot stack (Go/Java/Python)
gRPC + protobuf
Schema-first, ~5โ10ร smaller wire size than JSON, strongly typed stubs in every language.
Deep diveMobile/web client needs to shape its own data
GraphQL (single endpoint, typed schema, client-picked fields)
Solves over/under-fetching; pair with DataLoader to avoid the N+1 trap.
Deep diveServer-pushed notifications (one-way, browser-friendly)
Server-Sent Events (SSE)
Simpler than WebSockets, runs over plain HTTP, browsers auto-reconnect.
Deep diveWhen customers say "the app is slow," how do you find out why?
Customers say it's slow; one request crosses 6 services
Distributed tracing (OpenTelemetry โ Jaeger / Datadog)
Logs don't correlate across services. A trace shows the waterfall and exposes the long-pole span.
Deep diveOn-call gets paged 5ร/day on CPU > 80% but nothing's actually broken
Alert on user-facing symptoms (error rate, p99 latency, SLO burn) - not resources
CPU at 80% is fine if latency is OK. Alert on "are users in pain right now?"
Deep diveWho is the caller, and what are they allowed to do?
Mobile app + backend API; users stay logged in for hours
JWT access token (15 min) + refresh token (30 days, rotated)
Stateless API; short access TTL limits blast radius if leaked; refresh-rotation detects theft.
Deep diveSign in with Google / Apple / GitHub
OAuth 2.0 Authorization Code + PKCE
Industry standard; PKCE protects against code interception (essential for public clients).
Deep diveService-to-service auth in a service mesh
mTLS (handled by Istio / Linkerd)
Zero-trust internal traffic; cert rotation automated by the mesh.
Deep diveSanity-check that your design fits the scale before drawing boxes.
How many QPS will this handle?
`avg QPS = DAU ร actions/day / 86,400`; peak โ 2โ3ร
Compute it out loud before designing. If it's 100 QPS, single Postgres. If it's 100K QPS, sharding.
Deep diveHow much storage for X users / Y events / Z retention?
`writes/day ร bytes/record ร replication ร retention`, +30% overhead
Rounds drive design choices: 4TB = single Postgres, 400TB = shard or NoSQL.
Deep dive