Stateless Service vs Stateful Service
People think a stateless service keeps no data, and that is not quite right. It keeps none inside itself between requests. The cart or the login lives in a shared store, so any copy can answer. A stateful service keeps that data in its own memory or disk. Each request must reach the one copy that has it.
Stateless Service
A service that keeps nothing between calls. So any copy can answer.
A stateless service keeps no memory of past requests inside itself. Each request carries all it needs, like a login token. Anything that must last, such as a cart, is saved in a database or cache outside the service. So any copy of the service can answer any request. That makes it easy to add copies, or to replace one that crashes.
Stateful Service
A service that keeps data between calls. So the right copy must answer.
A stateful service keeps data from past requests inside itself and needs it for the next one. A game server holds each match in memory. A database holds its rows on its own disk. Requests for that data must reach the copy that holds it. That makes the service harder to grow, move or restart than a stateless one.
In one line
- Stateless Service
- A service that keeps nothing between calls. So any copy can answer.
- Stateful Service
- A service that keeps data between calls. So the right copy must answer.