Skip to content
BENIBIX Learn

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.

Development🏗️ Architecture

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.

Example
Jack's shop runs five copies of its web app. Carts live in a shared cache, so the load balancer can send each click to any copy.
Why it matters
Stateless services grow by just adding copies. A crash loses nothing, because nothing lived there.
Full entry
Development🏗️ Architecture

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.

Example
Emma's chat server keeps each open chat in memory. When it restarts, every user in those chats is cut off and has to join again.
Why it matters
Some jobs need state, like databases and live games. Knowing which parts hold state tells you what needs backups and careful moves.
Full entry

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.