Loading
Loading
Foundations
Rough numbers, computed out loud, that decide which architecture is even on the table.
By the end of this chapter
The purpose of a back-of-the-envelope estimate is not accuracy. It is elimination. If the answer is forty requests per second, a single machine with a single database is correct and everything else is overengineering. If it is four hundred thousand, sharding is not optional. The estimate decides which conversation you are having.
A handful of reference points make arithmetic possible without a calculator. These are deliberately round.
| Quantity | Round value |
|---|---|
| Seconds in a day | ~100,000 |
| Seconds in a month | ~2.5 million |
| Memory read, 1 MB | ~microseconds |
| SSD random read | ~100 microseconds |
| Round trip within a datacentre | ~0.5 ms |
| Round trip across an ocean | ~150 ms |
| One character of UTF-8 text | ~1 byte |
| A modest JSON record | ~1 KB |
Take a link-shortening service. Ten million people use it, and each creates one link a day and follows twenty.
Now read what that implies. Two thousand reads per second is comfortably within one well-indexed database with a cache in front. One hundred writes per second is nothing at all. Under two terabytes a year fits on one machine for several years. So the correct first architecture is unglamorous: one database, one cache, several stateless API servers — and the estimate is what justifies refusing to shard.
Traffic is never flat. A consumer product might see three to five times its daily average in the evening peak, and a product tied to an event can see far more than that for a short window.
You provision for peak and you pay for average, which is the entire commercial argument for elastic infrastructure. When you cannot scale elastically, the peak multiple is what sizes the fleet — and it is worth asking whether the peak can be flattened instead, by moving work off the request path and into a queue.
Sign in to keep a note here. It is free, and nobody else can see it.
Sign inWhat this chapter was for: