开发者

How do I keep user specific data separate in my database?

I'm in the planning phase of designing an app that will involve users register开发者_StackOverflow社区ing with my website and storing data. I've decided on using Spring and Hibernate but I have a couple questions for which I would like to get answers.

My first question involves data separation. When a user registers with my site, they will be able to store data imported from another source. The amount of data (number of rows) for each user will grow very fast. If I store all user data in a single database I expect to run into performance problems very quickly. To address this, I was planning to create a new database for each user that signs up. This would happen on the fly via some script or other programmatic solution. Is this feasible? Does anyone know of any design pattern that addresses this problem?

My second question is related to my first question. If it is feasible to create a new database for each user, how will this work with hibernate? Obviously I won't restart my application every time a new user signs up. Can hibernate be configured dynamically to connect to a different database based on some criteria (currently logged in user)? If I have two users logged in simultaneously, the expected behavior would be that each user only have access to data in their database.

Thanks.


DB performance problems usually boils down to poor indexing, not enough memory and/or poor SQL queries. A single DB per user does by far not solve this, that's only overcomplicated. There is not really a design pattern for this, just have solid hardware with enough memory and a well-normalized database with well-indexed columns. Putting the right indexes is relatively trivial, generally it suffices to just put it on columns which have key constraints and columns which are involved in WHERE clauses. Hibernate/JPA in turn generates in general well-optimized SQL queries and offer second-level caching possiblities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜