No SQL, No Problems (or: Mo' SQL, Mo' Problems)

26 Feb 2010

Let’s talk about NoSQL:

If you’ve been following the latest trends in the .net world via reddit, twitter, or your favorite blogs, you’ve been seeing a great deal of chatter about a term called NoSQL. Some might even call it a ‘movement’ but that scares me just a little bit - when things become ‘movements’, their meanings become a bit nebulous. Here are a few cases where a ‘NoSQL’ solution might be useful to you: You have a several multi-million row tables that each have foreign key relationships to one another, joins against these tables pound the server, but must return rapidly.

You have “jagged” datasets where each record has a different composition of fields and children, those children in turn have their own properties.

You need to find a root record based on a complex set of relations to other tables. A New Hope: There are many NoSQL options out there right now, but for reasons that will become obvious very shortly, I am going to talk about one in particular: MongoDB. MongoDB is a “document-oriented” database written in c++ that stores your documents in a format called “BSON.” BSON is conceptually similar to JSON, but is a binary format that also explicitly carries type information. Mongo has some nice features, including:

  • Dynamic creation and allocation of databases and document collections (including the capability of having nested collections)
  • Ability to do deep-graph searches (i.e. locate documents based on child properties of the document)
  • Ability to execute arbitrary JavaScript functions for aggregation and as criteria of searching
  • Very few requirements on what can be inserted into a database
  • Support for regex searching.
  • Speed
  • …more…

But you should be warned: MongoDB doesn’t make ACID guarantees. If you’re storing twitter updates, you’re probably ok, if you’re storing financial transactions, don’t use MongoDB. But this is a blog about C# where we have strong & static typing, we live and breath order in our daily lives (ha!). “Leave all that ‘No SQL’ to those dirty Ruby hippies”, you say.

Let me break it to you: NoSQL doesn’t mean NoStructure.

To that end, I’ve been (with lots of help) incubating a project on GitHub called NoRM. In brief, NoRM is a library to connect to MongoDB using .Net (and Mono) and to query and hydrate documents into strongly & statically-typed documents in a way that doesn’t make us C# developers queasy. We still have a long way to go before a 1.0 release, but I think it’s important to point out some of the guys that have been most enthusiastic about this project (and contributed some great code and ideas) include: James Avery Jason Alexander Rob Conery Nate Kohari Karl Seguin These guys really know their stuff, and I am so happy to have them working on this with me. My next post will be about some of the design decisions we’ve made with NoRM and how you might use it (soon) in some of your own projects.