Are NoSQL databases ACID?
One of the main features you may miss when discovering NoSQL ("Not-Only SQL"?) databases, coming from a RDBMS background, is ACID.
ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties that guarantee that database transactions are processed reliably. In the context of databases, a single logical operation on the data is called a transaction. For example, a transfer of funds from one bank account to another, even involving multiple changes such as debiting one account and crediting another, is a single transaction. (Wikipedia)
Please ensure you read the Martin Fowler
introduction about NoSQL databases.
And the corresponding video.
First of all, we can distinguish two types of NoSQL databases:
- Aggregate-oriented databases;
- Graph-oriented databases (e.g. Neo4J).
By design, most Graph-oriented databases are ACID!
This is a first good point.
Then, what about the other type?
In Aggregate-oriented databases, we can identify three sub-types:
- Document-based NoSQL databases (e.g. MongoDB, CouchDB);
- Key/Value NoSQL databases (e.g. Redis);
- Column family NoSQL databases (e.g. Cassandra).
It may be schema-less, blob-stored, column-driven, but it is always some set of values bound together to be persisted.
This set of values define a particular state of one entity, in a given model.
Which we may call Aggregate.
What we call an Aggregate here, is what Eric Evans defined in its Domain-Driven Design as a self-sufficient of Entities and Value-Objects in a given Bounded Context.
As a consequence, an aggregate is a collection of data that we interact with as a unit.
Aggregates form the boundaries for ACID operations with the database.
So, at Aggregate level, we can say that most NoSQL databases can be as
safe as ACID RDBMS, with the proper settings.
Of source, if you tune your server for the best speed, you may come into something non ACID. But replication will help.
My main point is that you have to use NoSQL databases as they are, not as a
(cheap) alternative to RDBMS.
I have seen too much projects abusing of relations between documents. This can't be ACID.
If you stay at document level, i.e. at Aggregate boundaries, you do not need any transaction.
And your data will be as safe as with an ACID database, even if it not truly ACID, since you do not need those transactions!
If you need transactions and update several "documents" at once, you are not in the NoSQL world any more - so use a RDBMS engine instead!
We are currently cooking a native direct MongoDB access in our
See our SynMongoDB.pas unit...
Still work to do, but I suspect this will be another unit feature of mORMot, when the corresponding
will achieve one highly-optimized bridge between our RESTful ORM and MongoDB.