The Artima Developer Community
Sponsored Link

Java Buzz Forum
Sessions, a Pitfall.

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
gregor riegler

Posts: 38
Nickname: nautic
Registered: Mar, 2013

gregor riegler is a passionate developer and techlead for fluidtime data services gmbh
Sessions, a Pitfall. Posted: Nov 28, 2013 2:29 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by gregor riegler.
Original Post: Sessions, a Pitfall.
Feed Title: Be a better Developer
Feed URL: http://www.beabetterdeveloper.com/feeds/posts/default
Feed Description: This Blog Provides Information and Guides for "Clean Programming" and "Best Practices" in Software Development with a focus on Java
Latest Java Buzz Posts
Latest Java Buzz Posts by gregor riegler
Latest Posts From Be a better Developer

Advertisement
I got asked quite often, why one shouldn't use sessions and whats so bad about them. In this post i want to sum up my thoughts and experiences.


Sessions produce unnecessary complexity

The term bugfoot is a combination of bug and bigfoot. It's used for a bug that appears only once and is not reproducable. A bugfoot tells you that something is wrong, and that it will probably come up again. But you cannot fix it, because you don't know the cause.

If you want bugfoots in your software, just use sessions. Sooner or later you'll happen to see one.

Sessions don't scale

Lets say you are a professional chess player, and you'd like to play multiple people at the same time. If you'd try to remember every game and your strategy on it, you'll hit your capacity rather quick. Now imagine you were not remembering anything of those games, and you were just rereading the chessboard on every move. You could literally play 1.000.000 people at the same time, and it wouldn't make any difference to you.

Now draw an analogy to your server. If your application gets a lot of load, you might have to distribute it to different servers. If you were using sessions, you'd suddenly had to replicate all sessions to all servers. The system would become even more complex and error prone.

Sessionstate cannot be bookmarkable nor cachable

Did you try to bookmark your shopping cart? Nah, of course you can't because it's empty as soon as the session ran out. Imagine a shop that actually allowed you to bookmark your cart. Like
  • http://example.com/carts/1337 or
  • http://example.com/cart?products=[{id:1, amount: 1}]
How wonderful that would be

Conclusion

You want a simple system that is easy to test and whose bugs are easy to reproduce. State leads to the opposite. HTTP was never ever ment to be stateful and it should have stayed this way.

If you want some rest, follow these two rules
  • Keep all application state (not resource state) on the client
  • Keep all shared state (not session state) on the server

Read: Sessions, a Pitfall.

Topic: Exploit better the results of Pmd, Findbugs and CheckStyle. Previous Topic   Next Topic Topic: 21 signs of BAD MANAGERS I met in my career as a software manager

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use