Estimación Aproximada
Estimación de capacidad · Cálculo de servilleta
Escrito por Darjus Kazakevic · revisado el
Five minutes of arithmetic tells you if one server is enough or you need fifty.
Back-of-the-envelope estimation is quick arithmetic done before design. You start from a few assumptions, such as daily active users and actions per user, and derive requests per second, storage per year and bandwidth. The goal is the order of magnitude: is it 10 requests per second or 10,000? That answer decides whether one Postgres is enough or you need caches and shards.
The main trick is to round. A day has 86,400 seconds; call it 100,000. Then 1 million requests a day is about 10 per second. The cost is precision. An estimate is often off by a factor of two, so use it to choose a design, then measure the real system.
En esencia — Turn users and actions into requests per second, storage and bandwidth with round numbers, size for the peak, and let the result choose the design.
Cuándo recurrir a él
Recurre a él cuando
- Before choosing between one database and a sharded cluster
- At the start of a design interview, before drawing any boxes
- When a launch or a campaign may multiply traffic
Reconsidéralo cuando
- A cheap load test on the real system can measure it instead
- To set exact budgets or contracts — an estimate can be 2× off
- A small internal tool that one server obviously handles
Conceptos clave
- Latency numbers (Orders of magnitude)
- A memory read is about 1,000 times faster than an SSD read, and a round trip inside one datacenter takes about 0.5 ms. Knowing these ratios tells you where the time goes before you profile anything.
- Powers of two and bytes
- Sizes step by about 1,000: KB, MB, GB, TB, PB. Learn a few typical sizes: a user row is about 1 KB, a phone photo about 2 MB, an hour of HD video about 2 GB.
- From users to QPS (Requests per second)
- QPS (queries per second) = daily active users (DAU) × actions per user per day ÷ 100,000 seconds. Work out reads and writes separately, because they scale in different ways.
- Peak factor and headroom
- Traffic is not flat. The busiest hour is often 2–5 times the daily average, and launches go higher. Size for the peak, then add spare capacity, because servers slow down sharply above about 70% busy.
- Storage and bandwidth
- Storage per year = writes per day × size × 365 × copies. Bandwidth = requests per second × response size. For media apps, these limits arrive before CPU does.
Reglas de diseño
- Estimate the peak, not the average
- Users do not arrive evenly. Multiply the daily average by a peak factor of 2–5, and more for launches and sales. A system sized for the average fails every evening.
- Round aggressively
- Use 100,000 seconds a day, 1,000 for 1,024, and one significant digit. You need the order of magnitude, and simple numbers keep the arithmetic in your head and easy to check.
- Work in the same order, out loud
- Write the assumptions first, then go: traffic, peak, storage, bandwidth, servers. Others can challenge one number, not the whole result. End by saying what the numbers change in the design.
- Check the result against known numbers
- Per server, for simple requests: an app server about 1,000 per second, Postgres about 10,000 queries, Redis about 100,000 operations. If a to-do app needs 10,000 servers, recheck the inputs.
Errores habituales
- Sizing for the daily average. The system is fine at 3 a.m. and falls over every evening at the peak.
- Mixing bits and bytes. Network links are sold in bits per second, so 3 GB/s of egress needs 24 Gbit/s, not 3.
- Forgetting copies and indexes. Three replicas plus indexes can turn 1 PB of data into 4 PB of disk.
- Stopping at the numbers. “15,000 reads per second” helps nobody until you say what it changes: a cache, a CDN, or ten databases instead of one.