views:

476

answers:

16

Let's say I want to build a gaming website and I have many game sections. They ALL have a lot of data that needs to be stored. Is it better to make one database with a table representing each game or have a database represent each section of the game? I'm pretty much expecting a "depends" kind of answer.

+8  A: 

Depends.

Just kidding. If this is one project and the data are in any way related to each other I would always opt for one database absent a specific and convincing reason for doing otherwise. Why? Because I can't ever remember thinking to myself "Boy, I sure wish it were harder to see that information."

Larry Lustig
+17  A: 

Managing 5 different databases is going to be a headache. I would suggest using one database with 5 different tables. Aside from anything else, I wouldn't be surprised to find you've got some common info between the 5 - e.g. user identity.

Note that your idea of "a lot of data" may well not be the same as the database's... databases are generally written to cope with huge globs of data.

Jon Skeet
May not even need 5 tables, it really depends on the schema.
JonH
Separate databases means they would be easier to backup/restore; a single database would mean all components are working or none. Data model change impact is inevitable in either case, but it could be implemented piecemeal if databases were separate.
OMG Ponies
It really depends if the components depend on each other. If they do not, then @rexem's comment makes sense. If they are related, then keeping in one database makes a lot more sense. Besides, if your data is so big that you need to consider sharding or partitioning, then this will be the smallest of your concerns.
gahooa
@rexem: Implementing change across 5 databases does indeed let you do it in smaller chunks in some cases - but it also means there's probably more to do in total, giving greater possible errors. I'm also not sure why you think it's easier to back up 5 separate databases than 1. I guess it means you could use 5 smaller areas of storage... but I doubt that that's a big deal. 5 schedules, 5 sets of scripts etc sounds like a bad idea to me.
Jon Skeet
@Jon: Schedules are just schedules - there's lots of large scale places using this approach, doing just fine. My actual point was that with a single database you constrain to a monolithic application. It'd be easier to restore a subcomponent if the databases are split.
OMG Ponies
@regex: Large scale places are one thing, but this sounds like it's not *that* large. Until the contraints you talk about actually become a real problem (rather than a theoretical one), I believe it will be easier to maintain a single database. One backup, one connection string etc.
Jon Skeet
A: 

Really depends :)..

Ask yourself these questions:

Could there be a resuability (users table) that I may want to think about? Is it worth seperating these entities or are they pretty much the same? Do any of these entities share specific events / needs? Is it worth my time and effort to build 5 different database systems (remember if you are writing the games that would mean different connection strings and also present more security, etc).

Or you could create one database OnlineGames and have a table that stores the game name and a category:

PacMan Arcade

Zelda Role playing

etc etc..

It really depends on what your intentions are...

JonH
+3  A: 

While there is not enough information in your question to give a good answer, I would say that unless you foresee needing data from two games at the same time for the same user (or query), there is no reason to combine databases.

You should probably have a single database for anything common, and then create independent databases for anything unique. Databases, like code, tend to end up evolving in different directions for different applications. Keeping them together may lead you to break things or to be more conservative in your changes.

In addition, some databases are optimized, managed, and backed-up at a database level rather than a table level. Since they may have different performance characteristics and usage profiles, a one-size-fit-all solution may not be scalable.

If you use an ORM framework, you get access to multiple databases (almost) for free while still avoiding code replication. So unless you have joint queries, I don't think it's worth it to pay the risk of shared databases.

Of course, if you pay someone to host your databases, it may be cheaper to use a single database, but that's really a business question, not software.

If you do choose to use a single database, do yourself a favour and make sure the code for each game only knows about specific tables. It would make it easier for you to maintain things later or separate into multiple databases.

Uri
A: 

If you are going to be storing the same data for each game, it would make sense to use 1 database to store all the information. There would be no sense in replicating table structures across different databases, likewise there would be no sense in creating 5 tables for 5 games if they are all storing the same information.

James
@James Goodwin Actually replicating data structures in independent databases is a perfectly valid pattern for scalability. It's called sharding or sometimes horizontal partitioning.
Asaph
I'm sure in some large scale databases this is necessary, But in this case it would probably bring unwanted complexity.
James
+1  A: 

If the different games don't share any data it would make sense to use separate databases. On the other hand it would make sense to use one database if the structure of the games' data is the same--you would have to make changes in every game database separately otherwise.

Update: In case of doubt you should always use one database because it's easier to manage in the most cases. Just if you're sure that the applications are completely separate and have completely different structures you should use more databases. The only real advantage is more clarity.

arno
+1  A: 

One database.

Most of the stuff you are reasonably going to want to store is going to be text, or primitive data types such as integers. You might fancy throwing your binary content into blobs, but that's a crazy plan on a media-heavy website when the web server will serve files over HTTP for free.

I pulled lead programming duties on a web-site for a major games publisher. We managed to cover a vast portion of their current and previous content, in three European languages.

At no point did we ever consider having multiple databases to store all of this, despite the fact that each title was replete with video and image resources.

I cannot imagine why a multiple database configuration would suit your needs here, either in development or outside of it. The amount of synchronisation you'll have to pull and capacity for error is immense. Trying to pull data that pertains to all of them from all of them will be a nightmare.

Every site-wide update you migrate will be n times as hard and error prone, where n is the number of databases you eventually plump for.

Seriously, one database - and that's about as far from your anticipated depends answer as you're going to get.

Paul Alan Taylor
A: 

I'm not sure this is correct, but I think you want to do one database with 5 tables because (along with other reasons) of the alternative's impact on connection pooling (if, for example, you're using ADO.Net). In the ADO.Net connection pool, connections are keyed by the connection string, so with five different databases you might end up with 20 connections to each database instead of 100 connections to one database, which would potentially affect the flexibility of the allocation of connections.

If anybody knows better or has additional info, please add it here, as I'm not sure if what I'm saying is accurate.

MusiGenesis
A: 

What's your idea of "a lot of data"? The only reason that you'd need to split this across multiple databases is if you are trying to save some money with shared hosting (i.e. getting cheap shared hosts and splitting it across servers), or if you feel each database will be in the 500GB+ range and do not have access to appropriate storage.

Note that both of these reasons have nothing to do with architecture, and entirely based on monetary concerns during scaling.

But since you haven't created the site yet, you're putting the cart before the horse. It is very unlikely that a brand new site would use anywhere near this level of storage, so just create 1 database.

Some companies have single databases in the 1,000+ TB range ... there is basically no upper bound on database size.

Jess
+1  A: 

Generally speaking, "one database per application" tends to be a good rule of thumb.

If you're building one site that has many sections for talking about different games (or different types of games), then that's a single application, so one database is likely the way to go. I'm not positive, but I think this is probably the situation you're asking about.

If, on the other hand, your "one site" is a battle.net-type matching service for a collection of five distinct games, then the site itself is one application and each of the five games is a separate application, so you'd probably want six databases since you have a total of six largely-independent applications. Again, though, my impression is that this is not the situation you're asking about.

Dave Sherohman
A: 

The number of databases you want to create depends not on the number of your games, but on the data stored in the databases, or, better say, how do you exchange these data between the databases.

  • If it is export and import, then do separate databases.
  • If it is normal relationships (with foreign keys and cross-queries), then leave it in one database.

If the databases are not related to each other, then they are separate databases, of course.

In one of my projects, I distinguished between the internal and external data (which were stored in separate databases).

The difference was quite simple:

  • External database stored only the facts you cannot change or undo. That was phone calls, SMS messages and incoming payments in our case.

  • Internal database stored the things that are usually stored: users, passwords etc.

The external database used only the natural PRIMARY KEY's, that were the phone numbers, bank transaction id's etc.

The databases were given with completely different rights and exchanging data between them was a matter of import and export, not relationships.

This made sure that nothing would happen with actual data: it is easy to relink a payment to a user, but it's very hard to restore a payment if it's lost.

Quassnoi
A: 

I can pass on my experience with a similar situation.

We had 4 "Common" databases and about 30 "Specific" databases, separated for the same space concerns. The downside is that the space concerns were just projecting dBase shortcomings onto SQL Server. We ended up with all these databases on SQL Server Enterprise that were well under the maximum size allowed by the Desktop edition.

From a database perspective with respect to separation of concerns, the 4 Common databases could've been 2. The 30 Specific databases could've been 3 (or even 1 with enough manipulation / generalization). It was inefficient code (both stored procs and data access layer code) and table schema that dictated the multitude of databases; in the end it had nothing at all to do with space.

I would consolidate as much as possible early and keep your design & implementation flexible enough to extract components if necessary. In short, plan for several databases but implement as one.

Austin Salonen
A: 

Remember, especially on web sites. If you have multiple databases, you often lose the performance benefits of query caching and connection pooling. Stick to one.

Chris Kaminski
A: 

Defenitively, one database

lepnio
A: 

One place I worked had many databases, a common one for the stuff all clients used and client specifc ones for customizing by client. What ended up happening was that since the clients asked for the changes, they woudl end up inthe client database instead of common and thus there would be 27 ways of doing essentially the same thing becasue there was no refactoring from client-specific to "hey this is something other clients will need to do as well" so let's put it in common. So one database tends to lead to less reinventing the wheel.

HLGEM
A: 

Security Model If each game will have a distinct set of permissions/roles specific to that game, split it out.

Query Performance /Complexity
I'd suggest keeping them in a single database if you need to frequently query across the data between the games.

Scalability Another consideration is your scalability plans. If the games get extremely popular, you might want to buy separate database hardware for each game. Separating them into different databases from the start would make that easier.

Data Size
The size of the data should not be a factor in this decision.

JohnFx