What are the benefits of a stateless web application?

16,750

Solution 1

  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.

Solution 2

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.

Share:
16,750
Genadinik
Author by

Genadinik

Thank you to everyone who has helped me. I am extremely appreciative of the amazing people on StackOverflow who have helped me :) I currently run https://www.problemio.com under which I offer mobile apps, books, coaching, and online courses, and even a B2B course licensing business: https://www.problemio.com/udemy/white-labeling-or-buying-udemy-courses.html I also run a funny t-shirt store: https://www.waveifyoulike.com

Updated on July 08, 2022

Comments

  • Genadinik
    Genadinik almost 2 years

    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?

  • tster
    tster about 13 years
    +1 for the linkable thing. That's actually one of my top reasons for not using session data. I'll add it to my answer.
  • Genadinik
    Genadinik about 13 years
    One more question: if an application is indeed stateless - is it then impossible to monitor if users are logged in and do authentication?
  • tster
    tster about 13 years
    @Genadinik, No, you can log user's last access to the site which is all a Session based site can do to. It's not like session run sites maintain some connection with the user's browser.
  • JaskeyLam
    JaskeyLam over 9 years
    @tster, so even though I store the session/user state in memcache, the application is not considered stateless? The state must be held in clinet?!
  • tster
    tster over 9 years
    @Jaskey, I never said state should be held in the client. If you are using this as a cache for your user's requests, that is different than if you are storing "user state". "User state" I think of as data which "if I lose this data my application will lose functionality", vs "cache data" which is "If I lose this data my application will lose performance"
  • dardawk
    dardawk almost 7 years
    Not all stateless applications are linkable. You can have an SPA front-end (without proper routing) and be completely stateless on the server side, but the session state is kept in javascript. IE, In this case, you can't share the URL and ensure your friend sees the same thing, but the web app would still be considered stateless.