Video in progress
Estimate how many application instances and how many DB connections are needed for the following figures.
At peak, 3,000 requests per second. Average response time is 200 ms, of which ~40 ms goes to DB queries. In a load test one pod handles 100 parallel requests without latency degrading. The DB has max_connections = 300.
By Little's law, the number of concurrent requests = RPS × average response time. At peak, 3000 RPS and 200 ms give ~600 concurrent requests; if each pod handles ~100, that's ~8–10 pods with headroom. DB connections are far fewer, depending on the time spent in the DB.
📖 Answer
The key formula is Little's law: L = λ × W. The average number of requests "inside" the system = the arrival rate × the time each one spends in the system.
Application level.
L = 3000 × 0.2 s = 600concurrent requests.- Each pod handles 100: 600 / 100 = 6 pods.
- Headroom: losing a zone, part of the pods going down during a deploy, GC. I usually add 30–50% — 8–9 pods, rounded up to 9–10.
DB connections.
- Each request spends only 40 ms in the DB:
3000 × 0.04 = 120concurrently active DB connections. - With 10 pods, that's ~12 per pod, and with headroom
maximumPoolSize = 15–20. - In total 10 × 20 = 200 < 300. We also check the autoscaling maximum against this: 15 pods × 20 = 300 — right at the limit, so either shrink the pool or add PgBouncer.
Two points that leave a good impression in an interview:
- Little's law works for any stable system: a thread pool, a Kafka consumer, a queue. "There are 10,000 messages in the queue, 500 per second get processed — each message waits ~20 seconds."
- Raising the pool size on the idea that "more is better" is a mistake. If the DB has 8 cores, 300 parallel queries won't speed it up, they just increase context switching and lock waits.
The calculation uses averages, but at peak latency grows — W grows, and L with it. So the final number is confirmed with a load test.
Sign up to mark studied questions and save your progress.