Why keep application servers stateless?
Options
- To save disk space on every application server
- Any instance can serve any request (easy scaling) (Correct option)
- Stateless servers are faster for CPU-heavy work
- To avoid using a database anywhere in the system
Answer
Any instance can handle any request, enabling autoscaling and easy failover; session state lives in a shared store or token
Why
If a server keeps user data in its own memory (like a login session), that user must always hit the same server, and if it restarts, the data is lost.
Stateless servers keep nothing between requests: sessions go to Redis or a signed token, files go to object storage (S3).
Then any server can handle any request, and you can add or remove servers freely.
Remember
Keep state out of app servers.