Book Deep Read · System Design Interview Vol 1 · Ch 1

Scale From Zero To Millions Of Users

System Design Interview: An Insider's Guide · Vol 1 · Ch 1 · Alex Xu · 2020

中文 →

What is this chapter about?

Whatever website or app you have open right now almost certainly started as one machine somebody rented. This chapter is about how that single machine grows into a whole server room. It opens Volume 1 of System Design Interview, and it is the only chapter in the book that designs no particular product. What it gives you instead is a route: on the way from zero to a few million users, what to change, and in what order.

An analogy first

Think of a website as a noodle shop. On opening day the owner does everything alone: take orders, cook, take payment, keep the ledger. Business booms — now what? The instinct is "hire a better owner." The real answer is division of labour: put a host at the door, add burners in the kitchen, pre-cook the popular dishes and keep them warm, hand a copy of the ledger to an accountant, pin delivery tickets to a wall for couriers to grab, and finally open branches across town. Every scaling step in this chapter maps onto one of those.

Why the old world was hard

When one machine stops coping, the cheap move is to buy a bigger machine. That road runs further than most people think — Stack Overflow served over two hundred million requests in a single day in 2016 on nine web servers and four databases. But it has one problem you cannot dodge: if that machine breaks, the site is simply gone. There is no substitute. So the real turning point is not "stronger" but "more" — a pile of ordinary machines, where losing one bothers nobody.

The mechanism: six things, in order

① Put a host at the door. Guests no longer walk up to a particular waiter; the host sends them to whoever is free. When a waiter calls in sick, guests are still served.

② But waiters must not "remember" guests. If the order you placed with waiter #3 lives only in his head, you have to order again the moment his shift ends. Write "who ordered what" into one shared book at the front desk instead, and any waiter can pick you up — this is the master switch for adding and removing staff freely.

③ Copy the ledger. Far more people read the books than write in them. Let writes go only into the original and reads go to the copies; the original instantly gets easier.

④ Pre-cook the popular dishes. The best sellers do not need making from scratch every time — that is caching. Photos and videos go further: keep a copy in every city and serve whichever is nearest.

⑤ Turn slow work into tickets on a wall. Photo editing, sending notifications — do not make the guest wait. Write a ticket, drop it in the queue, let the kitchen work through it, and add cooks when it backs up.

⑥ Only when it truly will not fit, split the ledger. One book is full, so split it into four by surname. This is the last step, and the only one you can barely walk back: once split, things that used to be a single lookup ("sort every guest by first visit") suddenly become painful.

How to use it

The six are ordered by return on effort: the early ones are cheap, reversible and fast-acting; the last is expensive and hard to undo. So the question worth asking is never "what technology should we adopt," but "which part gives out first?"

One line to remember

Scaling is not "buy a bigger machine." It is repeatedly moving the thing that gets remembered out of wherever it is blocking you: out of the waiter's head (stateless), onto copies (read replicas), closer to the guest (caching and edge delivery), into a queue (async) — and only then splitting it up (sharding).

Want the mechanisms, the numbers and the diagrams? → Switch to the deep read