The whole course ▾
System Design · Week 8 revision
Week 8 revision: Senior level
Senior week in ten minutes: Docs, schedulers, streams, regions and senior habits, then six questions.
New System Design videos go up at 6 pm. Subscribe on YouTube so you don't miss it.
Got a doubt? Ask in the comments under the video.Subscribe
Lesson 35Google Docs
The last week of lessons was the hardest. It started with three people typing into the same sentence.
Lesson thirty-five. Concurrent edits are made against older versions, so their positions must be adjusted: Ana's s moved from position three to seven. Editors' browsers keep WebSockets open, and a load balancer routes every editor of one document to the same session server, which orders the edits with operational transformation, or merges them with a CRDT. Each edit is appended to the edit log before it's broadcast, and snapshots make loading fast. Cursors are sent live, and never stored.
The interview line: operational transformation with a central server, or a CRDT for offline-first; one session server per document; edits logged before they're acknowledged; snapshots for loading and version history; and presence as throwaway data.
Lesson 36The job scheduler
Then cron, for a whole company, after one machine's failure left the restaurants unpaid.
Lesson thirty-six, in three lines. Job definitions and individual runs live in a database, with runs indexed by their start time, so finding what's due is one quick query. Workers claim a run with a conditional write and a lease, extended by heartbeats, so a dead worker's run returns to pending. And because a paused worker can outlive its lease, runs happen at least once, so jobs are idempotent, with fencing tokens.
The interview line: runs claimed with a lease and heartbeats, idempotent jobs, priorities and per-team quotas, retries into dead letters, and jitter to spread the midnight spike.
Lesson 37Stream processing
Then QuickBite sold ads, and every click became money.
Lesson thirty-seven. Never add one to a database row per click: keep every click as an event in Kafka, and count the stream with a processor like Flink, in one-minute windows. Count by when each click happened, using watermarks to wait for late clicks. And checkpoints, saving counters and Kafka offsets together, plus idempotent output, give exactly-once counts, while a nightly recount from raw events produces the billing numbers.
The interview line: click events into Kafka, partitioned by ad; a stream processor counting tumbling windows by event time, with watermarks and checkpoints; idempotent writes to a counts store; and a nightly batch recount for anything that's billed.
Lessons 38 and 39Regions, and senior habits
And to finish: QuickBite went abroad, and then we looked at the whole course on one board.
Lesson thirty-eight. Regions are for speed, survival, and laws that keep data in-country. Give every customer a home region, so each record has exactly one writer and regions never conflict. Send users to the nearest healthy region with geo DNS, copy data asynchronously, accepting a few seconds of possible loss, and practise failover, because an untested one is only a hope.
Lesson thirty-nine. Requirements before boxes, and only numbers that decide something. Every trade-off said in one shape: we gain this, we give up that, and that's acceptable because of this. Depth on the hardest part, not on every box. And the simple system that meets the requirements wins, because every extra box is a cost you pay every day.
What's nextThe final mock, and beyond
Tomorrow is the final mock interview of the course, and it's the one we've been building towards since lesson one: design QuickBite itself. After that, the mock interviews keep coming.
Twelve more mock interviews follow, every Sunday and Wednesday. Yelp, and places near you. A distributed cache. Spotify, and an online coding judge. Live comments and live video for fifty million viewers, a train booking rush, Google Maps, a stock exchange, hotel booking, and a metrics system. And finally, serving ChatGPT itself.
Test yourself
Why can't a shared document be saved with last write wins?
Show the answer
Each save would erase other people's typing: edits must be merged, not replaced.
A worker's lease runs out while it's still running a job. What can happen?
Show the answer
Another worker claims it and runs it too: a duplicate run.
In stream processing, what is a watermark?
Show the answer
An estimate that all events up to a certain time have arrived; windows close behind it.
Why recount ad clicks every night if the stream already counts them?
Show the answer
Billing needs exact numbers: dedupe, remove bots, and catch what the stream missed.
Why not copy data between regions synchronously?
Show the answer
Every write would wait for a round trip to the far region.
What two things should every box on your diagram have?
Show the answer
A reason it's there, and a cost you can name.
Lessons on weekdays, the week's revision on Saturday, a mock interview on Sunday.