The Choices Before the Requirements a show in 8 chapters
Goal: make the bakery chain's 3 choices before naming a database
1 of 8 Your guess
Before we start
Every app that remembers things, an order history, a feed, a bank balance, has a computer somewhere keeping them. Someone had to decide how.
You are that someone, for a new app. Which picture is closest to what you decide first?
Pick the closest. You find out which fits at the end.
857 s ÷ 300 s ≈ 2.9: nearly three times as long, on 128 times the cores
2 of 8 The problem
A laptop against 128 cores
May 2015, a small workshop in Switzerland. Three researchers took the published results of big data systems, software built to spread one job across many computers, and asked what those papers rarely asked.
Not "how much faster with more machines?" but "is it faster than one ordinary computer doing the job alone?" They raced one core of a 2014 laptop against clusters of 128 cores.
Your goal: a chain of 40 bakeries wants its orders kept. Before anyone names a database, make its 3 choices: how many machines, where the number-crunching lives, and who runs it.
The job: a Twitter follower graph, 41 million accounts and 1.47 billion follow links. Rank every account by how many important accounts follow it, the rule Google once used to rank web pages.
Here it is on seven made-up accounts. Each round, every account hands its score out evenly along the arrows it follows. The paper's job ran 20 rounds.
Press Play to run the rounds.
Spark, one of the big systems, had reported 20 rounds of that ranking on 128 cores: 857 seconds. The researchers wrote the same ranking as one plain program, on one core of a 2014 laptop, reading the graph from the laptop's own disk.
How many seconds did the one laptop core take?
Next step: watch the race.
Both run the same 20 rounds on the same graph. Watch the clock.
Press Play to start the clock.
One core beat 128. Not because the big systems were badly built. The next chapter shows the bill they pay.
4 machines × 16 boxes of time = 64 boxes spentthe work alone: 37 boxes, so one machine takes 37
128 cores × 857 s = 109,696 core-seconds109,696 ÷ 300 ≈ 366 laptop jobs
40 shops × 50 orders = 2,000 orders a day2,000 × 365 days × 5 years = 3,650,000 orders3,650,000 × 1 KB = 3.65 GB (a GB is a million KB)86,400 seconds in a day ÷ 2,000 ≈ one order every 43 s
20,000,000 rows: 74 ms on one core, measured3,650,000 ÷ 20,000,000 × 74 ms ≈ 14 ms
3 of 8 The cost
The bill for splitting
Split one job across machines and the pieces have to talk, wait for each other, and agree on who has what. Here are four machines on a made-up job, three rounds.
Press Play to run three rounds.
Now the real race, counted as machine time. One core busy for one second is a core-second. Spark's 128 cores ran 857 s each.
That is 366 times the machine time the laptop spent, for the same answer.
Why count core-seconds, not seconds?
Seconds say how long you waited. Core-seconds say how much machine you paid for: 128 cores busy for 857 s is 109,696 core-seconds of machine, for a job one core did in 300.
The paper put four published systems against the one core. Only one got under the line.
Its name for the honest test is COST: how many cores does a big system need before it beats one core running a plain program? For several systems, no setup their own authors reported ever did.
So why ever use many machines? Three reasons, and a design should name which one it is paying for.
A system spread over many machines is a distributed system. If none of the three applies, mostly what it buys is the bill.
Back to your goal. The bakery chain: 40 shops, about 50 orders a shop a day, five years of history, 3 developers. Saving one order is a write.
That is 3.65 GB in all, and one write every 43 seconds.
How fast does one core get through that? The lesson timed one core adding up 20 million made-up orders: 74 ms. The bakery's whole five years is about 14 ms.
3.65 GB fits in a small server's memory several times over. None of the three reasons applies. Choice 1: one machine.
3,650,000 rows − the 8 shown = 3,649,992 more
4 of 8 The idea
The till and the back office
The bakery keeps its orders as a table: one row per order, one column per fact about it.
Two very different kinds of work read this one table.
At the counter, the till does one thing over and over: record this sale, now, correctly. Each job touches a row or two, and a customer is standing there, so it must finish in milliseconds.
Once a month the back office asks: which shop sold the most last quarter? That reads every order ever made, but only two facts of each, shop and price. Nobody minds a minute.
Press Play to read the rows.
The till's kind of work is transaction processing (OLTP). The back office's is analytics (OLAP).
One database can do both while the business is small. As it grows, a long analytics read starts slowing the till, for the people standing there.
And the back office soon wants data from other systems too, not only the till's.
The usual move: a second copy, kept in step, for analytics. The till keeps its own database, and the long reads move off it.
For the bakery, a replica of the same database is enough for years. Choice 2: analytics reads a replica.
5 of 8 The idea
Warehouse or lake
When analytics outgrows a replica, its copy takes one of two shapes. The first: a separate database every system's data is copied into, cleaned and arranged into tidy tables first. The back office with a filing clerk: a data warehouse.
The second: dump everything, raw, in whatever format it arrived, into cheap storage, and sort it out when someone needs it. The back office with a big box of receipts: a data lake. Data scientists like it: nothing is lost.
Most large companies keep both: the lake holds everything raw, the warehouse holds the cleaned part most questions need. A newer middle road, a lakehouse, puts the tables straight on the lake's files.
The bakery needs none of this yet. Its replica stays until the questions want data from other systems.
Why not keep only the lake?
Then every question starts by sorting the raw box again. The warehouse keeps the sorted part that most questions need, so most people never touch the box.
One choice is made for you, by law. Since 25 May 2018 a European regulation, the GDPR, gives people in the EU rights over data about them, in some cases the right to have it erased. Some countries require certain data to stay inside their borders.
So "which machine?" can have a legal answer before it has a technical one.
5,000,000 students ÷ 3,600 s in the hour ≈ 1,389 requests a second365 days × 24 hours = 8,760 hours, all of it in 1so that hour is 8,760 times the average hour
5% of the expected load: 1 in every 20 it was built for
over 90% off: every 100 spent became under 10
6 of 8 The fix
Rent or own, one or many
A real app is rarely one database. It is a database plus a cache plus a search index plus a queue, stitched together. Whoever stitches them is designing a data system.
Each part needs machines, and you can rent them by the hour from a company like Amazon, which also runs the parts for you.
19 October 2022: David Heinemeier Hansson of 37signals, the company behind Basecamp and HEY, posted "Why we're leaving the cloud". They paid "over half a million dollars per year" for Amazon's database and search alone.
His argument: the cloud excels at two ends, a tiny app and a wildly uneven load. A steady, growing company sits at neither, and renting forever costs it more than owning.
The uneven end, from the lesson's made-up companies: an exam results site. Five million students, nearly all in the hour results go up, once a year.
Owning machines big enough for that hour means paying for idle machines the other 8,759 hours of the year. Renting for the peak wins.
22 March 2023, from inside Amazon: Marcin Kolny on the Prime Video team. Their tool that watches live streams for glitches was built from many small rented pieces, each passing every video frame to the next through Amazon's S3 storage.
It hit "a hard scaling limit at around 5% of the expected load", and every hand-off cost money.
They moved every piece into a single program on ordinary rented servers. Their infrastructure cost fell "by over 90%".
What changed
- Prime Video's bill, per 100 it used to spend: 100 → under 10
Hansson left rented machines but kept many machines. Prime Video kept renting but went from many pieces to one. Two separate dials.
Who runs it: managed or self-hosted. How many machines: single-node or distributed.
The bakery has 3 developers, and nobody should be fixing a database at 3 a.m. A managed database with automatic backups is the cheapest thing they can buy. Choice 3: managed.
Goal met, and no database brand named once.
7 of 8 Your guess
Your picture now
Goal met: one machine, analytics on a replica, managed. All from 3.65 GB, one write every 43 s and 3 developers. Which picture is closest now?
Pick one.
c is the lesson: measure the job, then choose. a names a database before anyone knows the job. b buys the bill up front: 128 cores took 857 s on a job one core did in 300.
8 of 8 Keep this
Keep this
Before arguing about which database, ask what the data is for, how big it is, and who is waiting. Then ask whether you need more than one machine at all.
The price: one machine has no spare when it dies, and stays far from users on other continents. If the load needs those, name the reason, then pay the bill. With the graph in memory, the one core took 275 s.
Read the full lessonComing up The bakery has its machine and its managed database. Next, how Twitter delivered timelines in 2012, and the three promises every data system has to keep as it grows.