
Stateful versus stateless
Every meaningful business application creates, modifies, or uses data. Data is also called state. An application service that creates or modifies persistent data is called a stateful component. Typical stateful components are database services or services that create files. On the other hand, application components that do not create or modify persistent data are called stateless components.
In a distributed application architecture, stateless components are much simpler to handle than stateful components. Stateless components can be easily scaled up and scaled down. They can also be quickly and painlessly torn down and restarted on a completely different node of the cluster—all this because they have no persistent data associated with them.
Given that fact, it is helpful to design a system in a way that most of the application services are stateless. It is best to push all the stateful components to the boundary of the application and limit their number. Managing stateful components is hard.