← Lessons

quiz vs the machine

Gold1390

System Design

Stateless vs Stateful Services

Whether a server remembers a client between requests or starts fresh every time.

5 min read · core · beat Gold to climb

What state means here

A stateless service keeps no client specific memory between requests. Every request carries everything needed, so any instance can handle any request. A stateful service holds session data in memory, so a client must keep talking to the same instance.

Why stateless scales easily

  • Any request can go to any instance, so a load balancer can spread traffic freely.
  • Adding or removing instances is trivial because nothing is lost when one dies.
  • Recovery is simple since there is no in memory state to rebuild.

State still exists, it just lives in a shared store like a database or cache rather than inside the service.

Why stateful is sometimes needed

  • Holding a live connection, a game session, or a streaming buffer in memory avoids fetching state on every request.
  • The cost is sticky routing, harder failover, and rebalancing when instances change.

A common pattern keeps services stateless and pushes durable state into a shared store, reserving statefulness for genuinely connection bound workloads.

Key idea

Stateless services let any instance serve any request for easy scaling while stateful services hold session memory and need sticky routing.

Check yourself

Answer to earn rating on the learn ladder.

1. Why do stateless services scale more easily?

2. Where does a stateless service keep durable state?