Core Concepts
Estimations
Estimate traffic, storage, and bandwidth in the units that determine a design choice.
A back-of-the-envelope estimate helps you make a design decision in an interview. Name the choice, identify the unit you need, and state the assumptions that determine the result. Work out enough about the traffic, storage, or bandwidth to choose a starting design and say what you would measure.
Turn daily activity into a peak write rate
To decide if one database writer can handle group chat, we need the number of write transactions per second it has to commit. Start with sends. Assume 10 million users are active each day and each sends 30 messages. We expect the busiest minute to average 3.5 times the daily rate.
10,000,000 users/day × 30 messages/user = 300,000,000 messages/day
300,000,000 messages/day ÷ 86,400 seconds/day ≈ 3,500 messages/s on average
3,500 messages/s × 3.5 ≈ 12,000 messages/s in the busiest minuteThat last figure is a per-second average over one minute. There can be higher bursts within it. If the prompt gives a peak rate the service must handle, use that rate for the capacity test.
Assume one database transaction per accepted send. The estimated busy minute needs about 12,000 committed transactions per second. If each transaction inserts the message and updates the channel's sequence number, it still counts as one transaction but changes two rows. If several sends commit in a single batch, the transaction rate falls and some sends may wait for the batch to fill. Name the work a transaction does before comparing rates.
Check whether a single writer fits
In a hypothetical end-to-end test with one writer, the highest sustainable rate is 15,000 committed transactions/s while 99% of sends are acknowledged within 200 ms. Test with the actual queries, indexes, and durability settings. Measure from send to acknowledgment, and count a write once it meets the durability promise. Testing a faster acknowledgment that can lose an accepted message would give us the capacity of a different design.
At the estimated 12,000 transactions/s, one writer is a starting point for this workload, with about 3,000 transactions/s of spare capacity. If the busiest minute averages 4.5 times the daily rate, the estimate rises to about 16,000 transactions/s and exceeds the tested capacity. Before committing to the writer count, test shorter bursts, simultaneous writes to a busy channel, and how much capacity remains after a failure.
If one writer falls short, check whether the design can do less work per send or batch writes within the latency budget. Splitting channels across writers can spread the load when channels can be written independently.
A queue gives a writer time to catch up after a burst. With 12,000 jobs arriving per second and capacity for 10,000, the backlog grows by 2,000 jobs every second. It starts to drain once arrivals fall below 10,000/s. After one second of excess traffic, a send at the back of the queue waits about 200 ms before its own write starts. Count that wait in the end-to-end send latency.
Estimate storage and bandwidth for the same workload
For storage, start with the 300 million messages per day. Suppose we keep messages for 30 days at an average of 400 bytes each for the stored text and message fields. Keep units with the terms so we can see what cancels.
300,000,000 messages/day × 30 days = 9,000,000,000 retained messages
9,000,000,000 messages × 400 bytes/message = 3.6 TB of message data
3.6 TB × 3 full copies = 10.8 TB across all copiesThese are decimal units. Budget separately for indexes, database overhead, and free space. When capacity is tight, the estimate lets us compare keeping all 30 days in the main store with moving older messages to cheaper storage.
For bandwidth, count every delivery. Assume a send goes to about 20 online recipients on average during that same busy minute, with 1 KB of payload per recipient. The delivery includes what the client needs to display the message, so it has its own byte size.
12,000 messages/s × 20 deliveries/message = 240,000 deliveries/s
240,000 deliveries/s × 1,000 bytes/delivery = 240 MB/s of payload
240 MB/s × 8 bits/byte = 1,920 Mb/s ≈ 1.9 GbpsThat is the outbound bandwidth across all the gateways, the servers that hold connections to clients. It excludes transport overhead. A busy channel can concentrate deliveries on some gateways. Check the busiest link and the traffic each gateway must carry when another goes down. For a gateway count, also measure how many simultaneous connections one gateway can sustain at that traffic level.
See also
- Introduction explains where an estimate can steer the interview.
- Latency vs Throughput shows how to compare rates at the latency the service must deliver.
- Scalability explains which limits more machines can address.
- Backpressure and Load Shedding follows an overloaded queue and shows how services can bound demand.
- Database Sharding shows how splitting writes changes the data path.
Used in
- Group Chat with Threads uses daily sends, gateway connections, and recipient deliveries to size different parts of the service.
- URL Shortener uses link creation volume and bytes per mapping to estimate annual storage growth.
- Online Chess uses active games and move frequency to estimate the peak move rate.
Done reading? Mark it so it sticks in your dashboard.