Learning Neo4j 3.x(Second Edition)
上QQ阅读APP看书,第一时间看更新

Transactional ACID-compliant database

The Atomicity, Consistency, Isolation, Durability (ACID) of transactions ensure that your data will not be corrupt. Neo4j prides itself in being an ACID-compliant database. To explain this further, it's probably useful to go back to what ACID really means, apart from that your data stays surprise-less. Basically, the acronym is one of the oldest summaries of the four goals that many database management systems strive for, and they are shown in the following figure:

What an ACID base is
  • Atomicity: This means that changes in the database must follow an all
    or nothing rule. Transactions are said to be atomic if when one part of the transaction fails, the consequence is that the entire transaction is rolled back.
  • Consistency: This means that only consistent or valid data will be allowed to be entered into the database. In relational terminology, this often means that the schema of the database has to be applied and maintained at all times. The main consistency requirement in Neo4j is actually that the graph relationships must have a start and an end node. Relationships cannot be dangling. Aside from this, however, the consistency rules in Neo4j will obviously be much looser, as Neo4j implements the concept of an optional schema.
A schema being optional in Neo4j is a really interesting matter; the idea being that it is actually incredibly useful to have a schema-free database when you are still at the beginning of your development cycles. As you are refining your knowledge about the domain and its requirements, your data model will just grow with you--free of any requirements to pre-impose a schema on your iterations. However, as you move closer to production, schema--and therefore consistency--can be really useful. At this point, system administrators and business owners alike will want to have more checks and balances around data quality, and the C in ACID will become more important. Neo4j fully supports both approaches, which is tremendously useful in today's agile development methodologies.
  • Isolation: This requires that multiple transactions that are executed in parallel on the same database instance do not impact each other. The transactions need to take their due course, irrespective of what is happening in the system at the same time. One of the important ways that this is used is in the example where one transaction is writing to the database and another is reading from it. In an isolated database, the read transaction cannot know about the write that is occurring next to it until the transaction of the write operation is complete and fully committed. As long as the write operation is not committed, the read operation will have to work with the old data.
  • Durability: This basically means that committed transactions cannot just disappear and be lost. Persisted storage and transaction commit logs that are forced to be written to disk--even when the actual data structures have not been updated yet--ensure this quality in most database systems, and also in Neo4j.

The summary of all this is probably that Neo4j has really been designed, from the ground up, to be a truly multipurpose database-style solution. It shares many of the qualities of a traditional relational database management system that we know today; it just uses a radically different data model that is well-suited for densely connected use cases.