All modules

Foundations: interview questions

16 questions. Try answering out loud before you open the model answer.

1. Design a photo-sharing app like Instagram. Where do you start, and what do you ask me?

Seniorinterviewrequirements

What the interviewer is really testing

Whether you scope an open-ended problem before designing, ask only the questions whose answers change the architecture, and turn vague goals into numbers you can design against.

Show the model answer, follow-ups and checklist

Model answer

I would not draw anything for the first five minutes. First I want us to agree on what we are building.

Functional scope. I would propose a scope instead of asking open questions: “I will assume the core is three things: upload a photo, follow other users, and view a feed of photos from the people I follow. I will leave out stories, direct messages, search and ads unless you want one of them.” A proposal gets a faster and clearer answer than “what features do you want?”.

Non-functional requirements. I would ask the handful that change the design:

  • How many daily active users are there, and how many uploads and feed views does each make? That gives the read to write ratio.
  • What latency is acceptable for loading the feed? May a new photo take a few seconds to reach followers’ feeds?
  • Is the audience global? That decides the CDN and multi-region questions.
  • What must never be lost? An uploaded photo, presumably. A like count can be approximate.
  • What are the availability targets for viewing and for uploading? They may differ.

If you ask me to choose, I would state assumptions: 100 million daily users, feed views far outnumbering uploads, the feed loading in under 500 ms at p99, a feed that may be a few seconds stale, and photos that are durable.

Then I would write these on the board, say the plan (a quick estimate, the API, the data model, a high-level design, then deep dives on feed generation and media storage) and check: “Does that scope match what you had in mind?”

The purpose of the opening is to give the rest of the session something to be judged against. “The feed may be a few seconds stale” is what later lets me justify building feeds asynchronously.

Likely follow-ups

I answer "you decide" to every question. What do you do?
State explicit assumptions with numbers, write them down and move on within a minute. The interviewer is checking that you can make reasonable calls without hand-holding. Offer one checkpoint ("tell me if any of these look wrong") and then design against them.
Which of your questions would change the design the most?
The read to write ratio and whether the feed may be stale. A read-heavy product that tolerates a few seconds of staleness points to precomputed feeds and heavy caching. If followers must see a post instantly, the fan-out design and the storage choices change.
How do you know when you have asked enough?
When I can state the two or three core use cases, the rough scale, and the latency, consistency and availability targets for the main path. That usually takes five or six questions and about five minutes. Further questions can wait until a design decision depends on them.
What if you realise halfway through that you scoped it wrongly?
Say so plainly, state what changes and adjust the design. Requirements change in real projects too, and interviewers often change one on purpose to see how you react.

Common mistakes

  • Drawing components before agreeing what the product does.
  • Asking a long list of questions whose answers would not change anything.
  • Asking open questions such as "what features do you want?" instead of proposing a scope to confirm.
  • Collecting requirements and never referring to them again when making decisions.
  • Skipping non-functional requirements, so that later trade-offs have no basis.

A strong answer includes

  • Proposes two to four core use cases and names what is out of scope
  • Asks about scale and the read to write ratio
  • Gets latency, consistency, availability and durability targets as numbers
  • States assumptions when the interviewer declines to answer
  • Writes the requirements down and confirms them
  • Outlines the plan for the rest of the session

Revise: How to run a system design interview

2. Halfway through your design the interviewer says "I don't think that will work." How do you respond?

Seniorinterviewcommunicationtrade-offs

What the interviewer is really testing

Whether you can hold a technical position without becoming defensive or collapsing: understand the objection, test it against the requirements, and either defend the choice with reasons or change it cleanly.

Show the model answer, follow-ups and checklist

Model answer

Pushback is usually one of three things. The interviewer has seen a real flaw, or wants to hear my reasoning, or is changing the requirements to see how the design adapts. I cannot tell which until I understand the concern, so my first step is to ask, not to defend.

Suppose I chose a relational database for orders and that is what they doubt.

  1. Clarify. “Which part worries you: the write volume, the schema, or how it grows?” Then I restate it: “So the concern is that one primary cannot take the write load at peak.”
  2. Check it against the numbers. We estimated 400 writes a second at peak. A single primary handles that comfortably, so on the current requirements I would keep the choice, and say why I made it: orders need a transaction across two tables, and the data is a few terabytes.
  3. Say where they would be right. “If writes were 50 times higher, or we needed writes in several regions, I would agree and move to a store partitioned by customer ID. The data model already keys everything by customer, so that move stays open.”
  4. If they are right, change course without fuss. “You are right, I missed that analytics events share this database. I will move those to a separate append-only store. Here is what changes on the diagram.”

There are two ways to get this wrong. One is abandoning a sound decision the moment it is questioned, which suggests I had no reason for it. The other is arguing past the point where I have been heard, which suggests I would be hard to work with.

What the interviewer is watching is the process: listen, reason from the requirements, decide. Design reviews at work go the same way, so I treat pushback as a review and not as an examination.

Likely follow-ups

What if you still disagree after hearing the interviewer's reasoning?
Say so once, with the reason, and name the evidence that would change your mind, such as a load test or a different requirement. Then offer to proceed with their approach and note the trade-off. Disagreeing clearly and moving on is senior behaviour. Repeating the argument is not.
How do you tell a hint from a test?
Often you cannot, so treat both the same way: take the concern seriously and reason it through aloud. If the reasoning exposes a flaw, it was a hint. If your choice survives, you have shown why. Repeated pushback on the same point is a strong signal to reconsider.
The interviewer changes a requirement and it breaks your design. What now?
Acknowledge what no longer holds, find the smallest part of the design that has to change, and redraw only that. Say what the new requirement costs. This is often deliberate, to see whether the design was reasoned or memorised.

Common mistakes

  • Becoming defensive and repeating the original argument more firmly.
  • Dropping the decision at once without checking whether the objection is valid.
  • Answering a different concern from the one raised, because you did not ask what it was.
  • Treating the interviewer as an opponent instead of a colleague in a design review.
  • Changing the design without saying what the change costs.

A strong answer includes

  • Asks a clarifying question and restates the concern
  • Tests the objection against the stated requirements or estimates
  • Gives the original reason for the choice
  • Says under what conditions the alternative would be better
  • Changes the design cleanly when the objection is valid
  • Keeps a collaborative tone throughout

Revise: How to run a system design interview

3. You have a high-level design on the board and 15 minutes left. I am not going to tell you where to go deep. What do you pick, and why?

Staffinterviewprioritisationrisk

What the interviewer is really testing

Judgement about risk. Whether you can find the parts of a design most likely to fail or hardest to get right, prioritise them under time pressure, and explain the choice.

Show the model answer, follow-ups and checklist

Model answer

I would pick by risk, not by what I know best. I ask three questions of the design on the board.

Where does the load land? From the estimates, which component takes the peak? If one path carries 35,000 requests a second and everything else a few hundred, that path deserves the time.

Where is being wrong expensive? Anything that involves money, inventory or uniqueness. A double charge or a double booking is worse than a slow page, so that is where concurrency and failure handling need to be worked through step by step.

What is specific to this problem? Load balancers and caches look the same in every design. Matching riders to drivers, or fanning a post out to ten million followers, does not. The specific part is where a generic answer is weakest.

Then I rank the candidates and say the result aloud. For a food-delivery design it might be: “The two riskiest parts are assigning each order to exactly one courier, because a race there double-assigns, and the courier location path, because it carries most of the writes. I will spend ten minutes on the assignment race: the conditional write, what happens when the courier’s app retries, and what happens if the service crashes halfway. Then five minutes on location ingestion. I am deliberately leaving out search and ratings, which are conventional.”

Naming what I skip matters as much as what I pick. It shows that the omission is a decision and not an oversight.

With the last minute I would list what I would examine next, so that the interviewer knows I can see the remaining risks: the cost of storing location history, how the system is rolled out and migrated to, and how we would detect orders that are stuck.

Likely follow-ups

Why not go deep on the part you know best?
Depth on a low-risk component shows knowledge but not judgement. The interviewer learns more from watching me reason about the part most likely to cause an incident. If my strongest area is also a real risk in this design, I would say why it qualifies.
What if the interviewer seems uninterested in the topic you chose?
Check instead of guessing: "I can go further on retries here, or switch to the location pipeline. Which is more useful?" Interviewers usually have areas they want to cover, and a short check lets them steer without derailing me.
How deep is deep enough?
Deep enough that the mechanism is unambiguous: the data involved, the exact sequence of steps, what happens on a crash or a retry at each step, and what it costs. If someone could build it from my description without asking what happens on failure, that is enough.
What would a staff-level candidate add that a senior one would not?
The risks outside the request path: how the system is rolled out and migrated to, what it costs to run, how it is monitored and operated, and which decisions are hard to reverse. Also a clearer statement of what is deliberately not being built.

Common mistakes

  • Going deep on a familiar component that carries little risk in this design.
  • Waiting for the interviewer to choose the topic.
  • Spreading 15 minutes thinly over five topics and reaching depth on none.
  • Covering only the happy path in a deep dive, with no crashes, retries or races.
  • Not saying what is being left out.

A strong answer includes

  • Chooses by risk: where the load lands, where being wrong is costly, and what is specific to the problem
  • Uses the earlier estimates to justify the choice
  • States the choice and the time split aloud
  • Names what is deliberately skipped
  • Covers failure, retries and concurrency inside the deep dive
  • Ends with the remaining risks

Revise: How to run a system design interview

4. A ride-sharing app has 2 million drivers a day sending their location every 4 seconds. Estimate the write rate and storage. What does it mean for the design?

Mid-levelestimationcapacity

What the interviewer is really testing

Whether you can turn a product description into requests per second and bytes with stated assumptions, tell average from peak, and draw a design conclusion from the result.

Show the model answer, follow-ups and checklist

Model answer

I will state assumptions first, then work out the rate, then the storage.

Assumptions. Each driver is online for 6 hours a day. At the busiest moment 1 million drivers are online at once. One update is about 100 bytes: driver ID, latitude, longitude, timestamp, heading and speed, plus overhead.

Write rate.

  • One driver sends 6 × 3,600 ÷ 4 = 5,400 updates a day.
  • 2 million drivers send about 10.8 billion updates a day.
  • Average: 10.8 billion ÷ 86,400 is about 125,000 writes a second.
  • Peak: 1 million drivers ÷ 4 seconds is 250,000 writes a second.

Storage.

  • 10.8 billion × 100 bytes is about 1.1 TB a day.
  • Kept in full, that is about 400 TB a year, before replication.

What it means. Two things stand out.

First, this is a very high write rate against a very small live dataset. The only thing matching needs is each driver’s latest position, and 1 million drivers × 100 bytes is 100 MB. So current locations belong in an in-memory store, partitioned by region, where each update overwrites the last. A relational database taking 250,000 durable row updates a second would be the wrong tool.

Second, history is a separate problem with separate needs. It is append-only, rarely read and large, so it goes through a log such as Kafka to cheap storage. I would ask whether we need every point for ever. Keeping full resolution for the duration of a trip and for a few days, then downsampling or deleting, cuts 400 TB a year to a fraction.

The estimate has split one vague requirement, “track drivers”, into two systems with opposite characteristics, which is what I wanted from it.

Likely follow-ups

What if drivers send an update every second instead of every four?
Everything multiplies by four: about 1 million writes a second at peak and more than 4 TB a day. I would batch on the client, sending several points in one request, and ask whether the product needs one-second resolution at all, since matching does not and the rider's map can interpolate.
Does the current-location data need to be durable?
No. It is replaced every few seconds, so after a crash it rebuilds itself within one update interval. That is why an in-memory store with no synchronous disk write is acceptable here, and why I would keep it apart from trip records, which must be durable.
How do you know 100 bytes per update is reasonable?
Add up the fields: an 8-byte driver ID, two 8-byte coordinates, an 8-byte timestamp and a few bytes for heading and speed come to about 40 bytes. Allowing for encoding, indexes and per-record overhead, 100 bytes is a rounded upper figure. If a factor of two mattered to the decision, I would carry both numbers.

Common mistakes

  • Working out only the daily average and not the peak rate.
  • Treating the current location and the location history as one dataset.
  • Multiplying out precise figures and never drawing a conclusion.
  • Leaving assumptions such as hours online and record size unstated.
  • Confusing drivers per day with drivers online at the same moment.

A strong answer includes

  • States assumptions: hours online, concurrent drivers at peak and bytes per update
  • Derives average and peak writes per second
  • Derives storage per day and per year
  • Notices that the live dataset is tiny although the write rate is high
  • Separates live location from history
  • Ends with consequences for the design

Revise: Back-of-envelope estimation and latency numbers

5. Your API must serve 100,000 requests per second at peak. How many servers do you need?

Seniorestimationcapacity-planning

What the interviewer is really testing

Whether you can reason from the cost of one request to the size of a fleet, state the assumptions that dominate the answer, and include headroom and failure tolerance instead of dividing two numbers.

Show the model answer, follow-ups and checklist

Model answer

It depends on what one request costs, so I will make that assumption explicit and then calculate.

Capacity of one server. Suppose a request uses 10 ms of CPU time on average. One core then handles 100 requests a second, and a 16-core server handles 1,600 if it runs flat out. I would not run it flat out, because latency climbs steeply as utilisation approaches 100%. Planning for about 60% gives roughly 1,000 requests a second per server.

Fleet size. 100,000 ÷ 1,000 is 100 servers at peak.

Failure tolerance. If the fleet is spread over three availability zones and must survive the loss of one, the two remaining zones have to carry the peak alone. That means 50 servers per zone and 150 in total.

Checking the assumption. CPU is not always the limit. If each request also waits 50 ms on a database, the limit may be threads or connections and not cores. If responses are large, it may be the network. I would also check that the systems behind the API can take 100,000 requests a second, because adding API servers upstream of a saturated database makes things worse.

Elasticity. If the peak is three times the average, autoscaling can shrink the fleet off-peak, provided new servers start faster than the load rises. For a known spike, such as a sale opening at a fixed time, I would scale up in advance.

So my answer is about 150 servers of that size. The assumption I would measure first is CPU time per request, because halving it halves the fleet. A load test on one server, ramped until latency bends, replaces my guess with a fact.

Likely follow-ups

Why plan for 60% utilisation and not 90%?
Queueing delay grows sharply as utilisation approaches 100%, so tail latency degrades long before the CPU is full. Headroom also absorbs short bursts, uneven load balancing and the extra traffic a server takes while a neighbour is failing or being deployed. The exact target varies by team, and 50 to 70% is a common range.
A load test shows that one server manages only 300 requests a second. What do you look at?
First, whether the server is CPU-bound at all. If CPU is low, the limit is elsewhere: a thread or connection pool that is too small, lock contention, a slow dependency or garbage collection pauses. I would use tracing to see where request time goes before adding hardware.
Would you choose fewer large servers or more small ones?
More small servers lose a smaller share of capacity when one fails and scale in finer steps. Fewer large ones mean less overhead per server and fewer connections to shared resources such as the database. For a stateless API tier I lean towards many medium servers and keep an eye on the total connection count.
How does the answer change if requests mostly wait on I/O?
Then CPU time per request is small and concurrency is the limit. With asynchronous I/O one server can hold many thousands of in-flight requests, so the fleet is sized by memory per connection and by what the downstream systems can absorb, not by cores.

Common mistakes

  • Dividing peak load by a remembered "requests per server" figure without saying where it comes from.
  • Planning for 100% utilisation with no headroom.
  • Forgetting the capacity lost when a zone or a batch of servers fails.
  • Sizing for the average instead of the peak.
  • Ignoring whether the database and other dependencies can take the same load.

A strong answer includes

  • States the per-request cost as an explicit assumption
  • Derives per-server throughput from cores and CPU time per request
  • Applies a utilisation target and gives the reason
  • Adds capacity to survive the loss of a zone
  • Checks limits other than CPU and the capacity of downstream systems
  • Identifies which assumption to measure first

Revise: Back-of-envelope estimation and latency numbers

6. You want to cache user profiles for a service with 200 million registered users. How much memory do you need, and how many cache nodes?

Seniorestimationcachingcapacity-planning

What the interviewer is really testing

Whether you size from the working set and not the whole dataset, account for overhead and replicas, and check both memory and throughput before saying which one sets the size of the cluster.

Show the model answer, follow-ups and checklist

Model answer

I would size the cache from the data that is hot, then check throughput.

What to cache. Not all 200 million. Assume 50 million daily active users, and that nearly all profile reads are for users who are active that day. Caching those gives a high hit rate. The rest can miss and load from the database.

Memory. Assume a serialised profile is 1 KB. Add the key and the cache’s own per-entry bookkeeping and call it 1.5 KB. 50 million × 1.5 KB is 75 GB.

Nodes. I would not fill nodes to the brim, because of fragmentation and growth. Using about two thirds of a 32 GB node gives roughly 20 GB each, so four nodes hold 75 GB. With one replica per node for failover, that is eight.

Throughput check. If each active user causes 20 profile reads a day, that is 1 billion reads a day: about 12,000 a second on average and perhaps 36,000 at peak. One in-memory cache node handles on the order of 100,000 simple operations a second, so four nodes have plenty of room. Memory, not throughput, sets the size of this cluster.

Consequences for the design.

  • Keys are spread over the nodes with consistent hashing, so losing a node loses about a quarter of the cache and not all of it.
  • A TTL lets inactive users age out, with LRU eviction as a backstop in case my 50 million figure is low.
  • A cold cache sends everything to the database. 36,000 misses a second at peak is the load the database must survive, or the cache must be warmed before it takes traffic.

If the interviewer changes an input, say profiles are 10 KB, the method stays the same and the answer becomes about 500 GB, at which point I would ask whether to cache a smaller projection of the profile.

Likely follow-ups

What hit rate do you expect, and what if it turns out lower?
If reads concentrate on daily active users, well above 90%. If it is lower, the access pattern is flatter than I assumed: either the working set is bigger than 50 million or the TTL is too short. I would watch the hit rate and the eviction rate together. Many evictions with a low hit rate means the cache is too small for the working set.
Why not cache all 200 million profiles to be safe?
It would take about 300 GB instead of 75 GB, plus replicas, mostly to hold profiles that nobody reads. A cache earns its cost on the hot set. The database serves the long tail acceptably because those reads are rare.
One cache node dies at peak. What happens?
With a replica, the replica is promoted and little changes. Without one, about a quarter of reads miss and fall through to the database, roughly 9,000 extra queries a second, until the replacement warms up. I would make sure the database can take that, and coalesce concurrent misses for the same key into one load.
How would the sizing change for a session store?
Sessions cannot be rebuilt from a database, so losing them logs users out. I would require replication and probably persistence, size for concurrent sessions instead of daily users, and treat it as a store and not a cache, which rules out evicting entries under memory pressure.

Common mistakes

  • Sizing for the whole dataset instead of the working set.
  • Forgetting per-entry overhead, headroom and replicas.
  • Checking memory but not throughput, or the reverse.
  • Ignoring what happens to the database when the cache is cold or a node is lost.
  • Quoting a node count without stating the node size assumed.

A strong answer includes

  • Identifies the hot working set and justifies it
  • Multiplies entries by size, including overhead
  • Leaves headroom on each node and adds replicas
  • Checks the request rate against per-node throughput
  • States which constraint sets the size of the cluster
  • Covers TTL or eviction and the cold-cache case

Revise: Back-of-envelope estimation and latency numbers

7. Your app runs on one server at 90% CPU, and traffic doubles every six months. Walk me through what you do over the next two years.

Seniorscalabilitybottlenecks

What the interviewer is really testing

Whether you scale by finding and removing bottlenecks in order of cost instead of jumping to a fashionable architecture, and whether you know what each step demands of the application.

Show the model answer, follow-ups and checklist

Model answer

Before changing anything I would find out what the 90% is. If the app and the database share the machine, I would see which one is using the CPU, and look at the slowest queries. A missing index is often worth more than new hardware.

Now: buy time. Move the database to its own machine and scale both up. It needs no code changes and stops the two competing. But doubling every six months is 16 times the load in two years, so this buys months and not years.

Next: make the app tier horizontal. Put two or more app servers behind a load balancer. That requires stateless servers, so sessions move to Redis or a signed token, and uploads move to object storage. It also removes the app server as a single point of failure and allows deployments without downtime. The database is now the single point of failure, so I would add a standby with automated failover at the same time.

Then: relieve the database, reads first. Most web workloads are read-heavy. I would cache the hottest reads, then add read replicas, accepting slightly stale reads and sending a user’s reads to the primary just after they write. Static assets go to a CDN.

Then: take slow work off the request path. Email, image processing and reports go through a queue to workers, which also absorbs spikes.

Last, and only if the numbers demand it: writes. If the write rate or the data size approaches the limits of the largest machine, I would first move write-heavy features, such as event logging, to their own stores. Sharding comes after that.

At every step I would measure first, because the bottleneck moves. After adding app servers it is usually database connections, then database CPU. I would also set up monitoring and regular load tests early. At this growth rate the next limit is never far away.

Likely follow-ups

How do you know which resource is the bottleneck?
Look at saturation in each tier: CPU, memory, disk I/O wait, network, and pool limits such as threads and database connections, alongside latency percentiles. The bottleneck is the resource that saturates first as load rises. A load test that ramps traffic until latency bends shows it directly.
Why not move to microservices in order to scale?
Splitting into services helps teams and deployments scale and lets parts scale independently, but it does not remove a database bottleneck, and it adds network calls and failure modes. A stateless monolith behind a load balancer scales out just as well. I would split a service out when one part clearly has different load or ownership.
After you add replicas, users report that their changes disappear. What happened?
Their reads are reaching a replica that has not yet applied their write. Send a user's reads to the primary for a short time after they write, or track the replication position of their last write and read from a replica that has reached it. That gives read-your-writes without giving up the replicas.
When would you shard, concretely?
When one primary can no longer take the write rate or hold the data at an acceptable operational risk, for example when backups and schema changes take too long, and the cheaper options are used up. I would pick the shard key early, usually tenant or user ID, and keep queries keyed by it so that the later migration is feasible.

Common mistakes

  • Proposing sharding or microservices as the first step.
  • Adding app servers without making the app stateless.
  • Adding capacity without measuring where the bottleneck is.
  • Forgetting that the database becomes the single point of failure once the app tier is redundant.
  • Treating reads and writes as the same scaling problem.

A strong answer includes

  • Diagnoses before scaling: which process, which queries
  • Separates the database and scales up first
  • Makes the app tier stateless and puts it behind a load balancer
  • Scales reads with a cache, replicas and a CDN, and notes the staleness
  • Moves slow work to queues
  • Leaves sharding until last and says what would trigger it
  • Measures at each step and expects the bottleneck to move

Revise: Scalability

8. You added a second app server behind a load balancer, and now users are randomly logged out. What is happening, and how do you fix it?

Mid-levelscalabilitystatelesssessions

What the interviewer is really testing

Whether you recognise server-local state as the obstacle to scaling out, can explain the symptom precisely, and can compare the fixes instead of naming only one.

Show the model answer, follow-ups and checklist

Model answer

The sessions are almost certainly held in each server’s memory. A user logs in on server A, which creates a session and sets a cookie containing the session ID. The load balancer sends the next request to server B, which has never seen that ID and treats the user as logged out. It looks random because it depends on which server each request happens to reach.

I would confirm it quickly by checking where the session store is configured, and by looking in the load balancer logs to see whether the failures line up with a change of server between consecutive requests from one user.

There are three fixes.

Sticky sessions. The load balancer pins each user to one server with a cookie. It is a configuration change that works in minutes, so it is a reasonable stop-gap. But load becomes uneven, and when a server dies or is replaced during a deployment its users are logged out anyway. It also works against autoscaling.

A shared session store. Keep sessions in Redis or the database, keyed by session ID, so that any server can serve any request. The cost is a lookup on each request, which is well under a millisecond for Redis in the same data centre, and a new dependency that must itself be highly available.

Signed tokens. Put the session data in a signed token held by the client, such as a JWT. There is no server-side lookup at all. The cost is that a token is hard to revoke before it expires, so logout and permission changes need short lifetimes plus a refresh step.

I would turn on sticky sessions today if users are being hurt, then move to a shared session store, because immediate revocation matters for most products.

Then I would look for the other server-local state that will bite next: files written to local disk, in-memory caches that are assumed to be complete, and scheduled jobs that now run twice.

Likely follow-ups

What else breaks when you go from one server to two?
Anything a server kept to itself. Files uploaded to local disk are missing on the other server, scheduled jobs run once per server, in-memory rate-limit counters and caches disagree, and each WebSocket connection lives on one server only. Each needs a shared service or an explicit owner.
Redis is now a single point of failure for logins. How do you handle that?
Run it with a replica and automatic failover, and decide what the app does if it is unreachable. Treating every user as logged out is the worst outcome for a short outage, so I would prefer a brief retry and a clear error. Session data is small, so replicating it is cheap.
How do you revoke a signed token before it expires?
A signed token cannot be made invalid by itself. The usual approaches are short-lived access tokens with a refresh token that the server can revoke, or a small denylist of revoked token IDs checked on each request. The denylist brings back a lookup, so it gives away part of the benefit.

Common mistakes

  • Blaming the load balancer or cookies without identifying server-local session state.
  • Offering sticky sessions as the complete and permanent fix.
  • Proposing signed tokens without mentioning that they are hard to revoke.
  • Not looking for other local state, such as files and scheduled jobs.

A strong answer includes

  • Explains the mechanism: the session is on one server and the request reaches another
  • Says how to confirm the diagnosis
  • Compares sticky sessions, a shared store and signed tokens, with the cost of each
  • Recommends one and gives the reason
  • Looks for other server-local state

Revise: Scalability

9. The primary database is saturated on writes. What are your options before sharding, and how do you decide that it is finally time to shard?

Staffscalabilitydatabasessharding

What the interviewer is really testing

Whether you understand why writes are harder to scale than reads, know the cheaper options and their limits, and can weigh the permanent operational cost of sharding against them.

Show the model answer, follow-ups and checklist

Model answer

Replicas and caches will not help, because every replica has to apply every write as well. So I would work through the cheaper options in order, and be clear about what each one really buys.

Reduce the work per write. Every secondary index is another write, so drop the unused ones. Batch many small transactions into fewer large ones. Look for lock contention on hot rows, such as a counter that everyone increments, and restructure it. This often yields a factor of two or more at little risk.

Scale up. Faster disks and more cores. It is cheap in engineering time and has a ceiling, but the ceiling is high.

Remove writes that do not belong. Event logs, audit trails, analytics and sessions are often most of the write volume, and they need none of the relational features. Move them to an append-oriented store or a log such as Kafka. This is functional partitioning. It is far cheaper than sharding because no query has to span the split.

Buffer bursts. A queue in front smooths a peak, if the product can accept asynchronous writes. It does not raise sustained throughput. If the average rate exceeds what the primary can apply, the queue only grows.

When to shard. When, after all that, the steady write rate or the data size still exceeds what one primary can handle with acceptable operations. Backups, restores, schema changes and replica rebuilds all slow down as data grows, and that is often the real trigger before raw throughput is. I would also shard for isolation, when one tenant’s load must not affect the others.

The cost is permanent: a shard key that every query must carry, no cheap joins or transactions across shards, rebalancing and hot keys. So I would choose the key early, usually tenant or user ID, keep new queries scoped to it, and consider a database that partitions natively before building sharding into the application.

Likely follow-ups

How do you choose the shard key?
It should appear in nearly every query, spread load evenly, and keep data that is used together on the same shard. Tenant or user ID is the usual choice. A timestamp alone is a poor key, because all new writes land on the newest shard.
One tenant produces 30% of all writes. Now what?
Hashing by tenant puts that tenant on one shard, which becomes the hot one. The options are to give that tenant a dedicated shard, to sub-partition its data by a second key, or to use a directory that maps tenants to shards so that large ones can be placed deliberately.
Why not move to a distributed SQL or NoSQL database instead?
That can be the right answer, since such systems partition and rebalance for you. The costs are a migration, different performance for joins and transactions, and a new system for the team to operate. I would compare the cost of the migration with the cost of building and running application-level sharding for years.
How do you move to shards without downtime?
Typically by replicating or dual-writing changes to the new layout, backfilling existing data, verifying that both sides agree, moving reads over gradually and then moving writes. Each step should be reversible. The details depend heavily on the database, and it is a project of months, which is part of the argument for delaying it.

Common mistakes

  • Suggesting read replicas or a cache for a write bottleneck.
  • Claiming that a queue increases sustained write throughput.
  • Jumping to sharding without reducing the cost per write or moving non-relational writes out.
  • Describing sharding without its permanent costs.
  • Ignoring operational triggers such as backup and schema-change times.

A strong answer includes

  • Explains why replicas do not scale writes
  • Lists the cheaper options: tuning, scaling up, functional partitioning and buffering
  • States the limit of each option
  • Gives concrete triggers for sharding, including operational ones
  • Names the costs of sharding and prepares the shard key early
  • Considers a natively partitioned database as an alternative

Revise: Scalability

10. Your service calls five internal services, each with a 99.9% availability SLO. Product wants you to promise 99.95%. Can you?

Senioravailabilityslodependencies

What the interviewer is really testing

Whether you can do availability arithmetic for components in series and in parallel, and whether you know the design moves that break the dependence instead of only reporting that the number is impossible.

Show the model answer, follow-ups and checklist

Model answer

Not as the design stands. If every request needs all five services, their availabilities multiply: 0.999 to the fifth power is about 0.995. The best I can offer is 99.5%, before counting my own failures. That allows about 44 hours of downtime a year, against the 4.4 hours that 99.95% permits. I am short by a factor of ten.

So the real question is how to stop the dependencies being in series.

Make dependencies soft. For each one, ask whether a request can be served without it. If recommendations are down, show the page without them. If the profile service is down, use a cached copy. A dependency with a fallback drops out of the multiplication, and often only one or two of the five are truly required.

Cache what the hard dependencies return. If pricing can be served from a cache that is a few minutes old, a short pricing outage is invisible.

Go asynchronous. If the response does not need a call’s result, as with sending a notification, put the call on a queue. An outage then delays work instead of failing requests.

Add redundancy where a dependency stays hard. Two independent instances at 99.9% give 99.9999% on paper. Failures are correlated in practice, so I would treat that as an upper bound.

Protect myself. Timeouts, limited retries and circuit breakers stop a slow dependency from tying up my threads and taking me down with it.

Then I would recalculate. With even one hard dependency at 99.9% I still cannot promise 99.95%, so either that service’s objective must rise or it needs a fallback too. That is the choice I would take to product: which features may degrade, and which dependency deserves investment.

One last check is whether the five fail independently. If they share a database or a deployment pipeline, their outages overlap, which flatters the arithmetic slightly but means one fault takes out everything at once.

Likely follow-ups

Two of the five turn out to be hard dependencies. What is the best you can offer?
0.999 squared is about 99.8%, which is roughly 17.5 hours a year and still short of 99.95%. To reach the target those two services would each need about 99.975%, before counting my own failures, or I need a degraded mode that covers their outages.
How do retries change the calculation?
Retries help with brief, independent failures. If a call fails at random 0.1% of the time, one retry cuts that to about one in a million. They do nothing during a real outage and they multiply load on a struggling service, so they need a limit, backoff with jitter, and operations that are safe to repeat.
How do you measure whether you met 99.95%?
As the ratio of good requests to all requests, measured as close to the user as possible, for example at the load balancer, over a rolling window such as 30 days. I would define "good" precisely: a response without a server error inside the latency threshold. A degraded response counts as good only if product agrees that it is acceptable.
Is it reasonable to promise more than your dependencies do?
Only if the design stops a dependency failure from becoming my failure, through fallbacks, caching or redundancy. Otherwise I am promising something the arithmetic rules out. This is why the services at the bottom of a stack usually need stricter objectives than the ones built on them.

Common mistakes

  • Saying that 99.9% dependencies give a 99.9% service.
  • Stopping at "it is impossible" without proposing changes to the design.
  • Assuming redundancy delivers the theoretical figure despite correlated failures.
  • Adding unlimited retries, which amplify an outage.
  • Forgetting the service's own failures and bad deployments.

A strong answer includes

  • Multiplies availabilities in series and gets about 99.5%
  • Converts the percentages into hours per year
  • Separates hard dependencies from soft ones
  • Proposes fallbacks, caching and asynchronous calls
  • Uses the parallel formula and notes correlated failures
  • Mentions timeouts and circuit breakers
  • Frames the remaining gap as a decision for product

Revise: Availability and reliability

11. You run active-passive across two regions, and the primary region goes dark. Walk me through the failover and what can go wrong.

Senioravailabilityfailoverdisaster-recovery

What the interviewer is really testing

Whether you understand failover as a sequence with a cost at each step, including detection, data loss, split brain and capacity, and whether you have thought about the way back.

Show the model answer, follow-ups and checklist

Model answer

I will go through it as a sequence, because the downtime is the sum of the steps.

Detect. Health checks from outside the failed region must agree that it is down, and not merely slow or unreachable from one vantage point. I would require several consecutive failures from more than one location. That takes tens of seconds, and it is a trade: a shorter threshold fails over on blips.

Decide. Automatically, or with a person confirming? A false failover of a whole region is expensive, so many teams want a human in the loop, but that adds minutes. The recovery time objective decides it. A 99.99% target cannot wait for someone to wake up.

Fence. Make sure the old primary cannot accept writes if it is in fact alive but cut off. Otherwise both regions take writes and the data diverges.

Promote. The standby database becomes the primary. With asynchronous replication, whatever had not arrived is lost. A few seconds of lag means a few seconds of acknowledged writes are gone, and I need to know which, to put things right with customers.

Redirect. Move traffic with DNS or a global load balancer. DNS depends on TTLs, and some clients ignore them, so a tail of traffic keeps heading for the dead region.

What goes wrong. The passive region has not been serving traffic. Its caches are cold, its server groups are small, and it may lack the quota to grow. It receives full production load at once and can fall over. Configuration and secrets may have drifted. A dependency that existed only in the primary region is discovered. And the runbook is out of date, because nobody has run it.

That last point is the main lesson. An untested failover is a hope, so I would rehearse it on a schedule and keep the passive region warm with a small share of real traffic.

The way back. The old region returns holding stale data, plus writes that never replicated. It must rejoin as a replica and resynchronise before any failback.

Likely follow-ups

How would you get the recovery point to zero?
Replicate synchronously, so that a write is acknowledged only after the second region has it. That adds a cross-region round trip to every write, and writes stall if the standby is unreachable unless you fall back to asynchronous mode, which reopens the gap. Many teams accept a few seconds of possible loss instead.
Why not run active-active and avoid failover altogether?
For stateless services, do. For data, active-active across regions means that each region owns distinct data, or that concurrent writes are reconciled, or that every write goes through cross-region consensus and pays the latency. It removes the promotion step and replaces it with conflict or latency costs.
The DNS TTL is 60 seconds. How long until all users have moved?
Most within a minute or two, but not all. Some resolvers and clients cache beyond the TTL, and long-lived connections stay attached to the old address until they break. An anycast address or a global load balancer in front moves traffic faster, because clients do not need to resolve again.
How do you test this without causing an outage?
Start with exercises in a staging environment, then planned failovers in production at quiet times with the team watching, and work up to doing it routinely. Sending a small, steady share of live traffic to the standby region continuously verifies its capacity and configuration.

Common mistakes

  • Describing failover as a single instantaneous switch.
  • Ignoring the data lost to asynchronous replication lag.
  • Not mentioning split brain or fencing.
  • Assuming the standby region can absorb full load at once.
  • Forgetting failback and resynchronising the old primary.
  • Never testing the procedure.

A strong answer includes

  • Breaks the failover into detect, decide, fence, promote and redirect
  • Relates the steps to recovery time and recovery point
  • Explains split brain and how fencing prevents it
  • Covers replication lag and lost writes
  • Covers cold caches, capacity and configuration drift in the standby
  • Says how the procedure is tested
  • Describes failback

Revise: Availability and reliability

12. Your service has a 99.9% monthly SLO and used its whole error budget in the first week. Product wants to ship a big feature next week. What do you do?

Senioravailabilitysloerror-budget

What the interviewer is really testing

Whether you understand an error budget as a decision tool shared by engineering and product, and can handle the conflict with judgement instead of either blocking everything or ignoring the objective.

Show the model answer, follow-ups and checklist

Model answer

First I would get the facts straight. A 99.9% objective over 30 days allows about 43 minutes of total outage, or 0.1% of requests. I would find out what used it: one incident or a steady trickle, our own change or a dependency, and whether the indicator measured real user pain or a monitoring artefact.

Then the policy. The point of an error budget is that this conversation was settled in advance. While budget remains, we ship at will. When it is spent, reliability work takes priority over launches until the service is back within its objective. If we have that policy, I would follow it, because an objective that is waived whenever it is inconvenient is not an objective.

That does not mean freezing everything. I would sort changes by risk.

  • Fixes for the cause of the incident go out first, together with anything that lowers risk, such as better rollback or alerting.
  • Low-risk changes behind feature flags, released to a small share of traffic first, can usually continue.
  • The big feature is the kind of change the policy exists for. I would propose shipping it switched off, or to a small percentage of users, so that work continues while exposure stays limited, and launching fully when the budget recovers.

Then I would talk to product with numbers and not a veto: this is what users experienced, this is the cause, this is what we are fixing, and these are the launch options with the risk of each.

If the date truly cannot move, for instance because of a contractual commitment, that is a business decision. It should be made explicitly, at the right level, with the risk written down, and it should be a recorded exception and not a habit.

Finally I would ask whether the objective is right. If we burn the budget every month and users do not complain, the target may be stricter than the product needs. If they do complain, the launch is not the priority anyway.

Likely follow-ups

What is the difference between the SLO and the SLA here?
The SLO is our internal target, 99.9%. The SLA is what we have promised customers in a contract, with penalties, and is normally looser, perhaps 99.5%. Missing the SLO triggers a policy response. Missing the SLA costs money and trust, and the gap between the two is the safety margin.
How could you have noticed sooner that the budget was burning?
Alert on burn rate: how fast the budget is being used compared with the rate that would exactly exhaust it over the window. A fast burn pages someone at once, and a slow burn raises a ticket. That is more useful than alerting on raw error counts, because it is tied to the objective.
The outage was caused by a cloud provider and not by your code. Does it still count?
Yes. Users were affected whatever the cause, and the budget measures their experience. What changes is the response: the work is to reduce exposure to that provider failure, with another zone or a fallback, and not to slow down our own releases.
Who decides to override the policy?
Someone with authority over both the product and the reliability risk, as the written policy specifies, typically a director or above. What matters is that the decision is explicit and recorded, and is not made by the team under deadline pressure.

Common mistakes

  • Treating the error budget as an engineering veto, with no conversation with product.
  • Ignoring the budget because the launch matters more, without an explicit decision.
  • Freezing every change, including the fixes that would restore reliability.
  • Not investigating what used up the budget.
  • Confusing the SLO with the SLA.

A strong answer includes

  • Converts the SLO into a concrete budget
  • Investigates the cause and pattern of the burn
  • Applies the agreed policy and explains why consistency matters
  • Separates changes by risk and puts fixes first
  • Offers product a launch with limited exposure
  • Escalates real exceptions as explicit, recorded decisions
  • Asks whether the SLO itself is set correctly

Revise: Availability and reliability

13. A user updates their profile picture, refreshes, and still sees the old one. There is nothing in the error logs. What is going on, and how do you fix it?

Mid-levelconsistencycachingreplication

What the interviewer is really testing

Whether you can diagnose staleness across every layer where an old copy can live, and fix it with the narrowest guarantee that works instead of making everything strongly consistent.

Show the model answer, follow-ups and checklist

Model answer

No errors and a change that “did not happen” usually means that the write succeeded and the read came from a stale copy. I would list every place an old copy could be, working inwards from the user.

  1. The browser or app cache. The image URL did not change, so the client shows what it already has.
  2. The CDN. The old image stays cached at the edge until its TTL expires.
  3. An application cache. The profile record in Redis still points to the old picture, because the write path did not invalidate it.
  4. A read replica. The profile was read from a replica that had not yet applied the update.

To find out which, I would fetch the profile from the primary, from a replica and from the cache, and request the image with and without the CDN. The first layer that disagrees with the primary is the culprit. Timing is a clue as well: replica lag corrects itself in seconds, and a TTL takes minutes.

The fix depends on the layer.

  • Images. Give every upload a new URL, with a version or a content hash in the path. A new URL bypasses both the browser cache and the CDN, and the old one can be cached for ever. This is better than purging.
  • Application cache. Delete or update the key when the profile is written.
  • Replica lag. Give this user read-your-writes. For a few seconds after a write, read their own profile from the primary, or record the replication position of the write and read from a replica that has caught up.

I would not move all reads to the primary or make replication synchronous. Other users seeing the old picture for a second is harmless. Only the author needs to see the change immediately, and a session guarantee provides that at almost no cost.

Likely follow-ups

How do you implement "read from the primary after a write" when there are many app servers?
The marker has to travel with the user and not live on one server. Set a short-lived cookie, or a field in the shared session store, that records when the user last wrote, and have every server send that user's reads to the primary until a few seconds later. A more exact version stores the log position of the write and compares it with each replica's position.
The user changes the picture on their phone and then looks on their laptop. Does your fix still work?
A cookie does not, because it belongs to one device. For read-your-writes across devices the marker must be stored on the server against the user, for example the time or log position of their last write, in a shared store that every request checks.
Why is deleting the cache key on write not always enough?
Because of a race. A concurrent reader can miss the cache, read the old value from a lagging replica, and write it back into the cache just after the delete. The stale value then stays until its TTL. Mitigations are to refill from the primary after a recent write, to keep the TTL short, or to delete a second time after a delay.
When would you choose synchronous replication instead?
When the concern is not what one user sees but what the system must not lose or contradict, such as a payment record that has to survive a failover. It costs write latency and availability, so I would apply it to those tables or transactions and not to profile pictures.

Common mistakes

  • Assuming replica lag at once, without considering the browser, the CDN and the application cache.
  • Fixing it by sending all reads to the primary.
  • Purging the CDN on every change instead of versioning URLs.
  • Forgetting that a cache can be refilled with stale data after it is invalidated.
  • Not explaining how to find which layer is stale.

A strong answer includes

  • Recognises a successful write followed by a stale read
  • Lists the layers that can hold a stale copy
  • Describes how to isolate the layer
  • Uses versioned URLs for images
  • Invalidates the application cache on write
  • Applies read-your-writes for replica lag and names the mechanism
  • Avoids a global strong-consistency fix

Revise: Consistency models

14. In a ticket-booking system, which operations need strong consistency and which can be eventually consistent? Justify each.

Seniorconsistencytransactionstrade-offs

What the interviewer is really testing

Whether you assign consistency per operation according to the cost of being wrong, and can name the mechanism that enforces each choice, instead of labelling the whole system.

Show the model answer, follow-ups and checklist

Model answer

I would go through the operations one at a time and ask what the worst outcome of a stale read or a conflicting write is.

Browsing and searching events. Eventual. If a new event takes a minute to appear, or a listing says “few seats left” just after selling out, nobody is harmed. This is most of the traffic, so it is served from caches, a search index and read replicas.

The seat map. Eventual, with a short bound. It is a hint. Showing a seat as free two seconds after it was taken is acceptable, provided the next step catches it. I would refresh it every few seconds or push updates.

Reserving a seat. Strong. Two buyers must never both hold seat 14C. This is the invariant, so it goes to one authoritative store with a conditional write: mark the seat as held by this user only if it is currently free, as a transaction or a compare-and-set. Of two concurrent requests, one succeeds and the other gets a clear “seat taken”. The hold carries an expiry, so that abandoned checkouts release their seats.

Payment and confirmation. Strong, and idempotent. The booking record and the seat’s change from held to sold commit together. A retried payment request must not charge twice, so it carries an idempotency key.

The user’s own bookings. Read-your-writes. After paying, the user must see the ticket straight away, so that read goes to the primary.

Confirmation email, analytics, recommendations. Eventual and asynchronous, through a queue.

The pattern is that strong consistency is confined to a narrow, low-volume path: one row per seat and one transaction per booking. Everything with high volume is served from copies. The system stays fast for the great majority of requests, which are browsing, and double-booking is impossible instead of merely unlikely.

During a network partition, the reservation path would refuse requests sooner than risk a double sale, while browsing stays up.

Likely follow-ups

A popular event goes on sale and 500,000 people try to buy 50,000 seats at once. Does your strong path cope?
Not unprotected. I would put a virtual waiting room in front that admits users at a rate the reservation path can handle, so that the strongly consistent store sees a controlled load. Contention is per seat, so partitioning by event and section spreads it, and general-admission tickets can use a counter instead of a row per seat.
Why not use eventual consistency for reservations and fix conflicts afterwards?
Because the fix is telling a customer who has paid that they have no seat. Airlines oversell on purpose and compensate, so it is a business choice, but for assigned seating most products treat double-booking as unacceptable. If the business accepted it, an always-available design with compensation would be legitimate.
How does a hold expire safely?
Store an expiry time with the hold and treat an expired hold as free inside the conditional write, so that correctness does not depend on a cleanup job running on time. A background job can tidy up later. Payment confirmation must check, in the same transaction that marks the seat sold, that the hold is still valid and belongs to this user.
Is a conditional write on one database really linearizable?
On a single primary, a transaction or compare-and-set gives the property that matters here: concurrent attempts are ordered and only one finds the seat free. If the store fails over to a replica, an acknowledged hold must not be lost, which needs synchronous replication or a consensus-based store for this data.

Common mistakes

  • Declaring the whole system strongly consistent or eventually consistent.
  • Trying to keep the seat map perfectly accurate instead of validating at reservation time.
  • Enforcing "the seat is free" with a read followed by a separate write.
  • Forgetting idempotency when a payment is retried.
  • Ignoring holds that are never completed.

A strong answer includes

  • Classifies each operation separately and gives a reason
  • Identifies the invariant: one seat, one buyer
  • Enforces it with a conditional write or transaction on an authoritative store
  • Gives holds an expiry
  • Makes payment idempotent
  • Gives the user read-your-writes on their own bookings
  • Keeps high-volume reads on eventually consistent copies

Revise: Consistency models

15. Your design replicates data across two regions. Is it CP or AP, and what exactly happens to user requests when the link between the regions fails?

Seniorcapmulti-regionpartitions

What the interviewer is really testing

Whether you can apply CAP to a concrete design by describing behaviour during a partition for each operation, including what happens after it heals, instead of reciting the theorem or attaching one label.

Show the model answer, follow-ups and checklist

Model answer

I would answer per kind of data, because one label would be wrong for part of the system. Take a shop with a catalogue, baskets, and orders that decrement stock.

First, what a partition means here. Both regions are up and serving their local users, but they cannot replicate to each other. Each must decide alone.

Baskets and catalogue: AP. Both regions keep serving reads and accepting basket changes. A user whose requests move between regions may briefly see an older basket. When the link returns, baskets are merged per user. I would take the union of the items, so that nothing a user added is lost, and accept that a removed item can come back. The catalogue has a single writer, so one region simply serves a stale copy until replication resumes.

Orders and stock: CP. A stock decrement must not be accepted in both regions independently, or we oversell. This data lives in a store that needs a majority to commit. Two regions alone have a problem: neither side is a majority. So I need a third location, even a small witness, to break the tie. The side that can reach the witness keeps taking orders. On the other side users can still browse and fill a basket, and at checkout they get an honest “try again shortly”.

After healing. The CP data needs no repair, because nothing conflicting was ever acknowledged. The AP data runs its merge.

The rest of the time. Each order commit pays a round trip to another location, tens of milliseconds, which is acceptable at checkout. Baskets replicate asynchronously and respond locally.

So: AP for browsing and baskets, CP for orders, and the visible effect of a partition is that one region temporarily cannot check out.

If the business would prefer to take every order and apologise for the rare oversell, I would make stock AP as well. That is a product decision, and I would raise it and not assume it.

Likely follow-ups

Why can two regions alone not give you a CP system that stays up when one is cut off?
Because a majority of two is two. When the link fails, neither region can tell whether the other is down or only unreachable, and if either may carry on alone then both may, which is split brain. A third vote in another location lets exactly one side form a majority.
How does the minority region know that it should stop?
It cannot reach a majority, so it cannot commit writes or renew its leadership, and it steps down. It must refuse consistent reads too, because it cannot know whether newer data exists on the other side. It can still serve reads that are explicitly allowed to be stale, if the product permits them.
Under an AP design, what if both regions accepted orders for the same last item during the partition?
Then you need a reconciliation rule that was decided in advance. Give each order a unique ID so that nothing is double-counted when the regions merge, and settle the stock conflict with a business process such as a backorder or a refund. Last write wins would silently drop an order, which is unacceptable.
A node is slow, not partitioned. Does CAP apply?
In practice, yes. The system sees only timeouts and cannot tell slow from unreachable. It must choose between waiting, which hurts availability and latency, and carrying on without that node, which risks consistency. That is why a timeout setting is in effect a CAP decision.

Common mistakes

  • Giving one label for the whole system.
  • Saying "we choose CA", or that partitions will not happen.
  • Describing a two-region CP design with no tiebreaker.
  • Not saying what users on the minority side experience.
  • Forgetting reconciliation after an AP partition heals.
  • Ignoring the latency cost outside partitions.

A strong answer includes

  • Defines the partition concretely: both sides are up and replication is cut
  • Classifies data per operation and gives a reason
  • Describes what users see on each side
  • Notes that two sites need a third vote to form a majority
  • Explains what happens after healing under each choice
  • Mentions the latency cost in normal operation
  • Raises the business option of accepting conflicts

Revise: CAP and PACELC

16. Partitions are rare. So why does the choice of consistency level still matter every day, and where in a global product would you accept stale reads?

Staffpacelclatencymulti-region

What the interviewer is really testing

Whether you understand the latency cost of consistency in normal operation, the "else" half of PACELC, can quantify it for a multi-region deployment, and can place each kind of data deliberately.

Show the model answer, follow-ups and checklist

Model answer

Because consistency costs latency on every request, and not only during failures. To guarantee that a read reflects the latest write, something has to wait. The write waits for a quorum of replicas, or the read checks with the leader or a quorum. With replicas in one data centre, the wait is under a millisecond and nobody notices. With replicas on three continents, a majority commit costs at least one round trip between regions, tens to a couple of hundred milliseconds, on every write. That is the “else” branch of PACELC, and you pay it all day.

For a global product I would place each kind of data deliberately.

Accept stale reads and replicate asynchronously: feeds, the catalogue, profiles as other people see them, counters and search. These are read from the local region in a few milliseconds. Staleness is bounded by replication lag, normally well under a second, and the author gets read-your-writes.

Pay for consistency: balances, inventory, uniqueness, and permission changes such as revoking access. These go through a consensus-backed store.

Then I would reduce what the consistent path costs.

  • Give each record a home region. A user’s data has its leader near that user, so their writes commit against a nearby quorum, and only interactions that cross regions pay the long round trip.
  • Keep the quorum close. Three replicas on one continent give a fast majority. A distant replica is there for disaster recovery and is not needed to commit.
  • Use bounded-staleness reads. Where a read may be a few seconds old, a local replica can serve it, even in a strongly consistent store.

This is as much a product and cost decision as a technical one, so I would put the latency of each option in front of product: “Consistent global writes add about 100 ms to this action. Is that acceptable at checkout? Is it acceptable while typing in a shared document?” The answers usually differ, and the design follows from them.

Likely follow-ups

How does Spanner serve consistent reads without always contacting a quorum?
It assigns commit timestamps using tightly synchronised clocks with a known uncertainty bound, and waits out that uncertainty before acknowledging a commit. A replica can then serve a read at a given timestamp once it knows it holds all the data up to that timestamp. Writes still pay for a majority, plus the short commit wait.
A user in Sydney edits data whose leader is in Frankfurt. What do they experience?
The write travels to the Frankfurt leader and its quorum, so it takes a few hundred milliseconds instead of a few. The options are to accept that for a rare case, to move the record's home if the user has relocated, or to apply the edit optimistically in the client and confirm it in the background.
How would you classify Cassandra at LOCAL_QUORUM in PACELC terms?
It favours latency in normal operation, because it waits only for replicas in the local data centre and replicates to other regions asynchronously. Within a region, reads overlap writes, but a client that switches region can read stale data. During a partition between regions each side keeps working, so across regions it behaves as PA/EL.
Which metric tells you that your staleness assumption still holds?
Replication lag per replica and per region, as a distribution and not only an average, with an alert when the tail exceeds what the product was promised. If a feature assumes one second of staleness and lag reaches a minute during a backlog, the feature's behaviour has changed although nothing has failed.

Common mistakes

  • Saying that consistency only matters during failures.
  • Proposing synchronous global replication for all data without stating the latency.
  • Treating "eventual" as unbounded instead of relating it to replication lag.
  • Not separating the author's view from other users' views.
  • Ignoring data placement as a way to cut the cost of consistent writes.

A strong answer includes

  • Explains that consistent operations wait for replicas even on a healthy network
  • Puts the cross-region cost in milliseconds
  • Sorts data into stale-tolerant and consistency-critical, with reasons
  • Uses asynchronous replication plus session guarantees for the first group
  • Cuts the cost of the second group with data homing or nearby quorums
  • Presents the trade-off to product as a decision with numbers

Revise: CAP and PACELC