What are the benefits of a stateless web application?

假装没事ソ 提交于 2019-12-03 03:08:00

问题


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?


回答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.




回答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.



来源:https://stackoverflow.com/questions/5539823/what-are-the-benefits-of-a-stateless-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!