Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of a stateless web application?

It seems some web architects aim to have a stateless web application. Does that mean basically not storing user sessions? Or is there more to it?

If it is just the user session storing, what is the benefit of not doing that?

like image 731
Genadinik Avatar asked Apr 04 '11 14:04

Genadinik


People also ask

Why stateless is better than stateful?

The Stateless protocol design simplify the server design. The Stateful protocol design makes the design of server very complex and heavy. Stateless Protocols works better at the time of crash because there is no state that must be restored, a failed server can simply restart after a crash.

What is a stateless web application?

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. Each session is carried out as if it was the first time and responses are not dependent upon data from a previous session.

What is the advantage of stateless Web service design?

Advantages of StatelessnessWeb services can treat each method request independently. Web services need not maintain the client's previous interactions. It simplifies the application design. As HTTP is itself a statelessness protocol, RESTful Web Services work seamlessly with the HTTP protocols.

What are is the advantages of statelessness?

The following are some advantages of statelessness: As the server does not need to manage any session, deploying the services to any number of servers is possible, and so scalability will never be a problem. No states equals less complexity; no session (state) synchronize logic to handle at the server side.


2 Answers

  1. Reduces memory usage. Imagine if google stored session information about every one of their users
  2. Easier to support server farms. If you need session data and you have more than 1 server, you need a way to sync that session data across servers. Normally this is done using a database.
  3. Reduce session expiration problems. Sometimes expiring sessions cause issues that are hard to find and test for. Sessionless applications don't suffer from these.
  4. Url linkability. Some sites store the ID of what the user is looking at in the sessions. This makes it impossible for users to simply copy and paste the URL or send it to friends.

NOTE: session data is really cached data. This is what it should be used for. If you have an expensive query which is going to be reused, then save it into session. Just remember that you cannot assume it will be there when you try and get it later. Always check if it exists before retrieving.

like image 70
tster Avatar answered Oct 02 '22 16:10

tster


From a developer's perspective, statelessness can help make an application more maintainable and easier to work with. If I know a website I'm working on is stateless, I need not worry about things being correctly initialized in the session before loading a particular page.

From a user's perspective, statelessness allows resources to be linkable. If a page is stateless, then when I link a friend to that page, I know that they'll see what I'm seeing.

From the scaling and performance perspective, see tsters answer.

like image 24
Jamie Wong Avatar answered Oct 02 '22 15:10

Jamie Wong