Shopping Cart - database vs session

  • Thread starter Thread starter Paul Hobbs
  • Start date Start date
P

Paul Hobbs

Hi All,

I am developing a site that makes use of a standard shopping cart. Anyone
can add items to the cart, but only registered users can actually check out.
When a user tries to check out, if they are not logged in they will be
prompted to either login or register before they can proceed to the
checkout.

There is NO requirement to allow users to add items to a shopping cart, and
return at some time in the future and still have those items in the cart.

My question is this: what are the pros and cons of storing the contents of
the cart in the database versus storing the cart contents in a session
variable. The author of one of my reference books (on ADO.NET) provides an
example of each approach, but says his preference is for a database driven
cart. I'm not sure why this would be - any thoughts?

Thanks in advance,

Regards,

Paul Hobbs
 
Session Variables:
Pro - Very fast access
Con - Server memory is limited and expensive, using too much hinders
performance for the entire machine

Database:
Pro - Hard drive memory is cheap and doesn't hinder performance
Con - Much slower access

The usage pattern of your application and performance requirements will
guide you through the tradeoffs here. If you plan to have 1,000,000
simultaneous users, and you aren't judicious with your session variables,
you can run into trouble. If you plan to have 10 simultaneous users, they
might appreciate the improved performance of using session variables.
 
Session dont work well in a webfarm environment. This is the biggest
advantage to Database or StateServer Session implementation.


Cheers,


Greg Jackson
PDX, OR
 
Back
Top