Quick revision
Every topic on one page, shortest version first. Read the one-liners top to bottom, open the ones that feel shaky, and go back to the full page only where you need to.
Start from scratch
- It is about who does what and where data lives. It is not about knowing more tools.
- Every part you add has a price. Naming that price is the core skill.
- There is no single right answer. Only answers that fit, and costs you chose on purpose.
- The same few moves repeat at every size. You are learning about fifteen ideas, not a hundred.
Say this: System design is choosing where things live, and what breaks when they fail. Then saying out loud what each choice cost you.
Open the full page →- New grads get light design questions at some product companies; full rounds are mostly mid-level and up.
- Learn the five-stage order and about ten core concepts before any big problem.
- Ten small problems cover almost everything a new-grad round asks.
- Practise out loud, with a clock, writing your answer before reading ours.
- Keep DSA and projects as your main prep; design is the tie-breaker.
Say this: For new grads, system design is a short round about asking good questions and drawing a few sensible boxes. Learn the order, ten ideas and ten problems.
Open the full page →- The question is vague on purpose. Making it clear is the first thing they score.
- You talk for most of the time. Silent thinking teaches the interviewer nothing.
- Drawing too early is a very common failure, and it is not about knowledge.
- They interrupt on purpose. Being interrupted is normal, not a bad sign.
Say this: They score how you think, out loud, in real time. Not the picture you end up with.
Open the full page →- Having a fixed first move is what stops you freezing.
- Stages 1 to 3 take about a third of the time. They make everything after them easy to defend.
- Every box in Stage 4 must point back to Stage 1 or Stage 3.
- Stage 5 is where senior level shows: say the cost of each decision, out loud.
Say this: Requirements, lifecycle, numbers, design, trade-offs. Same order, every time.
Open the full page →- Slack is the time before a person notices, not the time before the machine finishes.
- No slack means do it now, inside the request. Slack means queue it and group it.
- Two products that look the same get opposite designs when their slack is different.
- Every problem page in this app answers this question directly.
Say this: Before drawing anything, ask how long the system has before someone notices. That answer designs half the system for you.
Open the full page →- Latency is per request. Throughput is per second. Improving one often hurts the other.
- A cache trades freshness for speed. A replica trades freshness for safety and more reads.
- Partitioning is the only way past one machine's write limit. Replication does not help writes.
- Idempotent means safe to repeat. On a network, any message can end up repeated.
Say this: You do not need all of these today. You just need to not get stuck when the word shows up on the next page.
Open the full page →Measuring things
- What it costs you: Chasing the wrong one wastes weeks. Speeding up code that was never the bottleneck buys you nothing. And building for scale you do not have costs you on every future feature, because a spread-out system is slower to change than a simple one.
- Adding servers to fix a problem that is already there at zero load.
- Assuming a system that is fast today will stay fast. Speed now tells you nothing about the shape of the curve.
Say this: "Is it slow with one user, or only when busy? If it is slow when quiet, that is a performance problem and more machines will not help. If it gets worse with load, something shared is running out and I want to know what before I spend money."
Open the full page →- What it costs you: Many techniques that raise throughput add latency, and many that cut latency leave capacity unused. Batching, queueing and connection pooling all get more work done per second by making single requests wait. You have to know which of the two your users feel.
- Quoting averages. They hide the tail. Quote p50 and p99.
- Chasing throughput on a path where a person is waiting.
- Assuming latency gets slowly worse as you near capacity. It does not. It hits a wall.
Say this: "Latency is one request. Throughput is requests per second. I would batch here, because nothing is waiting on any single write. That raises throughput and adds a little latency nobody can feel. On the checkout path I would not, because there one person is watching their one request."
Open the full page →- What it costs you: Memorising numbers can make you sound sure about a system you have never measured. Real machines vary a lot. Use these numbers to choose between two designs. Never use them to promise a speed to a room full of people.
- Quoting numbers with fake precision. "About half a millisecond" is right. "0.47 ms" is a claim you cannot back up.
- Forgetting that a round trip crosses the distance twice. People quote the one-way number and end up half wrong.
Say this: "A round trip inside one datacenter is well under a millisecond, so I am not worried about lots of small calls there. Across regions it is over 100 ms, so I will allow at most one of those per request and design around it."
Open the full page →- What it costs you: It takes time, and an early number can anchor you. Two minutes estimating is two minutes not designing. And a number you picked badly at the start will quietly shape everything after it. Say your assumptions out loud, so a wrong one gets corrected instead of growing.
- Doing the maths and then designing as if you had not. The estimate has to change a decision, or it was decoration.
- Fake precision. "1,847 requests per second" from made-up assumptions is worse than "roughly two thousand".
- Forgetting peak traffic, then being caught out by the sale-day question later.
Say this: "Ten million daily users, twenty actions each, so about two thousand per second on average and call it six thousand at peak. Reads are maybe fifty to one against writes. So the hard part here is read fan-out, not durability."
Open the full page →How a request reaches you
- What it costs you: Answers are cached all over the internet: in the browser, the operating system, the router, the internet provider. Those caches only loosely respect your TTL. So a DNS change is not a switch you flip. It rolls out over minutes to hours, and some clients ignore it completely. That makes DNS a poor way to fail over on its own.
- Treating DNS as a load balancer. It has no idea which servers are healthy or busy.
- Trusting your TTL. Plenty of resolvers do not.
- Forgetting DNS lookup time in the time budget of a first request.
Say this: "DNS routes users to the nearest region, not to a specific server. That is the load balancer's job. I would not rely on DNS for failover, because cached answers mean minutes of users still hitting the dead address. Anycast or a global load balancer handles that properly."
Open the full page →- What it costs you: Every step up in promises costs time. TCP promises delivery and order, and pays for it with handshakes and resends. HTTPS adds at least one more round trip for the TLS handshake (two with TLS 1.2). Styles with lots of small calls multiply those costs by the number of calls, which is how a design gets slow without any single part being slow.
- Choosing UDP for speed, then rebuilding retries and ordering on top of it.
- Treating an RPC call like a local function. It can fail, hang, or run twice.
- Tuning the wire format when the real cost is making twenty calls one after another.
Say this: "REST over HTTP at the edge, because anything can use it and GETs are cacheable by the CDN. gRPC between internal services, because I control both ends and want the compact encoding and a schema. And I would group these calls before I worry about either, because twenty round trips cost more than the format does."
Open the full page →- What it costs you: Doing this well costs you flexibility up front. A versioned API means running two versions at once for a while. Cursor pagination means clients cannot jump to page 500. Careful error contracts mean writing down failure cases instead of letting an exception leak out. All of that is work you do before anyone has complained.
- A list endpoint with no pagination at all. It works until your biggest customer arrives.
- Offset paging on a sharded store, which gets dramatically worse as shards grow.
- Returning 200 with an error inside the body. Now nothing can retry correctly.
- Removing a field because "nobody uses it". Someone often does, and you will hear about it from them.
Say this: "List endpoints are cursor-paginated, with the cursor opaque so I can change what is inside it. Changes are additive by default, and I only version when the meaning of a field changes. Errors carry a stable code plus Retry-After on 429 and 503, so clients know what is safe to retry. Cost: no jumping to page 500, and no total count without a separate query."
Open the full page →- What it costs you: One more hop, one more thing to configure, and one more thing that can be set up wrongly in a way that affects everything at once. It is also a single point of failure unless you run more than one. And putting too much logic in it creates a part that nobody owns and that everything depends on.
- Forgetting the proxy needs a backup of its own. It is now in front of everything.
- Losing the client IP, then rate limiting every user as if they were one person.
- Letting the gateway collect business logic until it is the riskiest deploy you have.
Say this: "One reverse proxy in front doing TLS, compression and rate limiting, so no service repeats that work. It is also the load balancer (same box), and I will run at least two of them, because it is now in front of everything."
Open the full page →- What it costs you: It is one more hop (a fraction of a millisecond) and one more thing that can fail, so it needs a backup of its own. It also pushes you to keep no user state on your servers. If a server holds a session in memory, every request from that user has to come back to that same server, and you have lost half the benefit.
- Drawing one load balancer and calling the design highly available. That box is now the single point of failure.
- Forgetting connection draining, and dropping requests on every deploy.
- Reaching for sticky sessions instead of taking state off the servers.
Say this: "Layer 7 balancer, least-connections, active health checks on a cheap endpoint that does not touch the database. Servers hold no session state, so any server can take any request. Cost: an extra hop, and I need at least two balancers, or the balancer is the single point of failure I just drew."
Open the full page →- What it costs you: Every box in the request path adds a network hop, a configuration you have to get right, and something that must itself be redundant. Stack a CDN, a load balancer, a gateway and a sidecar proxy and you have four hops before your code runs, four places a timeout can be set wrongly, and four teams who can each break every request. The gateway carries a further risk: it is the easiest place to put logic that belongs in a service.
- Saying an API gateway replaces the load balancer. The gateway runs as several copies, so something must balance across them.
- Drawing a gateway, a load balancer and a reverse proxy as three hops when one product does all three.
- Letting response aggregation in the gateway grow into business logic.
- Forgetting that layer 4 balancing cannot route by path or retry an HTTP request.
Say this: "One layer 7 load balancer in front, which also terminates TLS. Behind it an API gateway, because partners call us with API keys and need per-key quotas. Each internal service is balanced by the platform. If we only had our own web client, I would drop the gateway and do auth in the services."
Open the full page →Storing data
- What it costs you: Choosing relational costs you work once one machine is not enough. You have to split the data yourself, and joins and transactions across those splits get painful. Choosing non-relational costs you flexibility. You must know your queries before you store the data, and any new question means rewriting the data or copying it into a second system.
- Naming a database instead of naming how you will read the data.
- Claiming non-relational stores "cannot do transactions". Many can, within one partition. Know the limit you are describing.
- Choosing for write volume you never estimated.
Say this: "Postgres for the core, because bookings need a real transaction. The event stream is 50k writes a second and only ever read by device id, so that goes in a partitioned key-value store. Cost: two systems to run, and no transaction covers both, so I will make writes to the stream safe to repeat."
Open the full page →- What it costs you: Every index makes writes slower, because each insert, update and delete has to update the index too. Indexes use disk and memory. And an index the query planner never chooses is pure cost with no benefit.
- Adding an index on every column "to be safe". You have now made every write slower, for queries nobody runs.
- Assuming an index exists because the column is important. It exists because someone created it.
- Missing the N+1, because each single query looks fast in the log.
Say this: "That query filters by user and sorts by time, so a composite index on (userid, createdat desc) serves both the filter and the sort. Cost: another index to maintain on a write-heavy table, and it will not help any query that filters on time alone."
Open the full page →- What it costs you: Every level of protection costs concurrency. Stronger isolation means more waiting, more lock contention and more deadlocks. Pessimistic locking makes writers queue. Optimistic locking makes writers retry, which is cheap when conflicts are rare and terrible when they are common. And a transaction held open across a network call ties up a connection while you wait on something you do not control.
- Assuming the default isolation level protects you. It usually does not.
- Read, decide in application code, then write. That gap is the bug.
- Holding a transaction open across a network call to another service.
- Using serializable everywhere and being surprised by aborted transactions under load.
Say this: "The reservation is one conditional update (set the seat to held where it is still free), so there is no gap between checking and writing, and the loser gets zero rows changed. Holds expire after ten minutes. Cost: that row is a serialisation point, so a single hot event has a write ceiling on it, which I accept because the inventory is finite anyway."
Open the full page →- What it costs you: Stronger isolation means more waiting or more aborted transactions. Locking implementations make transactions queue and deadlock more often. Snapshot-based implementations keep old row versions around and abort conflicting transactions, so the application must retry. Serializable is correct by construction and costs the most throughput under contention.
- Assuming the default level is serializable. In PostgreSQL it is read committed; in MySQL InnoDB, repeatable read.
- Using serializable or repeatable read without retrying on serialization failures (SQLSTATE 40001).
- Treating "repeatable read" as one behaviour. PostgreSQL gives snapshot isolation; MySQL mixes snapshot reads with locking writes.
- Forgetting write skew: no row is overwritten, yet the rule is broken.
Say this: "Postgres at its default, read committed. The seat booking is a single conditional update, so it is safe at that level. The rota change checks a rule across several rows, so that one transaction runs at serializable with a retry on 40001. Cost: under contention some of those transactions abort and retry, which I accept because the rule cannot be broken."
Open the full page →- What it costs you: Pessimistic locking costs concurrency: writers to a hot row queue one at a time, a lock held across slow work blocks everyone behind it, and two transactions locking rows in different orders deadlock. Optimistic locking costs wasted work: every conflict throws away an attempt and repeats it, which is cheap when conflicts are rare and collapses into a retry storm when they are common.
- Holding a
FOR UPDATElock while calling a payment provider or waiting for a user. - Optimistic locking with unlimited retries. Cap the attempts and return a clear conflict error.
- Forgetting to check rows affected, which turns the version check into a no-op.
- Reaching for either one when a single conditional
UPDATEwould do the check and the write atomically.
Say this: "Profile edits use optimistic locking with a version column, because two people rarely edit the same profile and it works across the form's two HTTP requests. The flash-sale stock is a single conditional decrement, so there is nothing to lock. The job table uses FOR UPDATE SKIP LOCKED so workers never block each other. Cost: optimistic writes can fail and the client must retry, which at this contention is about one in a hundred."
Open the full page →- What it costs you: The pool is a queue, so when it is full, requests wait. A pool that is too small becomes your bottleneck while the database sits idle. Pools also carry state. A connection handed back mid-transaction, or with a session setting still on, causes bugs that show up in unrelated requests later.
- Fixing timeouts by making the pool bigger. That usually moves the queue into the database and makes it worse.
- Holding a database connection while calling an external API. Never do work you do not control while holding something scarce.
- Forgetting that pool size multiplies by the number of application instances.
Say this: "Pooled connections, sized at roughly four times the database core count, with a two-second timeout on getting one so we fail fast instead of piling up. With autoscaling I would put pgbouncer in front, so total connections stay flat no matter how many app servers we run."
Open the full page →- What it costs you: You now have two copies of the truth, and they can disagree. Users may see old data. You have added a part that can fail, and when it fails, everything it was protecting gets hit at once. And from now on you have to decide, for every item, when it stops being true.
- Saying "add a cache" without saying what clears it. That is the obvious follow-up question.
- Assuming a cache makes writes faster. It does not. It usually makes them slightly slower.
- Ignoring what happens when it is empty. That is where the outage lives.
Say this: "Cache-aside in Redis, five minute TTL with jitter, and I delete the key on write. Cost: on the rare path where the delete fails, a user can see data up to five minutes old. And if Redis dies the database takes the full read load, so I will coalesce misses to make one key mean one database read."
Open the full page →- What it costs you: Every strategy picks two of three: fast writes, a cache that is never stale, and no risk of losing a write. Write-through gives fresh data and safety but every write waits on both systems. Write-back gives fast writes and fresh reads but loses whatever was not yet flushed when the cache dies. Write-around and cache-aside keep writes simple and safe, and pay with misses and stale windows.
- Writing the cache before the database. A failed database write leaves a value in the cache that was never saved.
- Calling write-back "write-through with batching" and skipping the data-loss window.
- Cache-aside with no TTL. One missed delete and the stale value lives forever.
- Treating read-through and write-through as competitors. One is a read policy and one is a write policy.
Say this: "Cache-aside reads, delete-on-write after commit, ten-minute TTL as a backstop. Cost: a narrow race can leave a stale value until the TTL, which is fine for a profile page. For the view counter I would use write-back, batching increments in memory and flushing every second, and say that a crash loses about a second of views."
Open the full page →- What it costs you: Redis's features are also its operational surface: persistence settings, replication, failover, cluster slots and memory used by data structures all need understanding and monitoring, and a Redis that has become a database is no longer something you can flush. Memcached's simplicity costs you everything it does not do: no persistence, no built-in replication, no data types, so a node restart empties it and anything beyond get and set is your code's job.
- Saying Redis is "multithreaded now" without qualification. I/O threads exist; commands still execute one at a time.
- Leaving Redis on the default noeviction policy and using it as a cache, then getting write errors when memory fills.
- Treating Redis replication as durable. It is asynchronous, so a failover can drop acknowledged writes.
Say this: "Redis, because besides caching I need atomic counters for rate limiting and a sorted set for the leaderboard. Eviction set to allkeys-lru for the cache keys, and I treat everything in it as rebuildable, because replication is asynchronous. If this were only a page cache I would be happy with Memcached."
Open the full page →- What it costs you: You now have two stores that can disagree. A row can point at a file that was never uploaded, or a file can sit there with no row pointing at it, costing you money until someone notices. Object storage is also slow per operation compared to a database, it cannot answer questions like "all files bigger than 10 MB" without a separate index, and permissions become your problem: a bucket left public by mistake is a well-known cause of data leaks.
- Storing files as database blobs, then wondering why backups and replicas are so slow.
- Streaming a large upload through the application server because it is easier to write.
- Signing a URL from a client-supplied key, letting one user write over another user's object.
- No cleanup for pending rows and abandoned multipart uploads. They cost money forever.
Say this: "The file goes straight to object storage over a presigned multipart URL. My servers only sign it and never touch the bytes. The database row is created as pending and flipped to ready on the completion event, with a sweeper for anything still pending after an hour. Cost: the row and the object can disagree, so that sweeper is not optional."
Open the full page →More than one machine
- What it costs you: Every nine costs money and complexity. Going from 99.9% to 99.99% means removing the single points of failure on the critical path, making recovery automatic, and testing it. The work does not add up in a straight line, it multiplies. Redundancy also brings its own new failures: a failover that triggers by mistake can cause an outage that would not otherwise have happened.
- Promising nines without counting your dependencies. They cap you.
- An untested failover. If it has never been used, it is a guess.
- Forgetting that deploys and config changes cause a large share of outages, and redundancy helps with neither.
Say this: "Three nines is nearly nine hours a year, four nines is under an hour. I would aim for three on this path, and say up front that my payment provider caps me anyway. Active-active rather than active-passive, because a standby that never takes traffic is a standby I do not trust."
Open the full page →- What it costs you: Copies take time to arrive, so a replica can serve data that is out of date. The user who just wrote something is the most likely person to notice. You also pay for the extra machines. And failover is hard to get right: promote too eagerly and you get two leaders, too slowly and you are down.
- Assuming failover is automatic and instant. Somebody has to notice the failure, noticing has a timeout, and that timeout is downtime.
- Drawing async replication and then promising no data loss.
- Multi-leader with no plan for conflicts. That plan is the whole question.
Say this: "Single leader with two async followers, plus one semi-sync follower so a failover to that follower does not lose committed writes. Reads go to followers, except within ten seconds of a user's own write, which go to the leader. Cost: the leader is still my write ceiling, and failover means a few seconds of write errors."
Open the full page →- What it costs you: You lose the things that were free on one machine. A query that does not include the shard key has to ask every shard and merge the results. Transactions across shards need a special protocol, or a redesign. Joins across shards are painful. Uniqueness across shards is not free. And rebalancing when you add machines is a project, not a config change.
- Sharding by timestamp. Every write goes to the newest shard.
- Choosing a key that is not in your main query, so every read hits every shard.
- Assuming rebalancing is easy. Plan the logical-partition trick up front, or budget weeks later.
Say this: "Hash-partition by conversation id into 1024 logical partitions mapped onto 16 machines, so growing means moving partitions rather than re-hashing. Cost: any query not scoped to a conversation has to ask every shard, and a very large group chat can still make one partition hot. I would handle those specifically rather than change the scheme."
Open the full page →- What it costs you: Stronger promises cost speed on every operation, and availability during failures. Weaker promises cost you correctness bugs that only appear under load, in production, and cannot be reproduced on your laptop. They also move the difficulty into application code, where mistakes do not raise errors.
- Saying "eventually consistent" as if it were a design. How long is eventual, and what does the user see in the meantime?
- Applying one model to the whole system instead of per feature.
- Forgetting that eventual consistency lets reads go backwards.
Say this: "Feed and counts are eventually consistent, a couple of seconds of lag nobody notices. A user's own posts are read-your-own-writes, so I pin their reads to the leader for ten seconds after they write. The balance check at payment is strongly consistent, and I accept the extra latency there, because being wrong costs real money."
Open the full page →- What it costs you: Using CAP as a label makes you less accurate. Real databases are not "CP" or "AP" overall. The same system is one thing for one operation and the other for another. And CAP only describes what happens during a network split, which is rare. It says nothing about the normal case, which is where you actually live.
- Reciting "pick two of three". Network splits are not something you pick.
- Calling a database "AP" or "CP" as if it were fixed. Most are configurable per operation.
- Forgetting the "else" half: consistency costs speed even when nothing is broken.
Say this: "During a network split I would keep browse and cart available and let them reconcile, and I would make checkout refuse rather than risk overselling. And even with no split, that checkout path pays a few extra milliseconds per write for majority agreement. That is the price of never selling the same seat twice."
Open the full page →- What it costs you: Every decision needs a round trip to a majority, so it is slow compared to a local write, and it gets slower the further apart the machines are. The cluster stops accepting writes if it cannot reach a majority, and that is on purpose. And it does not get faster with more machines. More machines means a bigger majority to convince, so a 7-node cluster commits more slowly than a 3-node one.
- Offering to implement Raft. Nobody wants that. They want to know you would use something that already has it.
- Pushing application traffic through a consensus store.
- Trusting a lock with no fencing token and no idempotency behind it.
Say this: "Leadership is a lease in etcd, renewed every few seconds. Only the lease holder runs the job. Cost: a majority round trip per renewal, and if etcd is unreachable nobody runs the job, which I prefer to two nodes running it. And the job itself is safe to repeat, so even an overlapping lease is survivable."
Open the full page →- What it costs you: Doing it properly costs you simplicity. Logical clocks give you correct ordering but no relation to real time, so you cannot use them to answer "how long ago". Version vectors grow with the number of writers. And ordering everything through one place is correct and puts a bottleneck in the middle of your system. Meanwhile the wrong-but-easy answer, wall clock timestamps, works fine until it drops somebody's data with no error.
- Last-write-wins on user content, described as if it resolved the conflict rather than discarded one side.
- Assuming time only moves forward. NTP can step clocks backwards.
- Trusting a timestamp sent by a client.
- Reaching for vector clocks when partitioning by key would have removed the problem entirely.
Say this: "I would not order these by wall clock, because server clocks never agree exactly and the loser is discarded silently. All writes for one conversation go through one partition, so the order is just arrival order. Where I do need cross-machine ordering I would use a hybrid logical clock, so the value still looks like real time but the causal order is correct."
Open the full page →- What it costs you: Everything gets harder and more expensive. Cross-region replication lag is tens to hundreds of milliseconds, so consistency choices you did not have to think about become design decisions. You pay for duplicated infrastructure and for cross-region bandwidth, which is not cheap. Deploys have to be regional. Testing gets harder, because most failures only appear when the link between regions is slow rather than broken. And the failure mode people forget is that a bug now ships to every region.
- Going multi-region for uptime when deploys are what actually causes your outages.
- Claiming multi-region writes without saying how conflicts are handled or avoided.
- Forgetting that a surviving region has to absorb the failed one's traffic.
- Treating data residency as a detail. It constrains the design more than latency does.
Say this: "Each user has a home region where their writes happen, chosen at signup, with replicas elsewhere for reads and disaster recovery, so no two regions ever write the same row. Global uniqueness stays in one authoritative region and pays the cross-region hop. Cost: a routing layer, a migration path for users who move, and every region sized to absorb another one failing."
Open the full page →Doing work later
- What it costs you: The user gets "we received it", not "it is done", and your product has to say so. You inherit duplicate delivery, so every consumer must be safe to repeat. You gain a backlog with no limit, which can grow faster than you drain it. Ordering is not free. And debugging gets harder, because the failure is now in a worker somewhere, minutes after the request that caused it.
- Adding a queue and never mentioning idempotency. Duplicate delivery will happen sometimes.
- No dead letter queue, or one nobody watches.
- Assuming global ordering. You almost certainly want ordering per key.
- Treating a queue with no size limit as infinite capacity. It is failure, postponed.
Say this: "Order confirmation is synchronous, because the user needs a real answer. Everything after it goes on a queue, partitioned by order id so one order's events stay in sequence. Consumers are idempotent on message id, five retries with backoff, then a dead letter queue with an alert. Cost: the receipt email can be a minute late, which is fine, and I need to watch backlog growth rather than size."
Open the full page →- What it costs you: You need somewhere to remember what you have already done: a key store with a retention window. That store is now on the path of every write. You have to decide how long to remember, and what to return for a repeat. Ideally the original result, which means storing the response too. And you have to pick the key carefully, because a bad key either misses real duplicates or blocks requests that were meant to repeat.
- Claiming a queue gives exactly-once delivery. It gives at-least-once, and you supply the rest.
- Generating a fresh key on each retry.
- Checking "have I seen this key" and doing the work as two separate steps, with a crash window in between.
Say this: "Every write endpoint takes an Idempotency-Key. I insert it with a unique constraint in the same transaction as the work, so a retry hits the constraint and I replay the stored response. Cost: an extra table on the write path and a retention window to manage. Worth it, because at-least-once is the only delivery I can actually get."
Open the full page →- What it costs you: Push costs write amplification: one action becomes a million writes, storage for a million copies, and a backlog that delays everybody when one big account posts. Pull costs read amplification: every timeline load becomes a query across everyone you follow, merged and sorted, which is expensive and repeated constantly. The hybrid costs you two code paths for one feature, forever, plus a threshold nobody wants to own.
- Choosing push or pull without doing the read-to-write arithmetic out loud.
- No answer for the biggest account on the platform. That is the follow-up.
- Copying whole posts into inboxes instead of references, making edits and deletes a nightmare.
- Unbounded inbox lists, and fanning out to users who never open the app.
Say this: "Fan out on write into a capped inbox of post ids, because reads beat writes twenty to one. Above ten thousand followers I stop fanning out and merge those accounts in at read time from a heavily cached list. Cost: two code paths forever, and a threshold I tune from queue lag rather than guess."
Open the full page →- What it costs you: Every option here is worse than a local transaction. Two-phase commit costs availability, because a coordinator failure leaves the others holding locks. Sagas cost you all-or-nothing, because the system is briefly in a state where half the work is done and visible, and you have to write and test an undo action for every step. The outbox pattern costs an extra table and a relay process. There is no free version. The goal is to pick the compromise you can live with, and say which one you picked.
- Proposing 2PC across microservices without naming the blocking problem.
- A saga with no undo actions written down. That is just a list of calls.
- Assuming an undo restores the previous state. It does not. It adds a correcting event.
- Doing the step you cannot take back first.
Say this: "I would avoid a distributed transaction. Reserve stock and create the order in one local transaction, write the event to an outbox in that same transaction, and let a relay publish it. Payment is a saga step after that, with a refund as the undo. Cost: for a few seconds an order exists that is not paid for, so the UI shows it as pending, and I need a reconciliation job for the stuck cases."
Open the full page →- What it costs you: Every write happens twice, once to the log and once to the data, so you pay in disk speed and space. The log has to be trimmed, or it grows forever. Recovery time depends on how much of the log is unapplied, so rare checkpoints mean fast writes and slow restarts. And a truly durable write means a real fsync, which is far slower than a write that only reached the operating system's buffer.
- Describing the log but applying the change first. The mechanism depends on that order.
- Confusing a write with a durable write. Without fsync, "committed" means "in memory somewhere".
- Forgetting checkpointing, then being surprised that recovery takes 40 minutes.
Say this: "Writes go to an append-only log, fsynced with group commit, then applied. Cost: every byte is written twice, and I have to checkpoint or recovery time grows without limit. The bonus is that the log is already the replication stream and the CDC feed."
Open the full page →- What it costs you: The consumer sees database rows, so it is tied to your schema. Rename a column and something downstream breaks. It is asynchronous, so consumers are always a little behind. The log itself is ordered, but once changes are spread across stream partitions, ordering holds only per key. And it is real infrastructure to run: connectors, positions, schema handling, and a plan for a consumer that falls so far behind that the log it needs has already been deleted.
- Writing to the database and a second system separately. They will drift.
- Treating row changes as business events and guessing the intent from differences.
- No plan for a consumer that falls behind the log retention.
Say this: "The search index is fed by CDC off the database log, so it cannot miss a write, including ones made outside the application. Indexing is safe to repeat because it writes the whole document. Cost: about a second of lag, a tie to the schema, and I need a reconciliation job, because long-running pipelines tend to drift."
Open the full page →- What it costs you: Streaming buys freshness and pays with complexity: late and out-of-order events, state you must keep in the middle of a running job, and a much harder story when you need to fix a bug in yesterday's numbers. Batch buys simplicity and correctness and pays in latency (results are hours old), plus the cost of reprocessing everything each run. Running both, to get freshness and correctness, means writing the same logic twice and keeping the two agreeing.
- Building a streaming pipeline for a number nobody acts on quickly.
- Aggregating by processing time and calling it hourly counts.
- No answer for late events beyond the watermark.
- Not keeping the raw events, so a logic bug can never be corrected.
- Claiming exactly-once without idempotent writes at the output.
Say this: "Events land in object storage raw and also feed a stream that aggregates into tumbling hourly windows by event time, with a five minute watermark and late events sent to a side output. Aggregates are keyed by window so a re-run overwrites rather than double-counts. Cost: results are five minutes behind rather than instant, and I keep raw events forever so a logic fix is a re-run rather than a permanent hole."
Open the full page →Common patterns
- What it costs you: You now have copies of your content everywhere, and clearing them is not instant. A bad deploy or a wrong image can stay live for minutes. Getting cache headers wrong can produce the worst bug in this area: a private response cached and then served to a different user. You pay for bandwidth. And debugging is harder, because the answer depends on which edge location the user reached.
- Assuming a purge is instant everywhere. It is not, and browser caches are out of your reach entirely.
- Caching a logged-in response with no per-user cache key.
- Long TTLs on unversioned filenames, which makes every mistake expensive to fix.
Say this: "Static files get a content hash in the filename and a one-year immutable cache, so I never purge. The HTML has a 60-second TTL with stale-while-revalidate. Logged-in responses are no-store. Cost: bandwidth, and any mistake on a non-versioned path takes minutes to undo worldwide."
Open the full page →- What it costs you: You will sometimes reject real traffic, and it hits your biggest customers hardest, along with anyone behind a shared IP address: an office, a university, a mobile network. You need somewhere to keep the counters. If that store is shared, it is now on the path of every request. If it is per server, your real limit is the configured limit times the number of servers.
- Limiting by IP only, then blocking an entire office.
- A shared counter with no answer for what happens when it is down.
- Returning a bare 429 with no Retry-After, which teaches clients to retry immediately.
Say this: "Token bucket at the gateway, keyed by API key with a per-IP fallback, counters in Redis with a sliding window. Burst of 100, sustained 20 a second. If Redis is unavailable I allow the traffic and rely on a rough per-server limit. A limiter outage should not take the API down, and I am accepting the abuse window that creates."
Open the full page →- What it costs you: It is more complex than a remainder, and someone has to maintain the ring: which nodes exist, and getting every client to agree on that view. Plain consistent hashing also spreads unevenly, so you need virtual nodes to fix it, which is more bookkeeping. And it still does nothing about one key being hot. It balances keys, not traffic.
- Describing the ring but leaving out virtual nodes. The balancing behaviour depends on them.
- Claiming it solves hot keys. It does not.
- Using it where a fixed partition count would have been simpler.
Say this: "Consistent hashing with about 150 virtual nodes per server, so adding a cache node moves roughly a fifth of the keys instead of all of them, and losing one spreads its load across everyone rather than doubling its neighbour. Cost: a ring the clients have to agree on, and it still does not help if one key is hot."
Open the full page →- What it costs you: It can say yes when the answer is no. Those are false positives, so every yes has to be checked against the real store. It can never say no when the answer is yes, which is what makes it safe. You cannot delete from a standard bloom filter, and you cannot list what is in it. And the false positive rate rises as you add items, so a filter sized for a million entries gets bad at ten million.
- Treating a positive as an answer instead of a hint.
- Sizing for today's data, then watching the error rate climb.
- Trying to delete from a standard filter and creating false negatives.
Say this: "A bloom filter of existing ids in front of the cache, about 1.2 MB per million keys at a 1% error rate, so lookups for ids that never existed die in memory instead of hitting the database. Cost: 1% of real lookups do a pointless query, and new ids must be added to the filter on write."
Open the full page →- What it costs you: Every technique here trades exactness or freshness for throughput. Sharded counters make reads more expensive, because you have to add the shards up. Approximate structures give you a number that is close but wrong. Batching in memory means losing the last few seconds of counts if a process dies. Pick which of those you can live with, and say so.
- Treating stock as a counter. It is a resource people compete for.
- Adding up the shards on every request instead of caching the total.
- Losing in-memory batches without ever admitting that it happens.
Say this: "View counts batch in memory per server, flush every second into one of 50 shard rows, and the displayed total is a cached sum refreshed every few seconds. Cost: the number is a couple of seconds old, and a crash loses under a second of counts. I would not use any of this for remaining tickets. That needs one row and a conditional update."
Open the full page →- What it costs you: The mapping is rough at the edges. Two points a metre apart can land in different cells, so you have to search the neighbouring cells too and then filter by real distance. Cell size is a tuning problem that changes with density: a size that works in a village is wrong in a city centre. And the results always need a final exact-distance pass, because cells are squares and your query is a circle.
- Forgetting neighbouring cells and silently missing the nearest result.
- One fixed cell size everywhere, so city queries return 50,000 candidates and rural ones return none.
- Ranking by straight-line distance when the product needs arrival time.
Say this: "Geohash at 6 characters, roughly a kilometre, with current driver positions in a Redis sorted set per cell. A search reads my cell plus the eight neighbours, then ranks the candidates by estimated arrival time, not straight-line distance. Cost: positions are a few seconds old, and I need to widen the search in empty areas."
Open the full page →- What it costs you: A second copy of your data that can drift from the source, and now you own keeping it in step. Indexing is expensive at write time, and the index is near-real-time rather than instant, so a user may search for something they just created and not find it. Relevance tuning is an ongoing job with no end. And how you split and normalise text is baked into the index, so changing it means rebuilding everything.
- Making the search index the source of truth. It is derived data and it will drift.
- Writing separately from the application to both the database and the index.
- Deep pagination with large offsets, which gets much worse as shard count grows.
- Splitting a small index into too many shards, making every query slower for nothing.
Say this: "Postgres stays the source of truth. The search index is fed by CDC and holds whole documents, so re-indexing is safe to repeat. Ranking is BM25 plus popularity and stock. Cost: about a second of lag, so a user searching for something they just created may not find it, so I read their own items from the database instead."
Open the full page →- What it costs you: All of them mean holding connections open, so your servers now hold state in a way plain request-response does not. Load balancers have to handle long-lived connections. A deploy drops everyone at once, and they all reconnect together. And capacity is measured in connections at once, not requests per second. Every option needs a plan for reconnecting, and a way to catch up on what was missed while disconnected.
- Choosing WebSockets by default because it sounds more capable.
- No reconnect-and-catch-up story, so users silently miss messages.
- Forgetting that deploys disconnect everyone at the same moment.
Say this: "SSE, because updates only flow server to client and reconnection with last-event-id is built in. Connections are grouped by channel so one server holds the subscribers for a topic. Cost: I now have long-lived connections, so deploys need a slow roll and clients need randomised reconnect delays, or every restart is a self-inflicted spike."
Open the full page →- What it costs you: A circuit breaker returns errors for requests that might have worked, so you trade away some successful requests on purpose for the survival of the system. It has thresholds to tune, and badly tuned ones either trip constantly or never trip at all. Retries multiply load: three retries means up to four times the traffic, at the moment you can least afford it. And any retry needs idempotency behind it, or you get duplicate side effects.
- Retrying without idempotency and creating duplicate side effects.
- Growing delays with no randomness, producing one synchronised retry wave.
- A breaker with no defined fallback. You fail fast into a blank page.
- No timeout at all, which makes everything else here irrelevant.
Say this: "Every outbound call gets a timeout just above p99, two retries with growing delays and full jitter, and a breaker that opens on a failure rate rather than a raw count. Recommendations have their own connection pool and fall back to a cached list. Cost: during an incident, some requests that would have succeeded are rejected. I am trading a few requests to keep the service up."
Open the full page →In production
- What it costs you: Security is friction you pay on every request, forever. Checking a token costs time. Checking permissions properly usually costs a lookup. Short token lifetimes mean more refreshes; long ones mean a stolen token stays useful for longer. Encryption costs CPU and makes debugging harder because you can no longer read what is going past. And every one of these is a place where being slightly wrong is much worse than being slow.
- Saying "JWT" and then promising instant logout everywhere. Pick one.
- Checking permissions only at the gateway, so any internal service that forgets leaks data.
- Trusting internal calls because they are on a private network.
- Secrets in environment variables or config files, with no rotation story.
- Designing your own token format or password hashing.
Say this: "Short-lived signed access tokens so services verify without a lookup, plus an opaque refresh token in a session store so logout actually works within fifteen minutes. Authorization is checked at data access: every query is scoped by the caller, not just by the gateway. Secrets come from a secret manager and are rotatable without a deploy."
Open the full page →- What it costs you: Observability is expensive, and the cost surprises people. High-volume logs can cost more than the service that produced them. Every metric with a high-cardinality label — user id, request id — multiplies your storage. Tracing every request is impractical, so you sample, and sampling means the rare failure you actually wanted is the one you did not capture. And instrumenting everything adds latency and code noise.
- Saying "we would monitor it" with no named signal, threshold or action.
- Metrics labelled with user id or request id, which explodes cardinality and cost.
- No trace id passed through queue messages, so the trace stops at the async boundary.
- Alerting on CPU and disk instead of on what users experience.
- Promising an availability number with nothing measuring it.
Say this: "Request rate, error rate, p50 and p99, and saturation per endpoint, with an SLO of 99.9% under 300 ms and an error budget that governs whether we keep shipping. Alerts fire on those symptoms, not on CPU. Traces carry an id through HTTP and queue messages, sampled but always kept for errors and slow requests. Cost: logs are the expensive signal, so they are structured, sampled, and scrubbed of personal data."
Open the full page →- What it costs you: Safety slows you down. A canary means a release takes an hour instead of five minutes. Backwards-compatible migrations turn one schema change into three deploys across three releases. Feature flags accumulate until nobody knows which combinations are tested. And every one of these adds a state your system can be in, which is a state you have to reason about.
- Promising four nines and never mentioning how you deploy.
- A migration that renames or drops in the same release that stops using the column.
- Backfilling two billion rows in one statement.
- Feature flags with no owner and no removal date.
- A rollback plan that depends on a human noticing and deciding.
Say this: "Rolling deploys with connection draining, and a canary at 1% comparing error rate and p99 against the current version, with an automatic stop. Schema changes are expand-and-contract across separate releases, backfilled in batches, so code can roll back without the data being stuck. Cost: a rename becomes five steps over several days instead of one deploy."
Open the full page →- What it costs you: Backups cost storage, and the good ones cost more: frequent snapshots plus continuous log archiving is not cheap at scale. Restoring is slow. A multi-terabyte restore is measured in hours, and that time is your outage. Encrypted backups need key management that survives losing the primary system. And testing restores properly costs real engineering time on something that produces no features.
- Calling replication a backup. It replicates the mistake too.
- Backups reachable with the same credentials as the application.
- Never having run a restore, so the RTO is a guess.
- A nightly snapshot with no log archiving, then claiming an RPO of minutes.
Say this: "Nightly snapshots plus continuous log archiving, so point-in-time recovery gives an RPO of about five minutes. Backups live in a separate account the application cannot reach. We restore to a scratch environment weekly and time it, which is how I know the RTO is around 90 minutes. User-facing deletes are soft, so the common case is an update rather than a restore."
Open the full page →- What it costs you: Optimising for cost always costs you something else. Cheaper storage tiers are slower to read. Fewer machines means less headroom for a spike. Reserved capacity is cheaper and locks you in. Aggressive caching cuts database cost and adds staleness. The aim is to know what you are buying, not simply to be cheap.
- Designing at scale and never mentioning what it costs.
- Optimising a line that is 3% of the bill while ignoring the one that is 80%.
- Autoscaling with no upper bound, so an attack becomes a bill.
- Sizing regions so that the survivors cannot absorb a failure.
- Forgetting egress and cross-region transfer entirely.
Say this: "Bandwidth dominates this bill by an order of magnitude, so the CDN is a cost decision before it is a latency one. A 95% hit rate takes the origin down to a twentieth of the traffic. Raw uploads move to cold storage after 30 days. Each region is sized to absorb another one failing, which is why utilisation looks low. I would track cost per video minute served rather than the total."
Open the full page →