Module 1: Core Concepts
Scalability
Learn vertical vs horizontal scaling for large-scale systems — bottlenecks, stateless services, load balancers, databases, and interview trade-offs.
Scalability is the ability to handle growth in users, data, or traffic without the product falling over. Interviews start here because every later component choice — cache, shard, queue, CDN — is a scale decision.
What you will learn
- Contrast vertical and horizontal scaling with concrete product examples
- Identify CPU, memory, disk I/O, and network bottlenecks on a request path
- Explain why stateless app tiers + load balancers unlock scale-out
- Describe how reads, writes, and storage scale differently
- Draw a simple “grow from 1 box to N boxes” evolution in an interview
What “scalable” means
- A system is scalable when adding resources (CPU, RAM, machines, bandwidth) increases capacity in a roughly proportional way.
- In interviews, do not say “make it scalable.” Name the growth metric: more QPS, more storage, more concurrent connections, or more fan-out.
- Traffic growth — requests per second (QPS / RPS)
- Data growth — bytes stored and queried
- Complexity growth — fans-out such as followers, chat groups, notifications
- Scalability ≠ raw speed — a fast single box can still hit a hard ceiling
- Scalability ≠ availability — replicas help both, but failover is a separate design
Vertical scaling (scale-up)
- Vertical scaling means giving one machine more power: bigger CPU, more RAM, faster disk, or a wider network link.
- It is simple operationally — same codebase, same address, fewer moving parts — so it fits early products well.
- Best for MVPs, single-primary databases, and low-ops teams
- Limited by the largest instance the cloud vendor sells
- One failure domain: if that box dies, the service can go fully down
- Diminishing returns if the real bottleneck is locks or disk IOPS
- Large instances get expensive; N smaller nodes often win later
Horizontal scaling (scale-out)
- Horizontal scaling means adding more machines and spreading work across them, usually behind a load balancer.
- App tiers scale out cleanly when they are stateless: no critical session data stuck on one node’s local disk or memory.
- Put sessions, uploads, and caches in shared stores (Redis, object storage, DB)
- Any healthy node can serve any request
- You gain capacity and fault isolation
- You also inherit distributed pain: partial failure, retries, clock skew, consistency
- Practical limits: partitioning, cross-node chatter, and ops complexity
Vertical vs horizontal comparison
- Use this side-by-side framing when the interviewer asks which approach you prefer.
- Complexity — vertical wins early; horizontal wins at large scale
- Blast radius — one big box down can mean full outage; many nodes can lose one and keep serving
- Data layer — compute scales out easier than strongly consistent writes
- Team skills — horizontal needs better observability, deploys, and on-call habits
- Usual path — start vertical → cache / read replicas → scale app out → shard writes last
Find the bottleneck first
- Never propose Kubernetes, shards, or a rewrite before you name what is saturated. Interviewers listen for diagnosis first.
- CPU-bound — heavy JSON, image work, crypto → add compute or move work async
- Memory-bound — large heaps / caches → more RAM or externalize the cache
- Disk I/O-bound — scans, logging → indexes, SSDs, batching, colder storage
- Network-bound — big payloads, fan-out → compression, CDN, pagination, regions
- Lock / contention-bound — hot rows or global mutexes → redesign the data model (more servers will not help)
Scaling the app tier
- Once the app is the bottleneck and state is shared, run N identical API servers behind an L4/L7 load balancer.
- Health checks remove bad instances from rotation
- Autoscaling adds nodes when CPU or queue depth rises
- Avoid sticky sessions unless truly required
- Size DB/cache connection pools for N app nodes
- Use rolling deploys so capacity never collapses to one fragile box
Scaling reads, writes & storage
- Reads, writes, and storage do not scale the same way. Label every box on your diagram with which of the three it helps.
- Reads — Redis/CDN caches, DB read replicas, materialized views, pagination
- Writes — single primary first; queues, batching, then partitioning/sharding when forced
- Storage — object store for blobs; transactional DB for records (do not put videos in primary SQL)
- Queues — absorb spikes; workers scale independently of the request path
- CDN — push static/media to the edge so origin sees a fraction of traffic
Mini evolution (interview story)
- Walk this 60–90 second story before diving into APIs. It shows you can evolve a design instead of jumping to the final architecture.
- One VM runs web + DB — fine for hundreds of users
- Split web and DB; enlarge the DB (vertical) when queries slow down
- Add a second web server + load balancer; move sessions to Redis
- Add a read replica + cache for heavy read paths; keep one write primary
- Only if write QPS or data size breaks the primary — shard or pick a purpose-built store
Common anti-patterns
- These patterns look “scalable” on a whiteboard but fail in production or interviews.
- Scaling everything “just in case” instead of the measured hot path
- In-memory-only sessions on each app node
- Synchronous fan-out on the user request path
- One shared DB used as queue, cache, warehouse, and OLTP store
- Premature microservices before bottlenecks are understood
Interview framing
- Use this order when you open a scalability discussion.
- Clarify load — DAU, peak QPS, payload size, read/write ratio
- Propose the simplest architecture that meets today’s numbers
- Show the next step when load grows 10×
- Call out what does not scale yet and why that risk is acceptable
- Connect forward — LB, cache, shard, and queues solve specific scale problems
Quick revision checklist
- Always ask: “What is growing — QPS, storage, connections, or fan-out?”
- State vertical vs horizontal with one concrete example each.
- Mention cost and ops complexity — not only throughput.
- Connect to later topics: LB, caching, replication, sharding, queues.
- Use percentiles (p95/p99), not averages, when talking about pain.
- Draw before/after diagrams: 1 box → LB + N apps + shared DB/cache.
FAQs
Is horizontal always better?
No. It adds distributed complexity. Prefer vertical until a clear bottleneck, availability need, or cost curve forces scale-out.
Can databases scale horizontally?
Reads often scale with replicas and caches. Writes scale with partitioning/sharding or specialized stores, but cross-shard transactions get harder — say that trade-off out loud.
What should I scale first in a typical web app?
Usually the stateless app/API tier behind a load balancer, then caches for hot reads. Touch write-path sharding only after evidence the primary cannot keep up.
Does autoscaling equal scalability?
Autoscaling helps only if the workload can run on many identical nodes. If state is stuck on one machine or the DB is saturated, adding app pods will not fix latency.
How do I talk about scalability without cloud buzzwords?
Name the resource (CPU, I/O, connections), the growth metric (QPS/storage), and the mechanism (bigger box vs more boxes + shared store). Skip product names unless asked.
Where does caching fit vs scaling machines?
Caching reduces work per request so you need fewer machines. Scaling machines increases capacity to do the work. Strong designs often use both.
Learner’s Task
- Practice out loud for 8–10 minutes. Treat this like a mini interview whiteboard — speak, sketch, and justify each choice.
- Pick a product (URL shortener, news feed, or food-delivery tracking) and state peak QPS + read/write ratio.
- Draw Stage 1 (single box) and name the first bottleneck you expect when traffic grows 10×.
- Propose Stage 2–3 changes using only vertical scale, a load balancer, and a shared session/cache store.
- Label every new box as scaling reads, writes, or storage — remove any box you cannot justify.
- Write a 4-sentence closing: growth metric, bottleneck, next scale step, and one risk you accept for now.