Two engineers are asked to design the same app.
Engineer A says: “I’ll use MongoDB. It’s scalable and fast.” The interviewer asks, “How much data will you have?” “Um… a lot?”
Engineer B grabs a pen: “One million users, about 10 posts each a month, roughly 2 KB a post. That’s 20 GB a month, about 240 GB in a year. A single PostgreSQL database handles that easily. We don’t need a distributed database.”
Same question. Engineer B didn’t know more technology. They just did the maths first.
This is back-of-the-envelope estimation: rough, quick calculations that tell you how big your system really is. You don’t need exact numbers. You need the right order of magnitude: is it 10 requests a second, or 10,000? Those two numbers lead to completely different designs.
Why estimate at all?
Because estimation answers the questions that decide your architecture:
- Which technology? Does one database cope, or do you need to split data across many?
- How many servers? One, ten, or a thousand?
- How much will it cost? $50 a month, or $50,000?
- What breaks first as you grow?
Without numbers, every choice is a guess. And guesses go wrong in both directions: you either pay for a giant system you don’t need, or launch one that falls over on day one.
The estimation chain
Every estimate follows the same chain. Each step feeds the next:
- Users: how many people use it each day (daily active users, or DAU)?
- Traffic: how many requests per second (QPS, queries per second)? How many are reads, how many writes? What’s the peak?
- Storage: how big is one item, how many per day, and how much after a year or five?
- Bandwidth: how much data flows in and out each second?
- Servers: how many machines handle the peak, with room to spare?
The cheat sheet
You only need a handful of numbers to do this in your head:
The most useful trick: a day has 86,400 seconds, so just call it 100,000. Now “10 million requests a day” is instantly about 100 per second. You lose a little accuracy and gain a lot of speed, which is exactly the point.
A worked example: a URL shortener
Let’s estimate a service like bit.ly from scratch. The assumptions:
- 100 million new short links a month.
- Each link is opened about 10 times (10 reads for every write).
- Each stored link takes about 600 bytes (the long URL, the short code, a few details).
Walk through it:
- Writes: 100 million a month ÷ about 2.6 million seconds in a month ≈ 40 writes a second. Tiny.
- Reads: 10 times that, 1 billion a month ≈ 385 a second on average, about 1,200 at peak.
- Storage: 100 million × 600 bytes = 60 GB a month, about 3.6 TB after five years.
- Short codes: 7 characters from 62 letters and digits gives about 3.5 trillion codes. At 100 million a month, that lasts about 2,900 years.
The conclusion: one PostgreSQL database handles 40 writes a second with ease. 1,200 reads a second is comfortable too, especially with a cache in front, because a short link never changes once it’s made, so it’s perfect for caching. No sharding, no exotic database, no microservices.
That decision took five minutes, and you can defend every part of it.
Read-heavy or write-heavy?
One number from your estimate changes the design more than any other: the ratio of reads to writes.
- Read-heavy systems (news sites, product catalogues, URL shorteners, social feeds) serve the same data to many people. Cache it. Add read copies of the database. A few seconds of staleness is usually fine.
- Write-heavy systems (chat, sensors, payments, logs) change constantly, and each user’s data is different. Caching helps less. Use queues to absorb bursts, storage that appends quickly, and eventually split writes across machines.
Most apps are read-heavy, but don’t assume it. A chat app can be 40% writes, and a design tuned for reads will struggle.
How many servers?
Once you know the peak requests per second (RPS), the server count is one line:
servers = (peak RPS × safety margin) ÷ RPS per server
Say the peak is 10,000 requests a second, a load test shows one server handles 1,000, and you add a 1.5× safety margin for growth and surprise spikes:
(10,000 × 1.5) ÷ 1,000 = 15 servers
Then add about 25% for failover, so one or two servers can die without anyone noticing: about 19 to 20 servers. With auto-scaling, you might run 12 normally and grow to 20 at peak.
Notice where the “1,000 per server” came from: a load test, not a guess. Estimates get you started. Measurements keep you honest.
Failure first: when the estimate is wrong
Estimates will be wrong sometimes. Plan for it:
- Too low. You planned for 1,000 users and got 10,000 on launch day. The database runs out of connections, CPU hits 100%, and limits you set for 1,000 users start rejecting real ones. Plan for 3 to 5 times your expected launch load, and load-test before launch.
- Too high. You planned for a million users and built Kubernetes, multi-region and a managed everything. You got 100 users and a $5,000 monthly bill. Start small, use managed services, and scale when the numbers ask.
- Wrong ratio. You assumed 90% reads, but it’s 60/40. Your cache keeps getting invalidated and the single write database becomes the bottleneck. Measure the real ratio as soon as you have traffic.
And design so that a wrong estimate makes the system slower, not dead. If the database is overloaded, serve slightly old data from the cache with a warning, rather than an error page. If even that fails, fail fast with a clear message instead of letting every request hang.
Puzzle: the $90,000 surprise
The culprit: polling. The app asks the server “any new messages?” every second, for every user, all day:
10,000 users × 86,400 seconds = 864 million API calls a day
≈ 26 billion calls a month
at about $3.50 per million calls ≈ $90,000
The messages were never the problem. The checking was. The fix: push new messages to the app over a single open connection (a WebSocket) instead of asking every second, and only send a push notification when the user is offline.
The lesson: estimate the hidden traffic too: polling, retries, health checks, notifications multiplied by group size. One small design choice can multiply your costs by a hundred.
In the interview
When an interviewer asks “How many servers do you need?”, never answer “Kubernetes will auto-scale, so it doesn’t matter.” Instead:
- State your assumptions out loud: users, actions per user, size per item.
- Do the maths roughly, rounding freely.
- Use the numbers to decide: “40 writes a second, so one database is fine.”
- Find the bottleneck: “Reads dominate, so caching gives us the biggest win.”
Interviewers don’t care whether you get 347,000 or 350,000. They care that numbers drive your design.
Key takeaways
- Estimate before you design. Users → traffic → storage → bandwidth → servers.
- Rough is fine. You need the order of magnitude, not the decimal point. Call a day 100,000 seconds.
- Let numbers decide. “PostgreSQL handles thousands of writes a second; we have 40” beats “let’s use Cassandra because it scales.”
- Find the read/write ratio. Read-heavy → cache. Write-heavy → queues and splitting writes.
- Add safety margins, then verify with load tests.
- Count hidden traffic and cost. Polling and retries can sink a budget.
That completes the foundations: how architects think, what system design is, how to write requirements, and now how to size a system. Next, we’ll look at the shape of systems themselves: monoliths, modular monoliths and microservices.
Comments