Throughput
easy 30 minThroughput is how much work a system finishes per second.
See it run
How much work gets finished per second, which stage limits it, and what really raises it.
Operations
One server to eight
400 requests arrive every second. One server finishes 100.
Step 1 of 5
One server
- Busy
- 100%
arrive
400/s
finish
100/s
queue grows
300/s
It finishes 100. The queue grows by 300 every second.
Step 1: One server
def finished(arriving, servers, each=100): return min(arriving, servers * each)def queue_growth(arriving, servers, each=100): return max(0, arriving - servers * each)- Answers
- How many servers?
- You leave with
- Capacity, with room
Four are enough on paper and completely busy. Six leave each at 67%.
In the real world
The same throughput doing real jobs. Pick one and step through it.
One small system, improved step by step. Each number can be worked out.
Step 1 of 5
Start
| Step | Reason | Throughput |
|---|---|---|
| Nothing | 2 connections, 20 ms | 100/s |
| + Pool | ||
| + Cache, 80% | ||
| + Batch of two | ||
| + 4 machines |
Two connections. Each request needs 10 ms to connect and 10 ms to query: 2 / 0.02 = 100 a second.
Step 1: Start
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Widening the wrong stage
criticalCapacity of a chain is its minimum. Anything else changes nothing.
Wrongscale(api, 4) # api is 30% busyRightstage = min(capacity, key=capacity.get)scale(stage, 2)One call per row
majorA round trip and a commit for every row.
Wrongfor r in rows: db.insert(r) # 1,000 x 5 msRightdb.insert_many(rows) # 50 msA queue without a limit
criticalIt grows until memory ends, and old work is useless by the time it runs.
Wrongqueue = [] # foreverRightqueue = Queue(maxsize=1000)# full: answer 429 at onceCounting attempts
minorErrors are quick, so a failing system looks busy and healthy.
Wrongmeter.record(); handle(req)Righthandle(req)meter.record() # only after success
Interview tips
How to explain it
- Finished work per second.
- The narrowest stage decides.
- Higher is better, for capacity.
Three formulas
- In progress = rate × time.
- Stage = workers / time.
- Cache: 1 / (1 - hits).
Raise it by
- Parallel workers, batches.
- Caches, pools.
- Balancing, queues and workers.
Watch out
- Bandwidth is a limit, not a result.
- Retries past saturation.
- A weak test client.