Interview: every page view is a read-write query on the leader
Followers already apply the stream and sit idle. Send reads that can lag to them, and send a user back to the leader when they just wrote.
More on Ticket interviews
- Database Interviews in the AI Era: The Ticket Format
- Interview: the same job runs twice
- Deadlock Interview Question: Find and Fix It in SQL
- Slow Query Interview: One Keyword Made It 40× Slower
- Interview: rate limit is 2/min, 30 requests get through
- Interview: “just add an index” slowed ingestion
- Interview: “I changed my name, refresh shows the old one”
- Interview: importing 10M rows takes six hours
- Interview: everything got slow and the disk keeps growing
- Lost Update Interview: Wallet Balance Wrong Under Load
- Interview: API p99 jumps 10× every night at 2 am
- Interview: profile lookups got 40× slower, writes are fine
- Interview: inserts stall, and only one page is hot
- Interview: the write succeeded, the next read shows an empty cart
- Interview: inventory stayed locked after the coordinator restarted
- Interview: for four minutes, both regions took orders
- Interview: shoes show a 0% discount, then the report crashes
- Interview: March gained $50 after the deploy, and the months don’t add up
- Interview: the new branch’s dashboard takes 38 seconds
- Interview: the index is right there, make Postgres use it
- Interview: warehouse and checkout overwrite the same order
- Interview: the bestsellers report now takes nine minutes
- Interview: an analyst query locked checkout
- Interview: the member is active and the email went out twice
- Interview: one shard is at 96% CPU and the other is idle
- Interview: the menu is slow, and the proposal is event sourcing
- Interview: four dashboards disagree about whether the database is slow
- Interview: checkout got slow the hour the warehouse job started
- Interview: the query is fast in staging and slow in production
- Interview: login looks up an email and reads the whole customers table
- Interview: the proposal splits one database into three shards
- Interview: the order page joins four tables on every view
- Interview: Sarah and John both debit version 1
- Interview: the CTO read a blog post and wants to move Postgres to MySQL
- Interview: one table takes 50,000 writes a second, another feeds dashboards. Which engine for each?
- Interview: EU users wait on the ocean for every write, can both regions take writes?
- Interview: users search cars by color, but the table is sharded by car id
- Interview: we added a fourth node and most of the data moved
- Interview: two people book the same room at noon, both get a confirmation
- Interview: everything is on the strongest consistency and far requests crawl
- Interview: the order is saved, the message to search and email never left
- Interview: rename a column on a 600 GB table while 30 servers keep serving traffic
- Interview: orders go to 16 shards in 2 regions, what should the order id be?
- Interview: one celebrity posts, and every timeline in the app slows down
- Interview: 5,000 customers share one database, and one of them slows down everyone
Keep learning
Every page view is a read-write query on the leader
Three followers sit idle while the leader serves every read. The question is which reads may be a little behind. replication stream The app sends every read to the leader
Leader CPU is reads. Followers are at 4%.
The leader takes writes and also serves every catalog and order GET. Three followers receive the replication stream and sit idle. Catalog may be seconds old. A user’s own saved address may not. leader CPU follower CPU on leader leader CPU (1 node) follower CPU (3 nodes) normal follower lag Restated: the machines that can answer reads are not asked. Routing, not capacity.
Four checks, in order
Which statements are read-only? split leader stats into reads and writes Catalog and order history are plain SELECTs. They can use a slightly old copy. Is the follower actually applying the stream? compare leader and follower log positions Yes, a few hundred ms behind. Healthy, just unused. Which read must see the user’s own write? find the GET after POST /address That one. A random follower may not have the write yet. What happens when the leader dies? ask who may become leader Only a follower holding every promised transaction. Idle is not the same as safe. POST /address COMMIT new address stream sends the change still applying… ~300 ms behind GET /address → follower returns OLD address stale own write Why the GET right after a save cannot go to just any follower.
You route by how stale the screen may be
Any write GET /catalog (lag < 5 s) GET right after own write Keeps all writes on the single leader. Falls back to the leader when lag passes 5 s.
Say these without the model
What is the leader doing that a follower must not do? Accepts writes. Orders the log. Source of truth. Receives the log. Replays it. Serves reads from a copy. Accept writes. Only the leader does that. It also sets the log order and is the source of truth. Two nodes taking writes is split brain (two diverging truths). one writer follower replays two writers is split brain What does the replication stream guarantee, and what does it delay? the stream Commit returns at once. Followers may lag. Commit waits for a follower ack. Slower writes. It guarantees order, not timing. Async: the commit returns before any follower has it. Sync: writes wait for a follower ack, shrinking the gap. ordered apply async means lag sync means commit latency A user saves an address and the next page shows the old one. What did the route do? User just wrote? Yes → leader No → any follower if lag < 5 s It sent the read to a follower that lacked the write. Fix the route: send that user’s next read to the leader. Or to a follower already past the write’s log position. The rule is per session, not for all reads. lagging follower route the next read per session, not global Why is “promote the least-loaded follower” an incomplete failover plan? Least loaded May be furthest behind. Promised commits vanish. Most caught up Has every promised commit. Old leader fenced off. The idle one may be furthest behind, so commits get lost. Promote the node with the full log, or wait for it. Fence the old leader (block it from writing) so it can’t diverge. most caught-up, not least loaded lost transactions fence the old leader
Catalog can lag. The address page cannot.
How do you take reads off the leader? Followers for catalog. Leader, briefly, after a user’s own write. Idle machines take most reads. The own-write screen never races the stream. Leader spared Stale own-write Failover story All reads to a random follower Leader CPU falls, but the address bug becomes permanent. No rule for too-far-behind followers. Make replication synchronous and then read followers Own writes get safer, but every commit waits. A routing rule would be cheaper.
Have one ready
Draw one leader and two followers. Where does a write go, and where does a read go?
Did you show these?
Routed next read for read-your-writes Fell back to leader past a lag ceiling Promoted the most caught-up follower
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.