Vertical Horizontal and Stateless Application Scaling

Scaling DNS and Load Balancing · 35 min

System Design · Module 5 · Lesson 1 of 4 · 35 min

Vertical Horizontal and Stateless Application Scaling

Identify the resource bottleneck, compare scaling up with adding instances, and remove private state that prevents safe request reassignment.

An additional instance helps only when requests can move to it and the constrained resource actually gains capacity.

01 The idea

The problem this lesson solves

Adding B causes intermittent logouts, while both app health checks stay green.

Prerequisite: earlier lessons introduce the vocabulary and shared examples used here. Follow the module order.

Vertical scalingIncreasing resources on an existing machine.
Horizontal scalingAdding machines or instances and distributing work.
Stateless request handlingHandling a request without relying on private durable history in one app process.

02 Worked example

Follow one worked example

Vertical Horizontal and Stateless Application Scaling worked diagram01App AReplaceable instance02App BReplaceable instance03Shared sessionTrusted identity state04Durable storeAccepted workVertical Horizontal and Stateless Application Scaling compact diagram01App AReplaceable instance02App BReplaceable instance03Shared sessionTrusted identity state04Durable storeAccepted work
App A: Replaceable instance • App B: Replaceable instance • Shared session: Trusted identity state • Durable store: Accepted work.

Trace the example in order. Follow the same identities, units and state transitions through the diagram and the events below.

1
Observe the symptomAdding B causes intermittent logouts, while both app health checks stay green.
2
Find private historyA stored the session only on its own disk.
3
Assign durable ownershipUse a designed shared session mechanism with expiry and authorization behavior.
4
Remove AA request reaching B now has enough trusted information to continue.

An additional instance helps only when requests can move to it and the constrained resource actually gains capacity.

03 The method

Mechanisms decisions and a guided tutorial

Work through the explanation in order, then apply it in the tutorial. Each comparison names a cost as well as a benefit.

Choice or conceptPurposeBoundary or cost
Vertical scalingLarger single machineResource ceiling and restart risk
Horizontal scalingMore instancesState, routing and failure coordination
Private durable stateEasy local accessBreaks reassignment
Replaceable local cacheFast readsCold instances increase origin load

Scale up or scale out

Vertical scaling gives one machine more resources. It can be a useful first move when one instance is undersized, but has hardware limits and may require disruption. Horizontal scaling adds instances and distributes work. It can improve capacity and fault tolerance, but creates coordination, routing and deployment complexity. Find the bottleneck first: adding app servers does not increase a saturated database's write capacity.

Move durable state out of app memory

If A keeps a login session only in its own memory, a request routed to B may appear logged out. Use a deliberately designed shared session store or verifiable tokens with appropriate expiry and revocation behavior. Durable uploads belong in shared storage, not one instance's disk. A local cache is acceptable when losing it causes a recoverable miss. Sticky sessions route a client back to an instance, but failure or rescheduling still exposes the private-state problem.

Scale the tier that is constrained

An app may be CPU-bound, waiting for a database, blocked on a lock or limited by a remote API. Adding app instances helps some of these cases and can worsen others. More callers can increase contention at the same saturated database. Start with where time and queues accumulate, then predict how the proposed change affects that resource.

Vertical scaling often preserves operational simplicity but has a ceiling and can require disruption. Horizontal scaling can add capacity and redundancy, but brings routing, deployment and state-ownership work. Neither choice is automatically more professional; the requirements and measured bottleneck determine the useful move.

Classify state by recoverability

In-flight request variables belong in memory. A local cache may also be private if losing it causes a recoverable miss. A login session, uploaded file or accepted business record that must survive reassignment needs a deliberate shared or durable home.

With local session files, a user can appear logged out when the next request reaches another healthy server. Sticky routing may hide the symptom until a restart or failover. A shared session store or verifiable token design addresses different trade-offs around revocation, expiry and availability; spell out that contract rather than call all state “stateless.”

Test reassignment before claiming elasticity

Start a request on A, route the next to B and remove A. The user action should still work under the stated contract. Also test uploads, background jobs and idempotency records: these are frequent private-state leaks.

An extra replica must be initialized and ready before receiving traffic. Warm necessary data gradually and ensure the shared cache and database can support the larger pool. A scaling event changes connection count and cache behavior even if the application code is unchanged.

Guided tutorial

1. List state

Inventory session data, uploads, local caches, jobs and accepted operations.

2. Label recovery

Mark each item as disposable, reconstructible or durable.

3. Move one request

Trace two requests from one user reaching different instances.

4. Identify the bottleneck

Choose a measurement that would justify app scaling instead of database work.

request state: private, short-lived
local cache: replaceable, misses are recoverable
session / accepted work: explicit shared or durable authority
upload: durable object storage or another shared contract
scale decision: measured bottleneck + surviving capacity

04 Cheat sheet

Review the decisions

Use this table to explain the mechanism and its limit without memorizing a product name.

Choice or conceptRememberCheck
Vertical scalingLarger single machineResource ceiling and restart risk
Horizontal scalingMore instancesState, routing and failure coordination
Private durable stateEasy local accessBreaks reassignment
Replaceable local cacheFast readsCold instances increase origin load
Vertical scalingIncreasing resources on an existing machine.
Horizontal scalingAdding machines or instances and distributing work.
Stateless request handlingHandling a request without relying on private durable history in one app process.

05 Where & why

Check the primary references

Use official references for protocol and implementation details. The questions here are teaching prompts.

Primary reference
NGINX HTTP load balancing

Read NGINX HTTP load balancing

Primary reference
DNS concepts

Read DNS concepts

Primary reference
Google SRE cascading failures

Read Google SRE cascading failures

State the implementation version and the workload assumptions when defending your own design.

06 Interview questions

Explain the reasoning out loud

Answer before opening the explanation. The questions progress from vocabulary to decisions and failure behavior.

What does Vertical scaling mean?
Increasing resources on an existing machine.
What does Horizontal scaling mean?
Adding machines or instances and distributing work.
What does Stateless request handling mean?
Handling a request without relying on private durable history in one app process.
Does stateless mean the process has no memory?
No. It uses request memory and can keep replaceable caches. Essential durable history must not be trapped in one eligible app instance.
Why can more instances hurt a database-bound service?
They can issue more concurrent work to the same constrained dependency, increasing queueing and contention.
Are sticky sessions a complete recovery plan?
No. They preserve affinity while the instance is available. Restart, failure or rescheduling still needs a state-recovery contract.
When is vertical scaling reasonable?
When a measured shortage can be relieved safely by a larger node and the simpler operational model is valuable. Assess its ceiling and failure risk.
What should a reassignment test include?
Authentication state, durable writes, uploads, retries and cold-cache behavior across different app instances.

07 Practice problems

Practice a new case

Solve the new cases before revealing hints. Complete worked solutions follow the set.

Choose the direction

Easy
Classify more CPU on one server and adding a second app instance.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Resource increase and instance increase differ.

Find the state

Easy
Explain why local session files cause intermittent logouts after a second app instance is added.
Follow-up
Both app processes can be healthy.
Show the hint
Follow the next request to a different instance.

Resource diagnosis

Medium
App CPU is low while database lock waits are high; explain why doubling app instances may not help.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Follow the queue.

State classification

Medium
Classify a request buffer, thumbnail cache and accepted export-job record.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Ask what must survive a restart.

Failover trace

Medium
A user uploads a file to A’s local disk then downloads through B; identify the missing contract.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
The file must be accessible after routing changes.

Scaling proposal

Hard
Propose an experiment to validate a horizontal-scaling claim for a read-heavy API.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Test the dependency behavior as the pool grows.

Worked solutions

1. Choose the direction

More CPU is vertical scaling; another instance with routing is horizontal scaling.

2. Find the state

The second instance cannot read the first instance's private session file. Store session state in a shared service or use a suitable verifiable-token design, with explicit expiry and revocation behavior.

3. Resource diagnosis

The constrained resource is coordinated database work. More app concurrency can amplify waiting; inspect the transaction/query pattern and bound demand first.

4. State classification

The buffer is transient; the thumbnail cache can be replaceable if regeneration is safe; an accepted job record needs durable ownership and recovery.

5. Failover trace

The upload needs a shared durable location or explicit ownership/routing and recovery design. A healthy second app cannot read A’s private disk automatically.

6. Scaling proposal

Measure latency, throughput, connection count, cache misses and database saturation at increasing app counts under the same workload. Include one-instance loss and cold starts before claiming the target is met.