Stateless vs Stateful Applicationsby Iwan Price-Evans on Scalability • June 23, 2022
Within the context of application delivery, the term 'state' refers to an application's condition at any given point in time. This condition may have been derived from user interaction, internal processing, or any other application function or process.
State can be used to maintain application conditions such as authentication sessions, interaction history, user preferences, and other interaction processes.
Applications are often described as being Stateful or Stateless, but what do these terms mean?
What are Stateful applications?
A Stateful application saves client session data to be used the next time the user needs it. This means that the state of the application is recorded. Stateful applications may want to keep track of user activity such as recent files, open windows, open tabs, or updated user preferences. Recording this information can enable application functionality to be made available even when offline.
When keeping track of state, stateful applications must use dynamic databases to maintain persistent data so it can be read later. This is how a stateful application would recover from a restart. It needs the persistent database to know which point to recover at. It's important to note that stateless applications may not fully recover a session after a failure. An application crash may require the user to log in again and start from scratch.
Stateful applications are typically complex and hard to scale.
- When a session state is stored on a server, the client and server must maintain their connection.
- Designing applications to rely on these client and server pairs makes them inherently difficult to scale.
- When scaling these applications, it's necessary to maintain the user sessions across multiple servers and ensure that each specific user request is connecting to the same server.
What are Stateless applications?
Stateless applications process code and content and don't record data. They don't keep track of information created during one user session to make it available to the user in subsequent sessions.
Even though an application may be stateless, it still needs to keep track of state somehow. This is done by the application relying on the client to maintain user sessions.
A server hosting a stateless application will process state information relayed to it and will have no internal record of that state. It doesn't require persistent databases to maintain the user's session state.
Stateless applications are typically simple and scalable.
- Stateless applications typically handle ephemeral state data. This architecture allows the state of applications to be transitory and this means that application design and implementation are simpler than in stateful apps.
- Stateless applications are suited to modern cloud architectures such as containers which can handle errors and failover to a completely new server instance.