← Contents
Idea 01 · added 2026-11-05

Label the pattern before drawing boxes

Spend the first thirty seconds of a system design question naming which of ten known patterns it is. The building blocks and trade-offs follow from the label. Now with plain definitions, an example for every trade-off, and Excalidraw starters.

Original The Only System Design Cheatsheet by Puneet Patwari

system designframework

The idea

Most system design questions are one of a small set of recurring shapes. If you name the shape out loud before you sketch anything, the architecture gets simpler, the trade-offs you raise are the right ones, and the answer stops sounding like a list of buzzwords.

Four quick questions do the classifying: are reads or writes dominant, do users need updates now or is near real time fine, is the value in serving live traffic or crunching data later, and is it one user at a time or fanout to millions.

Most real systems combine two or three patterns. Saying which one is primary and which are secondary is itself a strong signal.

The ten patterns

PatternTell-tale signalTrade-off to raise
Read heavyRead:write ratio is huge; latency matters more than freshnessWhat to cache at which layer, invalidation, hot keys, replica lag
Write heavy / event drivenLots of writes, work happens async, reads are aggregatesAt-least-once vs exactly-once, partition keys and ordering, back pressure, DLQs, replay
Real time fanoutOne event must reach many clients within secondsGateway sharding, per-connection cost vs batching, reconnect history, fallback to polling
Batch and analyticsMinutes-to-hours freshness is fine; queries scan a lotBatch size vs frequency, Lambda vs Kappa, late data, cost per query
Search and filteringText, tags and filters; relevance matters as much as speedIndex freshness, typo tolerance, shard/replica scaling, ranking signals
File and mediaLarge blobs, CDN, thumbnails or transcodingMetadata vs blob split, cold tiers, resumable uploads, signed URLs
Workflow orchestrationMulti-step flows that need retries or compensationOrchestration vs choreography, where state lives, debugging stuck runs
Transactional / financialMoney moves; never lose or duplicateACID boundaries, idempotency keys, double-entry ledger, outbox, reconciliation
RecommendationOutput is a ranked list with a feedback loopCandidate generation then ranking, offline vs online, cold start, explore vs exploit
Events and notificationsOne event becomes messages on many channelsPreferences and suppression, dedup keys, immediate vs digest, provider fallback

Each pattern in detail

Tap a pattern to open it. Each one has the picture to draw, the vocabulary in plain English, and every trade-off from the table above with a concrete example and a default answer to give.

01Read heavyMany more reads than writes (100:1 or more), and users care about speed more than seeing the very latest value.

Put copies of the data close to the reader. A cache answers most requests from memory, read replicas soak up the rest, and only writes go to the one primary database.

Typical questions URL shortener redirects, product pages, user profiles, a news feed read path, feature-flag evaluation.

Excalidraw starter: 01-read-heavy.excalidraw

Terms in plain English

Cache
A fast, temporary copy of data kept in memory (Redis, Memcached) so you can skip the slower database. If it's lost you can rebuild it, so it is never the source of truth.
Cache hit / miss
Hit: the answer was already in the cache. Miss: it wasn't, so you go to the database. Hit ratio (say 95%) is the number that decides how much load the database sees.
Cache-aside
The app checks the cache, and on a miss reads the database and puts the result in the cache itself. The most common setup.
Read-through
Like cache-aside, but the cache library fetches from the database for you on a miss. The app only ever talks to the cache.
Write-through / write-around / write-back
Ways to handle writes. Write-through updates the cache and the database together. Write-around writes only the database and lets the cache fill on the next read. Write-back writes the cache now and the database later, which is fast but can lose data.
TTL (time to live)
How long a cached item may live before it expires, for example 60 seconds. Short TTL means fresher data and more database load.
Invalidation
Deleting or updating a cached item when the real data changes, so readers don't see the old value.
Hot key
One key that gets a huge share of traffic, such as a celebrity's profile. It can overload the single cache node or shard that owns it.
Cache stampede (thundering herd)
A popular item expires and thousands of requests miss at the same moment and all hit the database together.
Read replica
A read-only copy of the database that receives changes from the primary. More replicas means more read capacity.
Replication lag
How far behind a replica is, often milliseconds but sometimes seconds. During lag a replica returns old data.
Read-your-writes
A guarantee that after you change something, you see your own change. Lag breaks it unless you route that user's reads to the primary for a short while.
CDN
Content delivery network: servers around the world that cache static files (images, JS, video) near users.

Trade-offs, each with an example

  1. Freshness vs load (TTL length)

    Example A product page caches price with a 5 minute TTL. The database sees one read per product per 5 minutes instead of thousands, but a price change can show the old price for up to 5 minutes. For price, you invalidate on write; for the review count, 5 minutes stale is fine.

    Default answer Say which data can be stale and for how long, then set the TTL per data type, not one global value.

  2. Cache-aside vs write-through

    Example Profile edits are rare. With cache-aside plus delete-on-write, an edit deletes the cached profile and the next read reloads it. With write-through, every edit also rewrites the cache, which keeps it warm but wastes work on profiles nobody reads.

    Default answer Default to cache-aside with invalidate-on-write. Use write-through when data is read right after it's written.

  3. Replica reads vs read-your-writes

    Example A user changes their display name, the write hits the primary, then the page reloads from a replica that is 800 ms behind and shows the old name. Fix: read from the primary for that user for a few seconds after a write, or read your own profile from the primary always.

    Default answer Name the lag and say which reads must go to the primary.

  4. Hot keys: one copy vs many

    Example A celebrity post gets 500k reads a second; one Redis shard tops out near 100k. Options: keep a small in-process cache on each app server for that key, or store copies under key#1..key#10 and pick one at random.

    Default answer Mention hot keys before the interviewer does, and pick local caching or key replication.

  5. Stampede protection vs simplicity

    Example The home page cache entry expires at 09:00:00 and 20k requests miss at once. A lock (only one request rebuilds, others wait or get the stale copy) or random jitter on TTLs (55 to 65 s) spreads the reloads.

    Default answer Add jitter to TTLs and let one request refresh a hot entry while others serve stale.

Read more on ByteByteGo (free)

02Write heavy / event drivenA firehose of writes (clicks, metrics, IoT readings, logs). Nobody waits for the full processing; reads are mostly totals or summaries.

Accept the write quickly, append it to a durable log, and let workers process it in the background at their own pace.

Typical questions Ad click counting, metrics and logging, activity tracking, likes counters, order events feeding other services.

Excalidraw starter: 02-write-heavy-event-driven.excalidraw

Terms in plain English

Message queue / log
A buffer between the service that produces events and the services that consume them. Kafka is a log: messages stay for days and readers track their own position.
Producer / consumer
Producer writes messages; consumer reads and processes them. They run and scale independently.
Partition
Kafka splits a topic into partitions so many consumers can work in parallel. Order is guaranteed only inside one partition.
Partition key
The field that decides which partition a message goes to, such as user_id. All events for one user land in the same partition, so they stay in order.
Offset
A consumer's bookmark in a partition: the position of the last message it finished.
Consumer group
A set of workers sharing a topic. Each partition is read by exactly one worker in the group.
At-most-once / at-least-once / exactly-once
Delivery guarantees. At-most-once may lose messages but never repeats. At-least-once never loses but may repeat. Exactly-once is at-least-once plus deduplication, and is costly.
Idempotent
Running the same operation twice has the same effect as running it once. Setting status = 'paid' is idempotent; adding $10 is not.
Back pressure
A way for a slow consumer to push back so producers slow down, instead of memory filling until something crashes.
Consumer lag
How many messages are waiting unprocessed. Rising lag is your early warning.
Dead letter queue (DLQ)
Where messages go after failing several retries, so one bad message doesn't block the rest.
Replay
Re-reading old messages from the log, for example to rebuild totals after fixing a bug.

Trade-offs, each with an example

  1. At-least-once vs exactly-once

    Example A click counter consumer crashes after adding 1 to the total but before saving its offset. On restart it reads the same click again and counts it twice. Fix: store each click_id you've counted (or make the write 'set count for window W to N'), so the retry is harmless.

    Default answer Choose at-least-once delivery plus idempotent consumers. Say what the dedup key is.

  2. Partition key: ordering vs hot partitions

    Example Keying ride events by driver_id keeps each driver's events in order. Keying ad clicks by ad_id puts a viral ad's 50k clicks per second in one partition while others sit idle. Fix: key by ad_id + random suffix (0 to 9), then combine the 10 partial counts.

    Default answer Pick the key from what must stay ordered, then check whether one key value can dominate.

  3. Synchronous vs asynchronous processing

    Example Posting a like returns 200 as soon as it's in Kafka (5 ms). The like count on the page updates a second later. If the like had to update 3 databases before returning, a slow analytics DB would slow every like.

    Default answer Do only the essential write in the request; push everything else to the log.

  4. Back pressure: buffer, shed, or slow down

    Example Black Friday triples event volume and consumers fall 20 minutes behind. You can let the log buffer it (Kafka keeps 7 days), add consumers up to the partition count, drop low-value events like debug logs, or tell producers to sample.

    Default answer Alert on consumer lag, autoscale consumers, and decide upfront what can be dropped.

  5. DLQ vs blocking retry

    Example One malformed event makes the parser throw. Retrying forever blocks that partition and everything behind it. After 3 tries, move it to a DLQ and keep going, then fix and replay it later.

    Default answer Bounded retries with backoff, then DLQ, with an owner and an alert on DLQ size.

Read more on ByteByteGo (free)

03Real time fanoutSomething happens and many connected people must see it within a second or two.

Clients hold open connections to gateway servers. An event goes onto a pub/sub bus, and each gateway pushes it to the clients connected to it.

Typical questions Chat (Slack, WhatsApp), live sports scores, collaborative cursors, stock tickers, flag changes streaming to SDKs.

Excalidraw starter: 03-real-time-fanout.excalidraw

Terms in plain English

Fanout
Copying one event out to many recipients. A message to a 10,000 member channel is a 1-to-10,000 fanout.
Short polling
The client asks 'anything new?' every few seconds. Simple, but wasteful and adds delay.
Long polling
The client asks, and the server holds the request open until there's news or a timeout, then the client asks again.
Server-Sent Events (SSE)
One long HTTP response the server keeps writing to. Server to client only. Works through most proxies.
WebSocket
A persistent two-way connection. Both sides can send any time. Best for chat and games.
Gateway (connection server)
A server whose job is holding many open connections (often 50k to 500k each) and pushing messages down them.
Pub/sub
Publish/subscribe: publishers send to a topic, and every subscriber of that topic receives a copy.
Connection registry / presence
A lookup of which user is connected to which gateway, and whether they're online.
Fanout on write vs fanout on read
On write: when something is posted, copy it into each follower's inbox right away. On read: store it once and assemble each user's view when they open the app.
Sequence number
An increasing ID per channel so a reconnecting client can say 'send me everything after 1042'.

Trade-offs, each with an example

  1. WebSocket vs SSE vs polling

    Example A live scoreboard only needs server-to-client updates, so SSE works and passes through corporate proxies easily. Chat needs both directions, so WebSocket. A dashboard that refreshes every 30 s is fine with polling and needs no special infrastructure.

    Default answer Pick the simplest transport that meets the latency and direction needs, and keep polling as the fallback.

  2. Fanout on write vs fanout on read

    Example On a social feed, a normal user with 200 followers posts: writing 200 inbox entries is cheap, and reads are instant. A celebrity with 50M followers posts: 50M writes take minutes. Hybrid: push for normal users, and merge celebrity posts in at read time.

    Default answer Push for the common case, pull for the heavy hitters, and say where the threshold is.

  3. Per-connection cost vs batching

    Example A stock ticker changes 50 times a second. Sending each tick to 1M clients is 50M messages a second. Coalescing to the latest value every 250 ms cuts that to 4M with no visible loss.

    Default answer Batch or coalesce updates when the latest value is all that matters.

  4. Gateway sharding: by user vs by topic

    Example Slack-style: sharding channel servers by channel ID keeps a channel's history and ordering in one place, and gateways in each region subscribe to the channels their users need. Sharding by user means each user lands on one gateway, so a big channel's message must go to many gateways.

    Default answer Say what you shard on and how a message finds the right gateways (a registry or pub/sub topics).

  5. Reconnect: lose messages vs replay

    Example A phone goes through a tunnel for 40 s. Without history, messages sent in that window are gone. With a per-channel sequence number and a short history store, the client reconnects and asks for everything after its last sequence number.

    Default answer Store recent history keyed by sequence number so reconnects can catch up.

Read more on ByteByteGo (free)

04Batch and analyticsAnswers can be minutes or hours old, and questions scan huge amounts of data: 'revenue by region last quarter'.

Land the raw data cheaply, then run scheduled jobs that compute summaries into a warehouse built for big scans.

Typical questions Daily reports, billing runs, experiment results, ad click aggregation for invoicing, ML training data.

Excalidraw starter: 04-batch-analytics.excalidraw

Terms in plain English

Batch processing
Processing a large chunk of data on a schedule (every hour, every night) rather than event by event.
Stream processing
Processing each event (or small time window) as it arrives, with tools like Flink or Kafka Streams.
Data lake
Cheap storage (like S3) holding raw files in their original form until someone needs them.
Data warehouse
A database tuned for analytics queries over lots of history (Snowflake, BigQuery, Redshift). It stores data by column.
Columnar storage
Storing each column together, so 'sum revenue' reads only the revenue column, not every whole row.
ETL / ELT
Extract, transform, load: pull data, clean it, load it. ELT loads raw data first and transforms inside the warehouse.
Lambda architecture
Run two paths: a batch path that's accurate but slow and a stream path that's fast but approximate, then merge them.
Kappa architecture
Only a stream path. To recompute history you replay the log through the same code.
Window / watermark
A window groups events by time (clicks per minute). A watermark is the point where you decide 'events older than this are probably all in'.
Late data
Events that arrive after their window closed, like a phone that was offline for an hour.
Partitioning by date
Storing files in folders by day so a query for 'last week' only reads 7 folders.

Trade-offs, each with an example

  1. Freshness vs cost (batch size and frequency)

    Example Running the revenue job nightly costs 1 cluster-hour. Running it every 5 minutes gives near-live numbers but runs 288 times a day, each with startup overhead. Finance needs daily; the sales dashboard wants hourly.

    Default answer Ask who reads the numbers and how fresh they need them, then pick the slowest schedule that satisfies them.

  2. Lambda vs Kappa

    Example Ad click counting: Lambda gives a fast streaming count for the dashboard and a nightly batch count for billing, but you maintain the logic twice and they can disagree. Kappa uses one streaming job, and to fix a bug you replay last week's log through the new version.

    Default answer Prefer Kappa when the log keeps enough history to replay; use Lambda when billing needs a separate audited batch path.

  3. Late data: wait vs publish and correct

    Example Clicks for the 10:00 to 10:01 window: waiting 5 minutes catches 99.9% of them but delays the number. Publishing at 10:01:05 is fast, and late clicks either get dropped or trigger a correction to an already-reported number.

    Default answer Use a watermark (for example 2 minutes), then send very late events to a correction path.

  4. Raw vs pre-aggregated storage

    Example Keeping every raw click lets you answer any new question later but costs storage and scan time. Storing only per-minute counts per ad is tiny and fast but can't answer 'clicks by browser' if you didn't count that.

    Default answer Keep raw data in the cheap lake, and serve dashboards from aggregates.

  5. Cost per query

    Example A dashboard that scans a 10 TB table every time someone loads it runs up a large bill. Partitioning by date plus a daily summary table means the dashboard reads megabytes.

    Default answer Partition by time and precompute the summaries the dashboards use.

Read more on ByteByteGo (free)

05Search and filteringUsers type words, pick filters and facets, and expect the best matches first, not just exact matches.

Keep the database as the truth and copy data into a search index built for text and ranking. Keep the copy updated through a change stream.

Typical questions E-commerce product search, typeahead/autocomplete, log search, job search with filters, documentation search.

Excalidraw starter: 05-search-filtering.excalidraw

Terms in plain English

Inverted index
A map from each word to the list of documents containing it, like the index at the back of a book. It's why search is fast.
Analyzer / tokenizer
Rules that turn text into searchable terms: lowercasing, splitting on spaces, stemming 'running' to 'run'.
Relevance / ranking
Ordering results so the best match comes first. BM25 is the standard text-scoring formula; business signals (sales, ratings) are mixed in.
Facet
A filter with counts, like 'Brand: Nike (120), Adidas (95)'.
Typo tolerance (fuzzy match)
Matching 'iphnoe' to 'iphone' by allowing a small edit distance.
N-grams / prefix index
Indexing word pieces ('iph', 'ipho') so partial words match, which is what powers autocomplete.
Shard / replica (search)
Shards split the index so it fits and searches in parallel. Replicas are copies that add query capacity and survive node loss.
Index freshness
How long before a change in the database shows up in search results.
CDC (change data capture)
Reading the database's change log and streaming each insert or update to other systems, like the indexer.
Trie
A tree of characters used for prefix lookup in autocomplete systems.

Trade-offs, each with an example

  1. Index freshness vs indexing cost

    Example A seller changes a price. Refreshing the index every second makes it searchable at once but costs CPU on every node. Refreshing every 30 s is cheaper, but search can show the old price for 30 s, so the product page should read the price from the database.

    Default answer Accept seconds of lag in search, and always show the authoritative value from the database on the detail page.

  2. Search the DB vs a dedicated index

    Example Postgres full-text search handles 1M products and simple queries with no extra system. At 100M products with typo tolerance, facets and custom ranking, a dedicated engine like Elasticsearch or OpenSearch earns its operational cost.

    Default answer Start with the database's search; move to a search engine when relevance and scale demand it.

  3. Shards vs replicas

    Example An index of 500 GB won't fit on one node, so you split it into 10 shards of 50 GB. If query volume doubles, adding replicas helps; adding shards doesn't, since each query still hits every shard.

    Default answer Shards for data size, replicas for queries per second and availability.

  4. Recall vs precision (typo tolerance)

    Example Allowing 2-letter typos finds 'iphnoe' but also matches 'phone' cases for 'iphone' searches. Limit fuzziness on short words, and rank exact matches above fuzzy ones.

    Default answer Fuzzy matching on, but rank exact matches higher and cap edits by word length.

  5. Autocomplete: precompute vs query live

    Example Top 10 suggestions for each prefix can be precomputed hourly from search logs into a trie or key-value store, and served in 5 ms. Live querying the full index for each keystroke is fresher but much heavier.

    Default answer Precompute popular prefixes and fall back to the live index for the long tail.

Read more on ByteByteGo (free)

06File and mediaLarge binary objects: photos, videos, documents. Upload, process (thumbnails, transcoding), and serve them fast worldwide.

Split the small metadata (title, owner, status) into a database and the big bytes into object storage. Clients upload straight to storage and download through a CDN.

Typical questions YouTube uploads, Google Drive/Dropbox, Instagram photos, attachments in chat or email.

Excalidraw starter: 06-file-media.excalidraw

Terms in plain English

Object storage (blob store)
Storage for whole files addressed by key, like S3. Very cheap and durable, but you replace a whole object rather than edit part of it.
Metadata
Small facts about a file: name, size, owner, upload status, storage key. Lives in a regular database.
Pre-signed URL
A temporary link, signed by your server, that lets a client upload or download one object directly to or from storage for a few minutes.
Multipart / resumable upload
Splitting a big file into parts (say 200 MB of a 1.6 GB file each), uploading them separately, then having storage join them. A failure only retries one part.
Transcoding
Converting a video into several formats and resolutions (240p to 4K) so every device and connection gets a playable version.
Adaptive bitrate streaming
Video cut into short chunks at several qualities; the player switches quality as bandwidth changes (HLS, DASH).
Storage tiers
Hot storage is fast and pricier; cold or archive storage is cheap but slow to fetch. Old files move to cold tiers.
Deduplication
Spotting identical files (or chunks) by their content hash and storing them only once.
Origin
The real storage behind a CDN. The CDN fetches from the origin on a cache miss.

Trade-offs, each with an example

  1. Upload through app servers vs direct to storage

    Example Streaming a 2 GB video through your API servers ties up a server thread and bandwidth for minutes. With a pre-signed URL, the client uploads directly to S3 and your API only writes a metadata row and hands out the URL.

    Default answer Always upload bytes directly to object storage; the API handles only metadata and authorization.

  2. Single upload vs multipart

    Example A 1.6 GB upload on hotel Wi-Fi fails at 90%. As a single upload, it starts over. As 8 parts of 200 MB, only the failed part retries, and parts can upload in parallel.

    Default answer Multipart for anything over about 100 MB, with resume support in the client.

  3. Process eagerly vs on demand

    Example Transcoding every upload into 6 resolutions right away costs compute on videos nobody watches (most get few views). Transcoding popular formats eagerly and rare ones on first request saves money but makes the first viewer wait.

    Default answer Eagerly make the common renditions; generate rare ones lazily or skip them.

  4. Hot vs cold storage

    Example Photos older than a year are rarely opened. Moving them to an infrequent-access tier can cut storage cost by about half, but each fetch costs more and may take longer.

    Default answer Use lifecycle rules to move old objects to cheaper tiers, and keep thumbnails hot.

  5. Public URLs vs signed URLs

    Example Public CDN URLs are simple and cache well but anyone with the link can share them. Signed URLs that expire in an hour protect private files but need generating per request and cache less well.

    Default answer Signed, expiring URLs for private content; plain CDN URLs for public assets.

Read more on ByteByteGo (free)

07Workflow orchestrationA business process with several steps across services that can each fail, need retries, wait for hours, or need undoing.

Model the process as a state machine whose progress is saved after every step, so a crash resumes where it left off instead of starting over or getting stuck.

Typical questions Order checkout (reserve, charge, ship), user onboarding, document approval, agent runs, data pipeline DAGs.

Excalidraw starter: 07-workflow-orchestration.excalidraw

Terms in plain English

Workflow
A defined sequence of steps with rules for what happens on success, failure and timeout.
State machine
A model with named states (PENDING, PAID, SHIPPED) and allowed moves between them.
Orchestration
One coordinator tells each service what to do next and tracks progress (Temporal, AWS Step Functions, Netflix Conductor).
Choreography
No coordinator. Each service listens for events and reacts ('payment succeeded' makes shipping start).
Durable execution
The engine records every step's result, so after a crash it replays history and continues from the last finished step.
Saga
A long transaction split into local steps, each with a compensating action to undo it if a later step fails.
Compensation
The undo for a step that already happened: refund a charge, release a reserved seat. It's a new action, not a rollback.
Retry policy
How many times to retry a failed step, how long to wait between tries (backoff), and which errors not to retry.
Timeout / heartbeat
A limit on how long a step may run, and a periodic 'still working' signal from long steps.
Stuck run
A workflow instance that is neither progressing nor failed, such as one waiting for an event that never comes.

Trade-offs, each with an example

  1. Orchestration vs choreography

    Example Checkout with 4 steps. With an orchestrator, the whole flow is in one place and 'where is order 123?' has one answer, but the orchestrator must be highly available. With choreography, services are loosely coupled, but adding a fraud check means changing who listens to what, and tracing a stuck order means searching 4 services' logs.

    Default answer Orchestrate flows that need a clear owner, visibility and compensation; use choreography for simple 'tell others something happened' events.

  2. Rollback vs saga compensation

    Example You charged the card, then shipping says out of stock. You can't wrap Stripe and your warehouse in one database transaction. The saga runs the compensation: refund the charge, release the reservation, email the user.

    Default answer Give every step that changes the outside world an explicit undo step.

  3. Where state lives

    Example If the order service keeps 'step 3 of 5' in memory, a deploy loses it. A durable engine or a workflow table persists each step's result, so a restart resumes at step 3.

    Default answer Persist workflow state after every step; never keep it only in memory.

  4. Retry aggressively vs fail fast

    Example Calling a shipping API that's down: retrying every 100 ms hammers it. Exponential backoff (1 s, 2 s, 4 s ... capped at 5 min) gives it time to recover. A 'card declined' error shouldn't be retried at all.

    Default answer Retry transient errors with backoff and jitter; fail fast on permanent errors.

  5. Debugging stuck runs

    Example A workflow waits for a 'document signed' event that was published before it subscribed. Without visibility, it waits forever. With a timeout on the wait and a dashboard of runs by state and age, it surfaces in hours.

    Default answer Give every wait a timeout and expose runs by state and age.

Read more on ByteByteGo (free)

08Transactional / financialMoney or inventory moves, and losing, duplicating or miscounting even one item is unacceptable.

A ledger in an ACID database is the single source of truth. Every request carries an idempotency key, events leave via an outbox, and a reconciliation job double-checks against outside systems.

Typical questions Payments, digital wallets, ticket or hotel booking, stock exchange orders, ledgers, inventory reservation.

Excalidraw starter: 08-transactional-financial.excalidraw

Terms in plain English

ACID
Atomic (all or nothing), Consistent (rules hold), Isolated (concurrent transactions don't see each other's half-done work), Durable (once committed, it survives crashes).
Transaction boundary
Exactly which writes must succeed or fail together in one database transaction.
Idempotency key
A unique ID the client sends with a request (often a UUID). If the same key arrives again, the server returns the first result instead of doing the work twice.
Double-entry ledger
Every money movement is written as two entries that cancel out: debit one account, credit another. The sum of all entries is always zero, which makes errors easy to spot.
Outbox pattern
Write the business change and an 'event to publish' row in the same database transaction; a separate relay publishes the event later. Both happen or neither does.
Two-phase commit (2PC)
A protocol that makes several databases commit together. Correct but slow and fragile, so usually avoided across services.
Reconciliation
Comparing your records against the bank's or payment provider's records (often daily) and flagging any mismatch.
PSP
Payment service provider, such as Stripe or Adyen, that actually talks to card networks.
Optimistic / pessimistic locking
Pessimistic: lock the row before changing it. Optimistic: change it only if its version number hasn't changed since you read it.

Trade-offs, each with an example

  1. Retries vs double charging

    Example The client sends 'pay $50', the network times out, and the app retries. Without an idempotency key, the user is charged $100. With a key, the server sees the key already succeeded and returns the original result. The same key is passed on to the PSP.

    Default answer Every payment request carries an idempotency key, stored with a unique constraint.

  2. One ACID database vs distributed transaction

    Example Moving $20 from Alice's wallet to Bob's: if both balances are in one database, a single transaction does it safely. If wallets are sharded across databases, you need 2PC or a saga with a pending state, both much harder.

    Default answer Keep things that must change together in one database; shard by account so most transfers stay local, and use a saga for the rest.

  3. Write to DB and publish an event: dual write vs outbox

    Example The service commits the payment, then crashes before publishing 'payment succeeded'. Shipping never hears about it. With an outbox, the event row is committed with the payment, and the relay publishes it after restart.

    Default answer Use the outbox (or CDC) whenever a database write must also produce an event.

  4. Pessimistic vs optimistic locking

    Example Concert tickets: 50k people try to book the last 100 seats. Row locks serialize everyone and pile up waits. Optimistic updates ('UPDATE seat SET held_by = me WHERE id = 7 AND version = 3') let most attempts fail fast and retry another seat.

    Default answer Optimistic locking for high contention with short operations; pessimistic when conflicts are rare but costly.

  5. Trust exactly-once vs reconcile anyway

    Example Even with idempotency and outbox, a PSP webhook can be lost or a refund done manually in the PSP dashboard. A nightly job matches every ledger entry to the PSP's settlement file and opens a ticket for each break.

    Default answer Always add reconciliation; it's the safety net that catches what the design missed.

Read more on ByteByteGo (free)

09RecommendationThe output is a personalized, ranked list, and what users click feeds back into what they're shown next.

A funnel: cheaply pull a few thousand candidates from millions of items, rank them with an expensive model, then apply rules for diversity and business needs.

Typical questions 'For You' feeds, 'customers also bought', YouTube up-next, job recommendations, people you may know.

Excalidraw starter: 09-recommendation.excalidraw

Terms in plain English

Candidate generation (retrieval)
The cheap first stage that narrows millions of items to a few thousand plausible ones, for example items similar to what you watched.
Ranking
Scoring each candidate with a heavier ML model that predicts how likely you are to click, watch or buy.
Re-ranking / filtering
Final adjustments: remove things you've seen, enforce variety, add ads or promotions.
Feature
An input to the model, such as 'user watched 3 cooking videos this week' or 'item's click rate'.
Feature store
A system that serves the same features for training (offline, in bulk) and for live requests (online, fast).
Embedding
A list of numbers representing a user or item, built so similar things have nearby vectors. Used for fast similarity lookup.
Collaborative filtering
'People like you liked this': recommendations from patterns in many users' behaviour.
Cold start
No history yet for a new user or new item, so behavior-based models have nothing to go on.
Explore vs exploit
Exploit: show what the model is sure you'll like. Explore: sometimes show something uncertain to learn more.
Offline vs online
Offline: batch work like training models nightly. Online: work done during the request, within the latency budget.

Trade-offs, each with an example

  1. One big model vs a staged funnel

    Example Scoring all 10M videos with a 50 ms model per item is impossible within a 200 ms request. Retrieval finds 1,000 candidates in 20 ms using embeddings, ranking scores those 1,000 in 80 ms, and re-ranking takes the top 50.

    Default answer Describe the funnel with rough counts and a latency budget per stage.

  2. Offline precompute vs online scoring

    Example Precomputing each user's top 100 nightly is cheap to serve but ignores what they did 10 minutes ago. Online ranking with fresh features ('just watched a cooking video') reacts in-session but costs compute per request.

    Default answer Precompute candidates offline and rank online with a few fresh session features.

  3. Cold start

    Example A new user has no history: show popular items in their region and ask for a couple of interests at signup. A new item has no clicks: use its content (title, category, embedding) and give it some guaranteed exposure.

    Default answer Name a fallback for both new users and new items.

  4. Explore vs exploit

    Example Always showing the predicted best item traps users in a bubble and the model never learns about new items. Reserving about 5% of slots for exploration costs a little short-term clicking but improves the model.

    Default answer Reserve a small exploration slice and measure its long-term effect.

  5. Optimize clicks vs long-term value

    Example Optimizing click rate rewards clickbait thumbnails. Optimizing watch time or 7-day retention rewards content people actually value, but that signal arrives later and is noisier.

    Default answer Pick the metric that reflects real user value, and keep guardrail metrics.

Read more on ByteByteGo (free)

10Events and notificationsSomething happens in the business, and the right people should hear about it on the right channel, once, at a sensible time.

Events go into a notification service that checks preferences and duplicates, then fans out to per-channel queues, whose workers call providers like APNs, FCM, email and SMS gateways.

Typical questions Order shipped emails, push alerts, SMS one-time codes, Slack-style mentions, daily digests, marketing campaigns.

Excalidraw starter: 10-events-notifications.excalidraw

Terms in plain English

Channel
A delivery route: push (APNs for Apple, FCM for Android), email, SMS, in-app inbox, chat.
Provider
The third-party service that actually delivers: APNs, FCM, SendGrid/SES for email, Twilio for SMS.
Device token
An ID the phone's OS gives your app so a push provider knows which device to deliver to.
Preferences
The user's settings: which notification types, on which channels, at what hours.
Suppression
Not sending, on purpose: opted out, quiet hours, bounced email address, or already sent today.
Dedup key
An ID such as (user_id, event_id, channel) used to make sure the same notification isn't sent twice.
Digest
Combining many events into one message: '12 new comments today' instead of 12 pushes.
Rate limit / frequency cap
A maximum number of notifications per user per period, and per provider per second.
Template
A reusable message layout with placeholders, rendered per user and language.
Fallback
Switching channel or provider when one fails, such as SMS if push isn't delivered within 5 minutes.

Trade-offs, each with an example

  1. Immediate vs digest

    Example A one-time login code must go out in seconds. 'Someone liked your post' x30 in an hour is better as one digest. Route by type: critical messages skip batching; social ones are batched into hourly or daily summaries.

    Default answer Classify notification types by urgency and batch the non-urgent ones.

  2. Retries vs duplicates

    Example The worker sends a push, FCM times out, and the worker retries. If the first send actually went through, the user gets two. A dedup key checked before sending, plus the provider's own idempotency when available, limits that to rare cases.

    Default answer Retry with backoff, check a dedup key before each send, and accept that push is at-least-once.

  3. One queue vs per-channel queues

    Example SMS provider has an outage. With one shared queue, retrying SMS messages clogs email and push too. Separate queues per channel (and per priority) isolate the failure.

    Default answer Separate queues per channel and per priority, each with its own rate limit.

  4. Respect preferences vs deliverability of critical messages

    Example A user muted all notifications, but a password-reset code or fraud alert must still arrive. Mark a small set of types as transactional that bypass marketing opt-outs (still within the law), and keep everything else subject to preferences.

    Default answer Separate transactional from marketing, and check preferences at send time, not when the event was created.

  5. Single provider vs fallback

    Example An email provider starts throttling during a campaign. With a second provider configured, workers switch over after error rates pass a threshold. That adds cost and setup, plus warming up sender reputation.

    Default answer Use a fallback provider for critical channels (SMS, login email), and a single provider for the rest.

Read more on ByteByteGo (free)

Words that come up in every pattern

Source of truth
The one place whose data wins when copies disagree. Say it first: 'Postgres is the source of truth; the cache and search index are copies.'
Idempotency
Make retried operations safe. Say what the key is: 'the order ID makes this charge happen once even if the request is retried'.
Online vs offline path
Online is what runs while the user waits (tight latency). Offline is background or batch work. Keep heavy work off the online path.
Decoupling with a log or queue
Put a durable buffer between producer and consumer so either can be slow or down. Then cover lag, back pressure and replay.
Degraded mode
What the user sees when the fast path fails: stale cached data, a 'notifications delayed' banner, polling instead of WebSocket.
Consistent hashing
A way to spread keys over servers so adding or removing a server moves only a small share of keys. Used by caches, Cassandra, DynamoDB.
Sharding
Splitting one dataset across many databases by a key (user_id). Great for scale; makes cross-shard joins and transactions hard.
Eventual consistency
Copies will agree soon, but not instantly. Fine for like counts; not fine for account balances.

Excalidraw starter diagrams

Each pattern has a starter diagram: the usual boxes and arrows, plus a yellow note of the trade-offs to talk through. Open one at excalidraw.com with Menu → Open, or drag the file onto the canvas.

To have all ten in your Excalidraw library, add the library in one click, or download system-design-patterns.excalidrawlib and drag it onto the Library panel. Then drag a pattern onto the canvas at the start of an interview and edit from there.

Habits that show up in every pattern

  • State where the source of truth lives before talking about caches or replicas.
  • Make every retried operation idempotent, and say what the idempotency key protects.
  • Keep the online serving path separate from the offline or analytics path.
  • Decouple producers from consumers with a log or queue, then talk about lag, back pressure and replay.
  • Describe the degraded mode: what the user sees when the fast path fails.

Say it like this

  • Before I draw anything, let me label this. Feeds are a read-heavy problem with a fanout component, so I'll lead with caching and how writes reach followers.
  • This is really a workflow problem, so I'll sketch it as a state machine first and then decide whether one orchestrator owns it or services choreograph through events.
  • Money is moving, so the ledger is the source of truth. Everything else is eventually consistent and we reconcile against it.

Bring it up when they ask

  • Design a news feed / URL shortener / notification system / payment flow.
  • How would you scale this to 10x?
  • Walk me through the trade-offs in your design.
  • Tell me about a system you designed. (Name its pattern to frame the story.)

Where it fits

LaunchDarkly
Flag evaluation (50T evals/day) is read heavy plus real time fanout: flag changes stream out to every SDK. Experimentation results are the batch and analytics pattern.
iii
A workflow and agent engine is the orchestration pattern almost by definition, with an event driven core. Expect questions about durable state, retries and stuck runs.