DEV Community

Hardik Shah
Hardik Shah

Posted on

5 1

Stateless vs Stateful - Which direction should you take?

Scaling a web app is hard, for it always comes with uncertainties and failures. Even a minor fault can break an application if it’s not built for scalability.

In traditional web development, however, one thing that might help a website scale is –– everything being stateless. Here Statelessness means that the server should not remember the application’s state. Instead, the client should remember all the information necessary for the execution with each request as the server can’t memorize and reuse information from previous requests.

Whenever you have to fetch a few things from a database, you receive a request containing everything you need to know. On answering that request, you don’t care about the client until you receive a new request. This makes work so easy; so convenient to execute as you are ensuring a clean state every time.

In traditional application development, however, everything for a fact is stateful. Things are stored in memory, which gives you a sigh of relief that they will continue to remain there until the app is closed; or unless it is reopened. You are not expected to maintain state across sessions; not forced to think that things can be missed out.

Enter Modern Complex Web apps

Modern web apps, on the contrary, sits in between statelessness and statefulness. Here, your server remains stateless and the frontend is stateful.

Think about a web app such as Trello or Canva where every URL points to a single page. Once you reload the page, all elements must be re-fetched from the server, maintaining the state on the server.

So, how do you decide whether the stateless or stateful approach would help you out?

The Answer is…

Until and unless you need a reason to store a state, going Stateless might help. One thing, however, you need to make sure is to think about the situation where maintaining a state is necessary.

Hugh Mckee, the developer advocate at Lightbend, urges to look into specific circumstances while choosing between Stateless or Stateful approach.

In his blog “How to build successful cloud-native solutions”, Hugh demonstrates the scaling capability of stateful applications by illustrating a shopping cart example.

Hugh concludes his opinion on stateless vs stateful debate with the following quote,

Alt Text

Need help in building complex web apps that scale, you can refer to these scalability tips shared by 25+ experts.

What is your opinion regarding stateful vs stateless debate? I would really love to know in the comments.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay