Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am asking this question in continuation with http-session-or-database-approach.

I am planning to follow this approach.

  1. When user add product to cart, create a Cart Model, add items to cart and save to DB.
  2. Convert Cart model to cart data and save it to HTTP session.
  3. Any update/ edit update underlying cart in DB and update data snap shot in Session.
  4. When user click on view cart page, just pick cart data from Session and display to customer.

I have following queries regarding HTTP Session

  • How good is it to store large data (Shopping Cart) in Session?
  • How scalable this approach can be ? (With respect to Session)
  • Won't my application going to eat and demand a lot of memory?
  • Is my approach is fine or do i need to consider other points while designing this?

Though, we can control what all cart data should be stored in the Session, but still we need to have certain information in cart data being stored in session?

share|improve this question
4  
Could you specify what exactly you mean with “saving to HTTP session”? Cookies, local storage in the browser, your database, or something completely different? –  amon Oct 17 at 19:10
1  
I believe that typically one uses a cache (ehcache for example) between the database and the server. The cache tends to be a bit more intelligent with fetching and storing data rather than trying to put it all in the session. –  MichaelT Oct 17 at 19:33
 
@amon: generally session data is stored as heap size allocated to JVM.Though container can write session data to disk, but only when low in memory. –  Umesh Awasthi Oct 18 at 2:17
 
@MichaelT: That is one of option i was thinking of, but have to cross check it. –  Umesh Awasthi Oct 18 at 2:18

1 Answer

I think the general pattern is try to store the least information possible in memory, only store the useful data only. This approach would make your application scalable.

If you really want an scalable application, you should build it on an app server, like JBoss/Wildfly or any other Java EE Container.

Design considerations in Java EE is to keep session beans as light as possible.

share|improve this answer
 
I can not bind my application design to specific app server :( –  Umesh Awasthi Oct 18 at 17:27
 
@UmeshAwasthi It will work in every Java EE container theoretically. –  jacktrades Oct 18 at 17:28
 
@UmeshAwasthi anyhow, if you want to go for scalable, don't store too much in session objects. –  jacktrades Oct 18 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.