System design · like a utility’s control room
Design a power grid control system
Watch a million sensors and keep the lights on, even when the control room can’t see.
The interview question
Design the system that watches a power grid’s sensors and sends commands to keep it safe.
Here is the simplest version that works. An interviewer doesn’t want the finished drawing. They want to watch you keep it standing while it breaks, one problem at a time.
Break 1 of 4 · 🗄️ Too much data
A million readings a second
Every sensor reports ten times a second. The collector writes each reading to a database, and falls behind.
Faults caught in time: Readings arrive 4 minutes late
How do you take in a million readings a second?
- Append them to a log that many readers can follow at their own pace
- Keep only 1 reading in 100
- Write each one to the database, but faster
Show the fix
Append them to a log that many readers can follow at their own pace. Appending to the end of a log is the fastest write there is. Control, dashboards and history each read it at their own pace.
Faults caught in time: Readings reach Control in 50 ms
Why not the others?
- Keep only 1 reading in 100. A fault can start and finish between the readings you kept.
- Write each one to the database, but faster. A database that updates and indexes every row can’t keep up with a firehose. The shape of the work is wrong, not the speed.
The idea behind it: The append-only log.
Break 2 of 4 · 💥 Things break
The control server dies
The one Control server crashes at 3 a.m. Nobody is sending commands to the grid.
Faults caught in time: 9 minutes with nobody in charge
How does control survive a crash?
- Three copies that elect a leader; if it dies, the others pick a new one
- Two copies, both giving orders
- A spare that someone switches on
Show the fix
Three copies that elect a leader; if it dies, the others pick a new one. The copies vote. A majority agrees on one leader in about a second, and only the leader gives orders.
Faults caught in time: A new leader in 1 second
Why not the others?
- Two copies, both giving orders. When they disagree, one opens a breaker while the other closes it. That’s called split brain.
- A spare that someone switches on. At 3 a.m. that’s minutes of nobody in charge, at the worst moment.
The idea behind it: Raft leader election.
Break 3 of 4 · 💥 Things break
The network splits
A storm cuts the link to one region. Control can’t see it, and the region can’t hear Control.
Faults caught in time: A region with no orders
What should that region do on its own?
- Simple safety rules that run locally, without Control
- Wait for Control to come back
- Shut the region down to be safe
Show the fix
Simple safety rules that run locally, without Control. Each substation knows the basics (trip on overload) and acts in milliseconds. Control coordinates; it isn’t needed to stay safe.
Faults caught in time: The region stays safe on its own
Why not the others?
- Wait for Control to come back. A fault during the storm would go unhandled until the link returns.
- Shut the region down to be safe. You’d black out a whole region because a cable broke.
Break 4 of 4 · 🔁 Messages repeat
Clocks disagree
One substation’s clock runs 2 seconds fast. Its readings look like they came from the future, and Control acts on them in the wrong order.
Faults caught in time: A breaker tripped for an old fault
How do you order events from many clocks?
- Stamp each reading with its time and how unsure that time is, and order carefully
- Trust every clock
- Use the time each reading arrived
Show the fix
Stamp each reading with its time and how unsure that time is, and order carefully. No clock is exact. Knowing how wrong it might be lets you wait out the doubt, or flag readings too close to call.
Faults caught in time: Events in the order they happened
Why not the others?
- Trust every clock. That’s the bug: one fast clock reorders the whole story.
- Use the time each reading arrived. Networks delay some messages more than others, so arrival order isn’t what happened.
The idea behind it: TrueTime and clock uncertainty.
Say it in the interview
- Sensors stream into an append-only log, which control and dashboards read at their own pace.
- Control is three copies with an elected leader, so a crash costs a second.
- Substations keep local safety rules, so a network split is safe.
- Every reading carries its time and how unsure that time is.
- Under it all: assume failure, and design so it’s survivable.
The six forces behind every design
Every break above is one of these. Learn the forces and the moves that answer them, and a design you have never seen stops being new.
- Many copies behind a load balancer
- A cache for what’s asked again and again
- A waiting line, and a fair limit each
- Do it later, from a queue
- Send results as they’re made
- Ask twice, take the faster
Break it yourself.
The diagram is live: press Break it, watch what goes wrong, and pick the fix. Free, nothing to install.