Playground: back-of-envelope capacity calculatorPlayground: back-of-envelope capacity calculator
The interview estimation skill, as a tool. Move the sliders and watch QPS, storage and bandwidth fall out: the same math you will do on a whiteboard.Interview estimation skill, ek tool ke roop mein. Sliders hilao aur dekho QPS, storage aur bandwidth nikalte hue: wahi math jo tum whiteboard pe karoge.
What "scale" means, precisely
A system scales when you can grow its capacity by adding resources instead of redesigning it. Two kinds of growth hurt differently: more users (more concurrent requests, more connections) and more data (bigger tables, slower queries, longer backups). A good design names which one it is solving.
Vertical scaling (scale up)
Buy a bigger machine: more CPU, more RAM, faster disk. A modern top-end server can have 128 cores and 2 TB of RAM, so "just get a bigger box" takes you surprisingly far. Entire startups run on one large Postgres instance.
Why people still choose it: zero code changes, no distributed-systems complexity, strong consistency for free, ops stay simple.
The hard limits:
- There is a ceiling: you cannot buy an infinitely big machine.
- One machine is a single point of failure. Restart = downtime.
- Cost grows super-linearly: the biggest instances cost far more per unit of power than mid-size ones.
Horizontal scaling (scale out)
Add more ordinary machines and spread traffic with a load balancer. No ceiling: add the 10th server like you added the 2nd. Failure of one server removes 1/N of capacity, not 100%.
The price: statelessness. If any server can take any request, no server may hold request-specific state. Logged-in sessions, carts, in-memory caches: all of it moves to a shared store (Redis) or the client (JWT). This one constraint shapes the entire application tier.
Worked example: sessions done wrong and right
v1: login session stored in server memory. LB sends request 1 to server A (login works), request 2 to server B ("who are you?"). Broken. Two fixes: sticky sessions (LB pins user to A, but if A dies the session dies too, and load spreads unevenly), or stateless: session in Redis, any server reads it in ~1 ms. The stateless version survives server death, deploys and autoscaling. This is why "stateless app tier" is the default answer.
Numbers to carry
- One well-tuned app server: ~1k-10k simple RPS; one well-tuned Postgres: ~10k-100k simple reads/sec (mostly from its cache).
- Autoscaling reaction time: minutes (provision + boot + warm). Traffic spikes arrive in seconds. Pre-scale for known events.
- Each new tier (cache, queue, replica) is another thing to operate: scale in steps, not all at once.
The scaling ladder (the order to climb)
- One server does everything (works to ~1k users).
- Split the database onto its own machine.
- Add app servers behind an LB (stateless first!).
- Add a cache (biggest win per rupee).
- Add read replicas for the DB.
- Shard the DB only when writes truly exceed one primary.
Jumping straight to microservices and sharding from step 1 is the most common resume-driven design mistake.
Common interview traps
- "Add more servers" without making the app stateless first.
- Forgetting the database: scaling the app tier 10x while one DB handles all writes.
- Autoscaling assumed to react instantly.
Interview Q&A
Q: Your API went from 1k to 1M users and is timing out. First three things you check?
A: (1) The database: slow query log and connection pool saturation, since DBs are usually the first wall. (2) Whether hot data is cached: a 90% cache hit rate can remove 90% of DB load. (3) Whether the app tier is stateless so more servers can be added behind the LB.
Q: When is vertical scaling the right answer?
A: Early stage, or stateful workloads like the primary DB where horizontal scaling costs consistency and complexity. A bigger primary + read replicas beats premature sharding almost every time.
"Scale" ka sahi matlab
System tab scale karta hai jab uski capacity redesign kiye bina, resources add karke badha sako. Do tarah ki growth alag dukh deti hai: zyada users (zyada concurrent requests, zyada connections) aur zyada data (badi tables, slow queries, lambe backups). Accha design batata hai wo kaunsi problem solve kar raha hai.
Vertical scaling (scale up)
Badi machine lo: zyada CPU, zyada RAM, fast disk. Aaj ka top-end server 128 cores aur 2 TB RAM tak le sakta hai, matlab "bada box lo" approach soch se zyada door tak chalti hai. Poore startups ek bade Postgres instance par chalte hain.
Fayda: code mein zero change, distributed systems ki complexity nahi, consistency free, operations simple.
Hard limits:
- Ceiling hai: infinitely badi machine nahi milti.
- Ek machine = single point of failure. Restart = downtime.
- Cost super-linearly badhti hai: sabse badi instances per-unit-power mehngi padti hain.
Horizontal scaling (scale out)
Aam machines jodo aur load balancer se traffic baanto. Koi ceiling nahi: 10vi server waise hi jodo jaise 2nd jodi thi. Ek server marne par sirf 1/N capacity jaati hai, 100% nahi.
Keemat: statelessness. Agar koi bhi server koi bhi request le sakta hai, to koi server request-specific state nahi rakh sakta. Login sessions, carts, in-memory cache: sab shared store (Redis) ya client (JWT) par jaata hai. Ye ek constraint poori application tier ko shape karta hai.
Worked example: sessions, galat vs sahi
v1: login session server ki memory mein. LB ne request 1 server A ko bheji (login hua), request 2 server B ko ("tum kaun?"). Khatam. Do fixes: sticky sessions (LB user ko A par pin karta hai, par A mara to session mara, aur load uneven), ya stateless: session Redis mein, koi bhi server ~1 ms mein padh leta hai. Stateless version server death, deploys aur autoscaling, teeno survive karta hai. Isliye "stateless app tier" default answer hai.
Yaad rakhne wale numbers
- Ek achhi app server: ~1k-10k simple RPS; ek achha Postgres: ~10k-100k simple reads/sec (mostly cache se).
- Autoscaling reaction time: minutes (provision + boot + warm-up). Traffic spikes seconds mein aate hain. Known events ke liye pehle se scale karo.
- Har naya tier (cache, queue, replica) operate karne ki ek aur cheez hai: steps mein scale karo, ek saath sab nahi.
- Ek server sab kuch kare (~1k users tak chalta hai).
- Database ko alag machine par.
- LB ke peeche zyada app servers (pehle stateless banao!).
- Cache add karo (per rupee sabse bada win).
- DB ke read replicas.
- Sharding tabhi jab writes sach mein ek primary se zyada ho jayen.
- "Aur servers laga do" bina app ko stateless banaye.
- Database bhool jaana: app tier 10x kar diya par writes ab bhi ek DB par.
- Autoscaling ko instant maan lena.
Scaling ladder (chadhne ka order)
Step 1 se seedha microservices aur sharding par kudna sabse common resume-driven design galti hai.
Common interview traps
Interview Q&A
Q: API 1k se 1M users par gayi aur timeouts aa rahe hain. Pehle 3 checks?
A: (1) Database: slow query log aur connection pool saturation, kyunki DB pehli deewar hoti hai. (2) Hot data cached hai ya nahi: 90% hit rate DB load ka 90% kaat deta hai. (3) App tier stateless hai ya nahi, taaki LB ke peeche servers jode ja saken.
Q: Vertical scaling kab sahi jawab hai?
A: Early stage, ya stateful workloads jaise primary DB, jahan horizontal scaling consistency aur complexity ki keemat leti hai. Bada primary + read replicas, premature sharding se almost hamesha behtar hai.