🏗️ Microservices Architecture
Beginner
What is a stateless service and why is it preferred in microservices?
Answer
A stateless service does not store any client session data or in-memory state between requests. Every request contains all the information needed to process it, and any persistent data is stored in an external store (database, cache, object storage). Stateless services are strongly preferred in microservices because they are trivially horizontally scalable — you can add or remove instances freely because any instance can handle any request. Load balancers can route to any instance without sticky sessions. Deployments and restarts are seamless because there is no state to preserve or migrate. Authentication state, for example, is typically stored in a JWT token (sent with each request) rather than in server-side session memory.