Why SQL sucks for MMORPGs
Posted by Ben Zeigler on October 30, 2006
Update: Some of the thoughts here were elaborated on at GDC 08.
SQL databases suck for being the back end of large MMORPG’s. That statement probably either makes no sense to you, or sounds wrong and counter intuitive. If it doesn’t mean anything to you, you can safely skip the rest of this entry. For everyone else (all 2 of you) I’ll explain. The first thing is that for most programmers, SQL database are the only type they’ve ever used. Oracle, DB2, and MySQL are all SQL databases, and are equivalent for our purposes. Because SQL databases are so ubiquitous, most programmers haven’t heard of Object Databases. In my opinion, object databases are generally more suited to MMORPG development.
There are two basic reasons that SQL sucks: data mapping and latency. Data mapping (also known as Impedance Mismatch) refers to the fact that the structure of data in an SQL database differs very heavily from the structure of C++ game data. SQL requires all data to be placed in simple tables, which is perfect for bank account data. However, game data is very structured and hierarchical. To represent the concept of “A player has a set of powers” in SQL involves creating two separate data tables, setting up foreign key constraints, and manually writing code to combine the data from the two tables for use by C++. To represent this in an object database, you just set this up in your C++ definition, and things work. This mapping is confusing, complicated, and slow. Unless your entire development team is fluent in SQL, you’re going to have to write some layer in between. And those layers inevitably make latency worse.
SQL database latency problems are felt by end users. If you were playing WoW about a year ago and waited 5 seconds to pick up loot, that was SQL lag in action. The problem is that SQL databases are designed for high throughput, not low latency. When you reach a certain number of transactions per second, performance break down. There are two basic solutions to this problem: buy ridiculously expensive hardware, or implement a caching layer. Eve Online helped their performance problems by buying $100,000 solid-state disk drives. That’s not always an option, so caching can be used instead. Basically, this works by doing all of the actual transactions in a caching layer between the database and your game. When doing it this way, the SQL database is used as a glorified hard disk, and you lose most of the safety and reliability of SQL in the process. Even worse, eventually you’ll hit the same performance problems as before. Basically, you want reliable, fast, and easy. With SQL you get to pick one.
So, why are object databases better? Basically, it’s because they structure data the same way as the rest of your code. There is no conversion between the database schema and the C++ class definition because they’re the same thing. Concepts like inheritance and substructures are automatically handled, instead of requiring extensive database hackery. And, because the structure is so close to the C structure, it is much faster to load things to and from disk. You get fast, easy, and reliable.
This site has a bunch of information on object databases, for the interested. There are several commercial vendors of Object Databases that would be happy to sell your their product, or if you can write your own if you’re up to it. I know Versant has a game-focused version of their object database for sale, but I haven’t evaluated it. I’m not going to endorse a specific product, but if you happen to be starting up development on a major MMORPG (or anything with complicated data and tight latency requirements), give object databases a look. Or, just enjoy knowing that you’re not the only person who thinks that SQL sucks.
GDC 08: SQL Considered Harmful « Double Buffered said
[...] image, need to use that somewhere). I posted thoughts similar to Shannon’s presentation in a blog post from a couple years ago, when we were starting development. Because I was working on the details of [...]
owen said
I see what your saying but the problem is that once you go Object Database you lose the features of SQL. So it is not that SQL sucks, its just that SQL doesn’t do OOP. And in fact OOP goes against all that SQL represents.
But as in any client server based application, the network plays a big part in latency
tieTYT said
You may want to check out couchDB which is neither. It’s “document oriented”. Don’t ask me what that means
Back to SQL databases. One thing that’s cool about SQL is that you can query for things you never thought of looking for while you were building your schema. And, you can do it in a relatively convenient language. Maybe object dbs have these features too though.
Brandon Thomson said
Interesting thoughts. I’m using Google App Engine’s datastore partially as an object database for Conquer-on-Contact (which is still under construction, but has some live players). This mode of operation is not supported and gets me some ridicule from the community but it works.