ravendbcap

How does RavenDB achieves consistency, availability, and partition tolerance?


According to CAP theorem it is impossible for a distributed computer system to simultaneously provide consistency, availability, and partition tolerance.

Reading about RavenDB it looks like this database supports ACID transactions and sharding at the same time. How does RavenDB achieves that?


Solution

  • To clarify things upfront:
    by default all writes in a RavenDB session between calls to .SaveChanges() are all-or-none. If one operations fails for whatever reason, then all changes in the current session/since the last save will be discarded. This feature, in combination with optimistic concurrency turned on, is very powerful. If you need longer transaction, there is support for System.Transaction as well, and that works as expected.

    In regards to sharding:
    There is no true support for distributed transactions in a sharded setup. However, due to the locality of reference documents in a good sharding strategy, you can have transactional writes on each of your stores. They simply work the same as if there weren't any shards at all.