A stateless service keeps no client-specific data in its own memory or on its local disk between requests.
Some data must survive after a request ends. Examples:
- sessions
- uploaded files
- caches that several instances must share
This data lives in a backing service, such as Redis, a database or object storage. Or it travels with each request as a signed token, like a JWT.
Why it matters for scaling: any instance can now serve any request. This means:
- The load balancer can use simple algorithms.
- You can add or remove instances freely. This is called autoscaling.
- A crashed instance loses nothing important. So deploys and failures do not log users out.
The Twelve-Factor App (a well-known set of rules for web apps) says it directly: processes are stateless and share nothing. Persistent data goes to a backing service.
- A stateless service keeps no per-client state in process memory or on local disk.
- Sessions live in Redis or a database, or in signed tokens.
- Any instance can serve any request.
- Statelessness enables autoscaling, safe restarts and simple load balancing.
Read more