Before diving into scaling, let us understand what state means in a service context.
State = any information a server remembers between requests.
| Stateful Service | Stateless Service | |
|---|---|---|
| Definition | Server remembers past requests | Server treats every request independently |
| Example | Server keeps your login session in memory | Server reads a token from your request to know who you are |
| Scaling | Hard β each server has different memory | Easy β any server can handle any request |
| Failure | If server crashes, state is lost | If server crashes, another server picks up with no data loss |
Think of a stateful service like a waiter who memorises your order in their head. If that waiter goes home sick, the next waiter has no idea what you ordered.
A stateless service is like a waiter who writes your order on a ticket. Any waiter can pick up the ticket and serve you β the information travels with the request, not with the server.