Statelessness
Definition
A communication protocol or application architecture where each request from a client is treated as an independent transaction that contains all the information needed to complete it, without relying on session context stored on the server.
What Problem It Solves
Statelessness solves the scalability limits of session-bound servers. By requiring every request to contain all the context and credentials needed for execution, it allows requests to be distributed to any available server, facilitating effortless horizontal scaling and load balancing.
What Happens If Not Used
Without stateless design, web servers quickly run out of memory trying to store active user sessions. Additionally, if a specific server crashes, all users routed to that server lose their active sessions, preventing high availability.
Easy Wording
A system that has no memory of the past. Every time you talk to it, it is like meeting a stranger for the first time, so you must explain everything they need to know in that single request.
Layman Example
A vending machine. It doesn't care who you are, what your name is, or what you bought yesterday. It only cares about the coins you insert right now and the button you press right now.
Technical Example
A RESTful API endpoint using JWT for authorization:
app.get('/api/dashboard', verifyToken, (req, res) => {
// The server does not store session state in memory.
// It receives everything it needs to know in the Authorization header.
const userId = req.user.id;
res.json({ data: getUserDashboard(userId) });
});