05 / 25 · Traffic and capacity
Horizontal scaling
Horizontal scaling adds more machines or application copies. Work must be shareable between them. It differs from auto scaling: horizontal describes the direction of growth; automatic describes how the decision is made.
What you will practise
- Separate scaling direction from automation
- identify serial work
- calculate scaling efficiency
Before you start: Replica, throughput and shared state.
About 4 minutes · offline-generated English female narration · captions included. Diagrams are conceptual; timings are illustrative.
Download MP4CaptionsListen without the video
Download audioChapters and full transcript
Let us understand horizontal scaling. A teacher asks three helpers to check homework instead of giving one helper a faster pen. This helps if papers can be divided. It does not help much if every paper must wait for one locked answer book. Shared resources and coordination decide whether more helpers actually increase throughput. Horizontal scaling adds more machines or application copies. Work must be shareable between them. It differs from auto scaling: horizontal describes the direction of growth; automatic describes how the decision is made.
Follow the normal path. One application serves event pages. Its safe measured capacity is finite, and a restart can interrupt every request reaching that copy. Deploy the same application on another machine or process. Horizontal scaling adds peers rather than increasing resources inside the original machine. SeatSpot can run several stateless event-page replicas during a sale. A user may reach a different copy on the next request, so login state, uploaded files and reservations cannot silently live only in one replica memory.
Now change one condition. Routing sends requests to ready replicas. Balance according to workload characteristics; more boxes are useful only when requests can reach them. A common misunderstanding is this: More app copies automatically scale database writes. The write owner, locks and connection limits can still constrain throughput. Think about this. Four copies reach 250 requests/second when one reaches 100. Did capacity grow four times? Pause the video and make your prediction. No. The measured efficiency is 62.5% of the ideal 400. Investigate the shared bottleneck before adding more replicas.
Let us reason with a concrete example. One replica safely serves 100 requests/second. A load test with four replicas reaches only 250. Ideal linear scaling would suggest 400, but the measured efficiency is 250/400 = 62.5%. This number describes the experiment, not a universal law. Investigate database locking, shared CPU, connection limits and the serial part before adding another four replicas. Re-test after each change. These figures are teaching examples, not production guarantees.
Turn the idea into a design decision. Both replicas use the same appropriate storage for files, sessions or records. A file written only to Replica A will not magically appear on Replica B. If every request waits on one locked database operation, extra applications may add waiting instead of throughput. Trace and load-test the complete path. When you try the practice task, look for this result. A gap from ideal scaling is a diagnostic clue, not proof which dependency is slow.
Check your understanding. Compare throughput and tail latency before and after scaling. Also remove one replica to check that remaining copies serve users correctly with available capacity. Here is a challenge. An upload is saved to App A local disk. The next download request reaches App B. Propose a fix. Pause before the answer. Store the file in a shared durable object store and keep metadata/access rules in an authoritative store. Stream or redirect authorized downloads from that shared location. Do not depend on sticky sessions for durability. For an interview, discuss state, job ownership, database limits and real load tests. Say what you would measure, not only which tool you would buy.
Start with an everyday picture
A teacher asks three helpers to check homework instead of giving one helper a faster pen. This helps if papers can be divided. It does not help much if every paper must wait for one locked answer book. Shared resources and coordination decide whether more helpers actually increase throughput.
Why SeatSpot needs this
SeatSpot can run several stateless event-page replicas during a sale. A user may reach a different copy on the next request, so login state, uploaded files and reservations cannot silently live only in one replica memory.
Trace one step at a time
Move through the diagram at your pace. Teal paths are active; unavailable components are labelled.
Start with one copy
One application serves event pages. Its safe measured capacity is finite, and a restart can interrupt every request reaching that copy.
Read all six mechanism steps
Start with one copy
One application serves event pages. Its safe measured capacity is finite, and a restart can interrupt every request reaching that copy.
Add another copy
Deploy the same application on another machine or process. Horizontal scaling adds peers rather than increasing resources inside the original machine.
Share incoming work
Routing sends requests to ready replicas. Balance according to workload characteristics; more boxes are useful only when requests can reach them.
Move durable state
Both replicas use the same appropriate storage for files, sessions or records. A file written only to Replica A will not magically appear on Replica B.
Find serial work
If every request waits on one locked database operation, extra applications may add waiting instead of throughput. Trace and load-test the complete path.
Test the gain
Compare throughput and tail latency before and after scaling. Also remove one replica to check that remaining copies serve users correctly with available capacity.
Pause and make a prediction
Four copies reach 250 requests/second when one reaches 100. Did capacity grow four times?
Correct a common misunderstanding
Claim to question: More app copies automatically scale database writes.
Better explanation: The write owner, locks and connection limits can still constrain throughput.
Compare ideal and measured growth
- Write the measured single-copy throughput.
- Multiply by four for the ideal reference.
- Compare the real result and name three shared constraints.
Check what you can explain
This is your self-check, not an automated grade. Try again without the diagram tomorrow.
0 of 3 goals checked. Choose one remaining idea to practise next.
Teach it back
Without looking, explain what this component changes, what it does not solve and what happens if it fails. Use the animation to check your explanation, then switch to Engineering.
Engineering model and trade-offs
Separate process-local temporary state from durable shared state. Use a suitable session/token design and shared storage where necessary. Sticky sessions can reduce movement but do not preserve a lost server or make state replication automatic.
Parallel throughput is limited by serial work, locks, downstream quotas and coordination overhead. Measure the actual request mix. Scaling application reads does not automatically scale the primary database write path.
Plan node/zone distribution, load balancing and instance identity. Background jobs need safe work ownership; duplicate consumers must not perform the same side effect twice. More replicas also mean more connections and observability data.
Work through an example
One replica safely serves 100 requests/second. A load test with four replicas reaches only 250.
Reason with the numbers
Ideal linear scaling would suggest 400, but the measured efficiency is 250/400 = 62.5%. This number describes the experiment, not a universal law.
Make a decision
Investigate database locking, shared CPU, connection limits and the serial part before adding another four replicas. Re-test after each change.
Implementation sketch
# In a configured test Kubernetes cluster:
kubectl scale deployment/seatspot --replicas=4
kubectl get pods -l app=seatspot
# Verify readiness and run a controlled load test.The scale command changes desired application replicas. It does not configure load balancing, storage, a cluster autoscaler or database capacity. An HPA may own this value in an automatically scaled deployment.
Where this is used
- Stateless request processing and parallelizable jobs.
- Distributing work and failure exposure across machines.
Common mistakes
- Assuming four replicas always give four times throughput.
- Keeping sessions/files only on local ephemeral disk.
- Ignoring extra downstream connections from each copy.
Practise a reasoned answer
Answer aloud or write notes before opening the reference. These prompts teach reasoning and trade-offs; they are not claimed questions from a particular company.
What must change before scaling a stateful web process horizontally?
Choose a practice depth
- Foundation
- Describe adding copies and sharing work.
- Practical
- Discuss state, job ownership, database limits and real load tests.
- Advanced
- Defend bottleneck measurements, coordination overhead and the cost of another replica.
Self-check rubric
- State the required user outcome and the relevant invariant.
- Explain the normal path and one failure path.
- Name a cost or consistency/latency trade-off.
- Say what you would measure or test before trusting it.
For deeper practice, connect this topic to the previous lesson and identify a shared bottleneck. A longer answer is not automatically a better answer.
Try it before viewing the solution
An upload is saved to App A local disk. The next download request reaches App B. Propose a fix.
Check one key idea
Your explanation and interview notes
Saved only in this browser when storage is available. Export a backup from the course page before clearing browser data or moving devices.
Loading your local notes…
Official references and next reading
The explanation, fictional examples and animations are original teaching material. Vendor behavior depends on the specific product/version; use its documentation before deploying.