I have always advocated the stateless web, but would like to know what the advocates of the stateful web are saying.
Do you have any situation where stateful is more appropriate than stateless?
Join Stack Overflow to learn, share knowledge, and build your career.
I have always advocated the stateless web, but would like to know what the advocates of the stateful web are saying.
Do you have any situation where stateful is more appropriate than stateless?
Our project uses the Wicket web framework, which allows stateful or stateless interaction. Stateful pages have a number of advantages:
Anything that's possible in a stateful application could also be implemented as stateless - you simply have to store the state on the client, and submit all relevant state information on every request.
Link to wicket: http://wicket.apache.org/
Using states generally makes the programmer's job easier.
However, states also introduce all sorts of concurrency issues that are simply not present in stateless situations.
This is essentially the debate between functional and imperative programming.
I'm in the statefull client-stateless server camp due to scaleability but when facing the hurdles of explaining why this and that became harder to implement using a stateless server, you get kind of resigned in the long run, this is where stateful server shines:). Eventhough I prefer statefull client this is not easy to implement efficiently using asp.net viewstate and perhaps this is where statefull web gets practical. I think statefull client, stateless server makes you more aware of the amount of data that is transported back and forth between tires. That is sometimes hidden until trouble occures using statefull server programming model. Also, going from stateless to statefull is easy (just ignore state info that you are providing since you already know it.. ). Going the opposite is almost impossible/not worth it. Another thing using a statefull server is that clearing state/cache is often a problem when you are using also a statefull client. It's just unintuitive and confusing, or maby just I am :)
Anyhow GWT and many other modern toolkits (Silverlight talking to WCF) seems to prefer stateful client, stateless server due to scaleability issues. Maybe stateful server should be the exception to the stateless rule ... one could choose per page/window.
Stateless web applications are essential when you start having higher traffic.
There could be plenty of user data that you don't want to store on the client side for security reasons for example. In this case you need to store it server-side. You could use the web applications default session but if you have more than one instance of the application you will need to make sure that each user is always directed to the same instance.
Load balancers often have the ability to have 'sticky sessions' where the load balancer some how knows which server to send the users request to. This is not ideal though, for example it means every time you restart your web application, all connected users will lose their session.
A better approach is to store the session behind the web servers in some sort of data store, these days there are loads of great nosql products available for this (redis, mongo, elasticsearch, memcached). This way the web servers are stateless but you still have state server-side and the availability of this state can be managed by choosing the right datastore setup. These data stores usually have great redundancy so it should almost always be possible to make changes to your web application and even the data store without impacting the users.
Things like long forms (and really anything that takes more than one page refresh) are much easier with persistent state, since you can actually keep track of what page/stage the user is on in an easy and straight-forward way. However, I personally don't think such a small advantage is worth it, but it greatly depends on the web application in question.