Saturday, December 11, 2010

Persistent, Aren't You?

One of the big questions for almost every project is how to persist the data.  Common forms include:

  • Flat files (XML, JSON, etc)
  • Databases (SQL, NoSQL, etc)
  • RAM
Now, granted, that last one isn't used very often.  You'd have to have a system that never goes down, or a series of redundant systems that always keep at least 1 system up at all times.  That's pretty tough to guarantee.  Of course, if you don't care that your data disappears during an outage (like with a caching server) then RAM is perfect.

Flat files are useful mainly when you just can't have a database, for some reason.  They're also useful when dealing with documents.

SQL databases (aka Relational Databases) are useful for data that has many parts that are related to each other.

NoSQL databases are useful for document storage, with minimal relationships.  They also tend to be easily horizontally scalable.

When I started working on the MUD, I was pretty sure I was going to use CouchDB or another NoSQL database for a few reasons:

  • Horizontal scaling
  • MUD accounts could be easily stored as documents.
When creating a SQL database for a MUD, you have a lot of tables to deal with, including Users, Characters, Items, Rooms, NPCs, and more.  Creating the relationships between them involves quite few many-to-one and many-to-many relationships.

On the other hand, a NoSQL database could store the user's account and everything attached to it as 1 big record.  Each area in the world could be another, etc.  It would simplify the data access quite a bit.

But in the end, I decided I didn't want to limit it to any of these.  I'll be writing a system that will store the data in any of the above methods simply by setting that information in the configuration files.  It should even be possible to create conversion tools that quickly convert from 1 format to another.  This would make backups or migrations quite easy.

And there's one more thing it makes easy:  Testing.  I will be creating a mock data store that can be used to feed any data into the system at will.  That'll make unit tests quite a bit easier and faster.

No comments: