The right storage model

time to read 2 min | 276 words

Originally posted at 12/15/2010

What are the advantages that you get when using RavenDB? The easy answers are:

  • Sparse data
  • Dynamic data
  • Better scaling across nodes

But there is another one that is even more important, in my eyes. It is the simple issue that with RavenDB, a document is a transactional boundary. That makes it very easy to model interactions on root aggregates that are much harder in relational database.

The most commonly used example is Order & OrderLines. In a relational database, those would be in two separate tables, and it is possible to modify order lines without touching the order. With RavenDB, on the other hand, the OrderLines are embedded in the Order document, so you literally cannot modify them without touching the order as well. This has a lot of implications. The most obvious one is that you just got rid of a big burden in terms of managing concurrency. You no longer have to be very careful about how you update parts of your model, as you have to be when using relational databases. You can just make any update you want, and if there are concurrent updates, it will completely, without you having to do anything at all.

Another benefit of this approach is that because a document is the transactional boundary, accessing all of it is a very cheap operation. Coming back again to the Order, it is a very cheap operation to access all of the Order details, which can be very costly in a relational database (having to access Orders, OrderLines, Addresses, etc… ).