Stateful vs Stateless

Md. Zahid Fesabelilla
2 min readNov 4, 2023

--

Stateful: In a stateful request, the server remembers the context or state of previous interactions with the same client, and this context is used to process subsequent requests.

Stateful requests are common in scenarios where maintaining continuity and context is important.

For example, Online Gaming, Chat Applications, Collaboration software like Google Docs etc.

Suppose we have a stateful application and we want to scale it horizontally and we introduce a load balancer for auto scaling. Due to the stateful application if user sign in to the one server then the load balancer moves the user’s request to another server, and then the user must need to log in again. It’s horriable user experience…. Right ?
Now the question is why it’s happen ?
The answer is the type of our application it’s a stateful application and it maintains its state in a server. If the server is changed then it initilize new state again.

So how we can solve it?
We need one extra level of complexity here. We need to store the states and both servers are sharing the states from here. For that we can use Redis or Memcached for storing the state.

Stateless: Every request or operation is considered in isolation, and the system does not retain any information about previous requests or transactions. Each request is self-contained and does not rely on historical context.

Stateless systems typically do not maintain session state. In web applications, this means that the server doesn’t store information about a user’s previous actions or maintain their session data between HTTP requests. Instead of that they maintain communication using tokens. Each request is responsible for sending the token. When the request is sent to the server it will take the token and it has to query the database to verify whether the token is valid or not. Usually, tokens have also some expiration time.

Stateless systems are often more scalable because they don’t require the storage and management of session data or context information between requests. This simplicity can make it easier to distribute requests across multiple servers or nodes in a network.

For exampls, Http(Hypertext Transfer Protocol) requests, REST(Representatiponal State Transfer)

In stateless we can easily scale our system horizontally. In that system, we need extra calls in the database. To solve that issue stateless architecture needs a different level of caching to reduce the database call.

--

--

Md. Zahid Fesabelilla
Md. Zahid Fesabelilla

Written by Md. Zahid Fesabelilla

Software Engineer at Rokomari.com | Largest online books selling company in Bangladesh 🇧🇩| Love to analyse, design and develop software| Problem Solver

No responses yet