🪶 System Design · System Building Blocks
Stateless Design
A server does not depend on local memory from a previous request.
Stateless services are easier to distribute across multiple servers.
Any server can process the next API request because session state is stored appropriately.
💡 Like a hotel where any front-desk clerk can help you, because your booking is in the system, not in one clerk's head.
💡 Why it matters
If a server remembers a user only in its own memory, that user breaks the moment a load balancer sends them elsewhere. Stateless servers are interchangeable, so you can add, remove or restart them freely. This is what makes scaling out and recovering from failures smooth instead of painful.
🛠️ How to achieve it
⚠️ Signs of trouble
- •A user breaks when sent to a different server.
- •Restarting a server logs everyone out.
- •Sessions are kept only in one server's memory.
- •You cannot add servers without special sticky routing.
🎯 Quick check
Score: 0/3Three questions to test the idea.
1. What makes a server stateless?
Answer: It keeps no per-user memory between requests
A stateless server relies on shared storage, so it remembers nothing private between requests.
2. Why does stateless design help scaling?
Answer: Any server can handle any request, so you can add or remove servers freely
Interchangeable servers let a load balancer spread traffic and let you scale out smoothly.
3. Where should session state live in a stateless design?
Answer: In a shared store like a database or cache
Shared storage lets every server read the same session, so no user is tied to one machine.
