What Makes a Service Stateful
What you'll learn: How to identify services that store session or connection information between client requests.
The Core Idea
A stateful service keeps track of client-specific information on the server between requests. Unlike stateless services that treat every request independently, stateful services "remember" previous interactions with a particular client.
Think of a stateful service like a personal shopper who remembers your shopping cart as you walk through a store. They keep mental notes about what you've selected, your preferences, and your conversation history. If you left and came back with a different personal shopper, you'd have to start over.
What Makes It Stateful?
A service is stateful when it:
- Stores session data in the server's memory (user preferences, authentication tokens, shopping cart contents)
- Maintains open connections that preserve state (WebSocket connections, database transactions)
- Requires requests from the same client to hit the same server instance
- Cannot easily swap servers mid-session without losing or transferring state
Common Examples
- Chat applications maintaining active WebSocket connections
- Shopping carts stored in server memory
- Game servers tracking player positions and actions
- Video streaming services managing active playback sessions
The Scaling Challenge
Stateful services complicate horizontal scaling. If a client's state lives on Server A, routing that client to Server B breaks their experience. You need "sticky sessions" (routing the same client to the same server) or external state storage, both adding complexity we avoided with stateless designs.
Key Takeaway: A service is stateful when it maintains client-specific data or connections on the server between requests, requiring clients to return to the same server instance or introducing complexity to share state across servers.