Lesson 3 / 24
Statelessness
Why the server should never remember a client between requests.
Every request stands alone
In a stateless API, the server keeps no session data about the client between calls. Each request carries everything needed to understand it — an auth token, the resource id, any filters — so no request depends on server memory of a previous one.
A drive-through, not a waiter
A waiter remembers your table's order across the meal — stateful. A drive-through window has no memory of you; every car states its full order at the speaker. Stateless servers work the same way: any server instance can handle any request.
Why it matters at scale
Statelessness lets you add or remove servers behind a load balancer freely — no server holds client-specific data that would be lost on failover. It trades a little repeated data (like a token) for much simpler horizontal scaling.
Quick check: In a stateless REST API, where should the client's identity/auth info live?
- In server-side session memory
- Sent with every request (e.g. a token in headers)
- Stored in the database and looked up by IP
Answer
Sent with every request (e.g. a token in headers) — Statelessness means the server holds no per-client session; the request itself must carry the credentials needed to authenticate it.