AlgoViz

Grow a design

medium 35 min

Start with the smallest system that does the job.

Video lesson · Chapter 1 of 5

Record the reason for each version

0:00 / 4:07

One break, one fix

1:20Reel coming soon

Theory

Read or listen first. About 1 min.

What it is

Growing a design means starting from the smallest system that works and changing it in steps. Each step answers one problem that the previous version could not.

It is the opposite of drawing the final picture from memory.

Why it exists

A small system can be explained, tested and trusted. From there, each addition has a visible reason.

Growing also tells you when to stop. If no target is missed, there is nothing to add.

A short history

  1. 1975

    John Gall's Systemantics: a complex system that works has evolved from a simple one that worked.

  2. 1990s

    Extreme programming popularises "you aren't gonna need it" and frequent small steps.

  3. 1999

    Martin Fowler's Refactoring describes improving software in small safe changes.

  4. 2000s onwards

    Cloud platforms make it practical to add capacity and parts after launch.

Words to know

Version
A complete design that does the job within its limits.
Break
The first target a version misses.
Headroom
How far you are from a limit.
Over-engineering
Parts without a reason.
Migration
Moving from one version to the next while running.

How it works

Step through the idea, or press Play.

Step 1 of 3

Version 1. Correct, complete and small

Understand it

Start here

The village and the river

A village needs to cross a river. Nobody begins with a great bridge. They lay stones, and use them until something does not work. Each change answers one problem, and each has a price.

Stones, a plank, a bridge, and then no more
Five stepping stones

The loop

Four sentences per version

Grow or stop

SayExampleIf you cannot say it
It breaks here"Reads, 10,000 a second at 7:45, and I plan one database for that."You have not found a break
So I change this"Keep the newest position in Redis."You are adding a favourite part
It costs this"A position can be a few seconds old, and Redis can fail."You have not decided yet
Now the next limit is"A database failure at 7:45."You do not know whether to go on

Version 1

Small, but correct

Version 1 is small in parts, not in care. It does every chosen feature and keeps the rule that must never break. It is not a prototype that loses data.

A good version 1

  • Every feature, end to end
  • The "never" rule is enforced by the database
  • Data is backed up
  • You can walk one request through it
  • Two or three boxes

A poor version 1

  • Only the feature you like
  • "We will add checks later"
  • Seven boxes, nothing connected
  • A queue because queues are good
  • No backup of data that must not be lost

A version 1 for most prompts

Find the break

Ask with a number

Walk the targets in order and compare each with what the current version can do. The break is the first one that fails. These are the usual places.

Seven places a design breaks

  • Reads

    Too many a second for one store. Index, cache, replicas.

  • Writes

    Too many a second. Batch, queue, bigger machine, then split.

  • Size

    Data or files outgrow one place. Object storage, partitions, deletion.

  • Contention

    Many want one thing. A rule that lets one win, then a waiting room.

  • Connections

    Many are open at once. Gateways that only hold connections.

  • Distance

    The network uses up the time. Edge, regions.

  • Failure

    One part down breaks a promise. A standby, retries, a reduced mode.

Headroom: how long until it breaks?

months=ln⁡(limit/load)ln⁡(1+growth),ln⁡(10,000/2,500)ln⁡1.10≈14.5\text{months} = \frac{\ln(\text{limit} / \text{load})}{\ln(1 + \text{growth})}, \qquad \frac{\ln(10{,}000 / 2{,}500)}{\ln 1.10} \approx 14.5
2,500 reads a second growing 10% a month reach 10,000 in a little over 14 months. That is a reason to stop now, and to say when to look again.

Fix it

The smallest change first

For one break there are several fixes. Try them from cheap to heavy, and stop at the first that meets the target with room to spare.

BreakTry firstThenOnly then
Slow readsAn index, a smaller queryCache with a short lifeReplicas, a search engine
Many writesBatch themA bigger machine, a queueSplit the data
Large filesResize, compressObject storageCDN
Must be livePoll less oftenServer-sent eventsWebSockets with gateways
One machine failsBackup and a tested restoreStandby with automatic failoverA second region

Choosing a fix

Worked example 1

School bus tracker, four versions

Targets: a parent sees only their own child's bus, a position at most 10 seconds old, 99.9% on school mornings. The plan is one district first, then a whole city, then a live map.

Grow the bus tracker

Version 1: One district

Forced by: The features: a bus reports, a parent looks, the school sets stops. 50 buses and 2,000 parents.

Our systemParentsBusesBus servicePostgreSQLroutes, history
What changes
One service and PostgreSQL. A bus sends a position every 5 seconds, so 10 writes a second. Parents poll every 10 seconds, so 200 reads a second. Every read checks that this parent has a child on this bus. Nightly backup.
What it costs
Almost nothing. One thing to run.
What breaks next
Nothing yet. For one district, stop here. The next limit is reads, if a city joins.

Say: It already protects the child's stop. Two hundred reads a second need no cache.

Check the numbers

100,00010=10,000/s,100,0002=50,000/s,2,0002=1,000/s,1,000×50=50,000/s\frac{100{,}000}{10} = 10{,}000/\text{s}, \quad \frac{100{,}000}{2} = 50{,}000/\text{s}, \quad \frac{2{,}000}{2} = 1{,}000/\text{s}, \quad 1{,}000 \times 50 = 50{,}000/\text{s}
With a report every 5 seconds and a poll every 2, only two polls in five find something new, so 60% do not. 100,000 parents / 2,000 buses is 50 parents each. One position in five is 200 a second, half of the 400 used for the 115 GB estimate, so history is smaller still.

Worked example 2

Recipe sharing, five versions

Targets: pages in 300 ms for 95 of 100 requests, search in 500 ms, a posted recipe is never lost, 99.9%.

Grow the recipe site

Version 1: Launch

Forced by: Post, view and search. 100 recipes a day, four photos each.

Our systemCooks, readersRecipe servicePostgreSQLrecipesLocal diskphotos
What changes
One service and PostgreSQL. Photos on the machine's disk: 100 × 4 × 500 KB is 200 MB a day. Search with a plain query. Nightly backup of both, copied elsewhere.
What it costs
A disk failure loses up to a day. That misses "never lost", so this version is for a private trial only.
What breaks next
The promise not to lose a recipe, before any load.

Say: It works end to end, and I know which promise it does not keep yet.

Exceptions

What cannot wait for version 4

Growing step by step works because most changes are easy to make later. A few are not. Find them in version 1, spend a minute on each, and leave the rest.

Now or later?

ChoiceWhy it is hard to changeIn our two systems
Main keyEvery record and link uses itA recipe gets an ID that does not depend on one database
Who may see whatA leak cannot be undoneThe parent check is in version 1
Where data may liveLaws and contractsChildren's data stays in the home region
Public callsOthers depend on themPhoto links go through our own domain

Stop

Knowing when to stop

  1. 1

    Read the targets aloud

    Tick each one with the number that meets it.

  2. 2

    Remove each box in your head

    If no target fails, the box goes.

  3. 3

    Say what you did not build

    "No shards: 91 GB in five years."

  4. 4

    Name the next limit and its trigger

    "At about 10,000 page reads a second I would cache pages."

When they push past the stop

  1. Interviewer

    Would you not use Kafka here?

  2. You

    Which target would it help? Writes are 0.1 a second and nothing else reads them as they happen. Today it is a part to run with no job.

  3. Interviewer

    Say five teams want every new recipe.

  4. You

    Then there is a job. I would write each event to a table in the same transaction as the recipe, and publish from it. A log such as Kafka fits when several readers need their own position. The cost is running it, and duplicates that readers must handle.

Summary

The whole topic in one minute.

Begin small and correct. Find the break with a number, make the smallest fix, say what it costs, and repeat.

Stop when every target is met, and say that you are stopping.

  • Version 1 is small in parts, not in care.
  • One break, one fix, with a number and a cost.
  • Cheap fixes first: remove load, grow what you have, then add.
  • The first break may be a promise, not a load.
  • Stop aloud: what is met, what is not built, what would change it.

Sources