I'm creating a web application using JavaBeans, JSP & Postgres. My database contains 2 major types of data 1) CMS-type data used for displaying forms & the info listed in drop-down menus, radio buttons, etc. 2) user-submitted data that is entered by users of the web-app via forms.
For all of the CMS-type data I am pulling it from the database into singleton JavaBean classes at the start of the application so that it can be accessed by the application via objects instead of making database queries. For user-submitted data, I am submitting the data to the database for storage.
I am now working on providing users of the application with a way to view the user-submitted data. I can see two different approaches for how to do this, and would like to get your opinion on which would be the best approach.
Approach 1) Each time someone wants to view user-submitted data, that data is pulled from the database into an instance of an object that represents the type of form data they are viewing. Once the object is no longer in use, the garbage collector would clean it up. More than one instance of this object could be created at once, so multiple users could have their own instance with the latest info from the database.
Approach 2) At the start of the application pull all of the user-submitted data into singleton classes each representing a different form submitted. If a user submits a new form, then create a new object in memory with all of the form data and then (afterwards) submit that same data to the database for persistence. If someone modified an existing form, the in-memory object would be updated first and then the database would also be updated - same for deleting an object. This would be done to ensure that whoever was viewing an object (by accessing that object's methods) would have the most up to date information and the database would remain in the background for storage purposes only.
It seems to me that from a design perspective, approach number 2 would be the best for separating out the database from the code, but I'm worried that it may be too memory intensive. The application will eventually have hundreds of millions of user-submitted forms, and I'm concerned that it might be a problem to hold all of those objects in memory all of the time. None of my objects would be very large - at most 40 attributes and 99% of them would be short strings or ints. I may occasionally have blobs for pictures or attached documents, but that is going to be rare.
Does anyone have any experience with these different approaches or any other approaches that might be better than the ones I've come up with?
If you need more information on how much memory my objects will take, please ask me specific questions as I am not as familiar with how to quantify program memory. Also, if you think that the answer lies in the speed/performance of my hardware or load balancing, etc. could you give me details on what hardware/equipment/practices I should be using to do this? I'm using a hosted Linux server to run my code.
I look forward to getting your input!