System Design Academy

Saving…

Lesson 4 of 8 in Module 20 of 54 lessons complete

Horizontal Scaling & Stateless Services

Module 2, lesson 4Concept10 min

Definition

Horizontal scaling

In plain English
Horizontal scaling means adding more machines that share the work.
Think of it like
It is like opening more checkout lanes instead of hiring one super-fast cashier.

Stateless service

In plain English
A stateless service keeps no user-specific memory between requests, so any copy can handle any request.
Think of it like
It is like a bank where any teller can help you because your details live in the shared system, not in one teller's head.

Session

In plain English
A session is the information a server keeps about a user between requests, such as who is logged in or what is in their basket.
Think of it like
Like a cloakroom ticket and the coat it belongs to.

Load balancer

In plain English
A load balancer receives incoming requests and spreads them across several servers.
Think of it like
It is like a restaurant host who seats each new group at a table with room.

Why it exists

Your ticket sale needs forty browsing servers at 10 am. One larger machine is no longer enough.

A basket stored only on Server A disappears from view when your next request reaches Server B. More servers need shared user data.

How it works

Sticky sessions

In plain English
Sticky sessions send each user back to the same server every time.
Think of it like
Like always being sent to the one cashier who remembers your order.

Autoscaling

In plain English
Autoscaling automatically adds or removes servers as traffic rises and falls.
Think of it like
Like a supermarket opening extra lanes when queues grow.

Shared store

In plain English
A shared store holds data outside application servers so every application copy can read it.
Think of it like
It is like a shared notebook that every cashier consults.
  1. Move sessions

    Put session data in a shared store that every server reaches.

  2. Make copies identical

    Run the same application on every server.

  3. Route requests

    Put the copies behind a load balancer.

  4. Adjust capacity

    Add or remove copies as demand changes.

Users reach a load balancer. It routes to servers A, B or C, which all access one shared session store.

Every application copy uses the same session data.

Users reach a load balancer. It routes to servers A, B or C, which all access one shared session store.

QuestionSession in one serverStateless application server
Where does the session live?Local memoryShared store
Can any copy answer?Only the copy with the sessionYes, while the shared store works
What happens when a copy dies?Its local session is lostAnother copy reads the saved session

Examples

Turn browsing capacity up

Browsing servers grow from four to forty when the sale opens at 10 am. Every basket lives in a shared store.

Any healthy browsing server retrieves your basket. Add servers before the rush so startup time does not delay customers.

  • Measure peak browsing traffic.
  • Keep basket data outside disposable application copies.

The insight

Shared sessions let you adjust application capacity without moving each user.

Trade-offs

Pros

  • Grow beyond one machine’s capacity.
  • Keep serving after an application copy fails.
  • Adjust copies with demand.

Cons

  • Shared user data needs careful storage.
  • More machines require more management.
  • Connections still belong to individual servers.

Use when

  • Use for web servers with variable traffic.
  • Use when identical copies handle requests independently.

Avoid when

  • Avoid extra copies for tiny workloads without a reliability need.
  • Avoid splitting a strictly ordered stream without a plan.

Quick check

Why must servers be stateless before you can add more freely?
Where does session data go in a stateless design?

Takeaways

  • Horizontal scaling means more machines sharing the work.
  • Stateless application servers keep sessions in a shared store.
  • That shared store needs protection too.

Try the quick check above whenever you feel ready.

Previous: Vertical Scaling