Interview: for four minutes, both regions took orders
A GC pause tripped a one-heartbeat failover. Failure detection, majority election, Raft terms, and fencing stale leaders at storage.
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: 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: every page view is a read-write query on the leader
- 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
Overview
GC pause, no heartbeat for 2s The leader is alive. It is not answering. timeout is 5s, so no election A follower does not promote itself on one gap. pause ends, heartbeats resume still a follower One leader the whole time. A real crash would take up to 5s to notice. Same pause. timeout is 1s → takes leadership The script promotes the follower because it missed one heartbeat. It never asked a majority. accepts order 501 Both sides commit. The two order logs disagree. pause ends, still accepts writes Nothing in the protocol tells the old leader to stop. majority votes it leader, term 8 A new term exists only because a majority agreed. Term 7 is over. write carrying term 7 storage rejects term 7 The term is a fencing token. The old leader cannot commit on top of term 8. sees term 8 and steps down When the pause ends it learns it lost and stops accepting orders. Leader process pauses for 2 seconds failure detector dead after 1 missed beat dead after 5s of silence no term check storage checks the term us-east (current leader) eu-west (follower) Play step 1 Next step Show all = beats.length ? ( Split brain: two nodes accept orders because “I stopped hearing you” was treated as “I am the leader.” A higher term fences the old leader. Detection can be aggressive because a stale writer is rejected. A looser timeout rides out the pause. The cost is on the other side: a leader that is actually dead is dead for up to 5 seconds, and every order waits.
For four minutes, both regions took orders
A 2-second pause silenced the leader, so the follower crowned itself. Storage took writes from both. phi accrual split brain Raft term Majority election plus a term checked at storage
Duplicate order ids from us-east and eu-west
02:14–02:18: both regions accepted new orders. 1,200 ids exist in both, with different customers. us-east had a 2 s GC pause. Nothing rebooted. 4 min GC pause machines down GC pause 2 s leader alive, silent 1 missed heartbeat timeout 1 s Follower self-promotes no vote Leader wakes still thinks it leads Two writers storage accepts both Restated: a quiet leader was replaced, and nothing stopped it when it woke.
What is allowed to declare itself leader?
One missed 1-second heartbeat is enough. A third node, the witness, is healthy and is never asked. The leader’s pause was 2 seconds. Storage will take a write from whoever believes they are leader. There is no token to compare. Timeout 1 s Shorter than a normal GC pause. One voter The healthy witness is never asked. No term on writes Storage can’t spot a stale leader.
Quiet is not the same as dead
Did the leader crash? the ticket No. A 2 s GC pause. The process was alive and resumed. What promoted the follower? One missed heartbeat. The pause outlasted the 1 s timeout. Did anyone else have to agree? promoteToLeader has no votes No. One node’s opinion made a second leader. An election with one voter. Why didn’t the original leader stop when it woke up? Writes carry no term (election number). Storage can’t tell old leader from new.
A majority elects, and storage enforces the term
A majority vote, so one follower can’t crown itself. Storage rejects writes with an old term. Regression test replays the same 2 s pause. Forbids the lazy fix: just a longer timeout.
No AI from here
What is wrong with “dead after one missed heartbeat”? Short timeout Fast failover. GC pauses look like crashes: false leaders. Long timeout No false alarms. A real crash goes unnoticed for seconds. A live but slow node gets declared dead, creating a second leader. GC, slow disks and network blips all delay heartbeats. Longer timeouts avoid that, but a real crash stalls orders longer. One fixed number can’t give both fast detection and no false alarms. false positive vs detection time GC looks like a crash one knob cannot do both What does a phi-accrual detector change? Suspicion grows smoothly from heartbeat history, not one hard deadline. φ rises as the current silence becomes unusual for this node. It is still only an opinion. Storage must still fence stale writers. threshold is the knob detection is not fencing Why does Raft refuse to elect a leader with one node’s vote? follower becomes candidate term + 1 term 8 Ask for votes Majority (2 of 3) Leader, term 8 Two sides can’t both hold a majority, so only one can lead. Commits also need a majority, so a paused leader can’t commit. On waking it sees a higher term and steps down. majority for election and for commit two partitions cannot both have a majority higher term wins We already have a leader flag in the app. Why must storage check the term? old leader (term 7) new leader (term 8) write, term 8 wakes, write term 7 flag still says leader reject: 7 < 8 returns term 8 step down Storage checks the term on every write and rejects older ones. The rejection carries the new term, so the old leader steps down. the flag is stale on wake the check is at storage the rejection carries the newer term The 1,200 duplicate orders are already committed on both sides. Now what? Fence first so no more duplicates appear, then repair by hand. Match by business key, not the colliding id: same id, two orders. Refund or remake the losing order. Never delete rows to make tables match. stop the bleeding with the fence business identity, not the colliding id committed history is repaired by hand
GC pauses of about 2 seconds happen a few times a day
What do you change first? Majority election plus a term checked on every write A pause may still trigger an election, but late writes fail. Fixes the actual bug. Single leader Failover speed Duplicate orders Only raise the timeout from 1s to 10s An 11 s pause does it again. Real crashes now cost 10 s of failed orders. Phi accrual with a high threshold, no fencing Fewer false elections. But if it’s wrong once, storage takes both writers. Let both regions write, and dedupe nightly A nightly job can’t tell which charge is real. This is how the ticket happened.
Have one ready
Tell me about a failover that fired when nothing was down. Both sides said 200. Majority vote + term check at storage. Pause-the-leader test.
Did you show these?
GC pause ≠ crash Found the one-beat promotion False alarms vs detection time Majority to elect and to commit Term check at storage, not a flag Fence first, then repair 1,200 orders
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.