File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes should I load product info into memory or keep in db? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "should I load product info into memory or keep in db?" Watch "should I load product info into memory or keep in db?" New topic

should I load product info into memory or keep in db?

Henry Sun

Joined: May 09, 2003
Posts: 18
I am going to develop a b2c shopping website with jboss-tomcat bundle. Now I must make a decision on whether I should load product info into memory or just keep it in table. If load into memory, the performance of customer browsing and searching will be good; but I am afraid of the memory capacity and issues like, when I want to update the product price or description, I need to refresh the memory objects. This shop has about 500 products and we will develop this application into Dell server with 1GB memory. Can anyone who has ever developed such e-commerce website give me some suggestions?
Paul Lester
Ranch Hand

Joined: Dec 27, 2002
Posts: 40
Hello, Henry: Considering that you have only 500 items, any database, including M$ Access should be able to give you nearly instantaneous access to any record; therefore, you won't notice much difference between hitting the database and caching the records.
Caching should be done only after careful consideration. One of the biggest problems, as you mentioned, is how to refresh the objects as well as how often to refresh them. Then there are the memory constraints, etc. I would steer away from caching your entire product line. If the number of products continue to grow then you are going to start having issues with memory.
Keeping the information in the database allows you to update or remove items easily and without an application restart. Further, if you determine that it is too slow you can add indexes, get faster hardware, etc.
Lastly, deciding whether or not to cache, in the design stages, is a bit premature. You should come to that decision AFTER you've done some profiliing of the application and found that the DB portion is indeed the bottleneck of the application.

Where Photography meets vision.<br /><a href="" target="_blank" rel="nofollow"></a><br />Please stop by!<br /> <br />SCJP,SCWCD,SCJD,SCEA
Henry Sun

Joined: May 09, 2003
Posts: 18
Thank you, Paul. I prefer keeping the pruducts in database instead of memory. I'll do some profiling, just like you said, then make the final decision.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

One of the best bits of advice I can give is not to worry about efficiency more than you need to. It's not like there's only one "right" way to do things.
I've found that it's a good idea to keep the design "loose" so that mods can be made as needed rather than to try and anticipate problems that may never occur. Especially if solving these non-problems is going to lock you out of being able to address the problems that do occur.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: should I load product info into memory or keep in db?
It's not a secret anymore!