Session or Database


General J2EE: Session or Database

  1. Session or Database (3 messages)

    Which is better to call server and retreieve values from database or to keep my values in session???

    Threaded Messages (3)

  2. The best answer is: "It depends"[ Go to top ]

    How much data are you going to be storing in the session/db? How long must those values persist? How sensetive is the data? What does the data represent? If the data represents a relation in the DB, thenI try to use the session as little as possible, but somtimes it is inevitable.

    If you are building an object over multiple pages and the database requires that the object is complete before you write it to the DB, then you have to use a session.

    If the data is not represented as a relation or and object in the system, the session is probably a good place for it.

    Sessions on different browsers behave differntly, so be carefull.
  3. The best answer is: "It depends"[ Go to top ]

    I personally never use the session.

    If you need to scale your system horizontally in the future then it is much easier to do if your system is stateless all the way to the database.

    I know most app servers support session replication, but I'nm not convinced this is as scalable as a stateless system.

    E-bay is an example of a high traffic site that doesn't use the session. (I read that somewhere)

    Ian Purton
    Website Uptime and Availability | Permission Email List Management | Sales Force Automation Solution | All Time Top 100 Rock Charts
  4. Session or Database[ Go to top ]

    Which is better to call server and retreieve values from database or to keep my values in session???

    I think this has two aspects. In an application one might want to store information related to the session of the user. ie. since the user login till he logs out or timed out. For such information storing in HTTP session might be useful.

    The other case is that one might want to store some application wide information, that do not change frequently since a system startup. For example, a currency or a conversion rate. Such information could be stored either in the database itself or an application-wide lookup table, typically a hashmap or hashtable to reduce the aceess time.

    But I also am aware that HTTP session behaves differently in different browsers and platforms. But I am not sure about this.

    Hope this helps.