Stateless Over Stateful Applications

Rachna Singhal
3 min readApr 8, 2019

--

The definition on Wikipedia says

A Stateless app is an application program that does not save client data generated in one session for use in the next session with that client.

A Stateful application saves data about each client session and uses that data the next time the client makes a request.

In other words, anything that reads or stores the information of its “State” to be used later is a stateful application. By State here I am referring to any condition that may change from one instance(session) to another. A very crude example of a Stateless application could be a calculator that always start with zero without storing the calculations or data from before. Similarly, your computer terminal is more of a Stateful application as it can store your previous ran commands and some data.

Stateful applications may not store all your information. The information it stores is based on the application and the conditions it needs or operates in.

Most applications that we might use in our day to day life are in some way Stateful apps. To put it mildly and in terms of web, any application that requires session or login is a stateful application as for each API call it would retrieve the user information to make computations.

A Stateful application needs a persistent storage for it to store its state and read later.

Why Stateless Applications?

Stateful applications were replaced by the modern Stateless application because Stateful applications left a lot of unanswered gaps like

  • A stateful application created a connection with the persistent storage to read and store the data. How long should that connection be open?
  • When dealing with sessions a lot of transactions happen at every request which needs to be maintained
  • How do we ensure that the connection is there or if it is disconnected?
  • How to maintain user’s data in cases of a network or storage failure?
  • In a Stateful application you are essentially saying that the client is dumb to store any information.

The answer to all these questions were provided by Stateless application which has now become the foundation of all software architecture of the new world.

Advantages of Statelessness

  • You can simply scale a stateless application by deploying it on multiple servers. Scales beautifully horizontally
  • Stateless apps can be cached easily and hence can be faster
  • Less storage
  • No need to bind the client to the server as in each request the client provides all its information necessary for the server to act upon it

Conclusion

Most software which are Micro-services are already Stateless applications using REST API design. Statelessness of application is the foundation on which most web and other concepts such as RESTful design are reliant on. A good understanding and advantage of Stateless over Stateful is very important in providing to the ever so demanding needs of the users nowadays.

--

--

Rachna Singhal

Programmer, Sports Enthusiast, Theatre Lover, Blogger, Traveller, bibliophile