Search code examples
databasedistributed-systemdata-synchronizationcap-theorem

CAP Theorem - async writes & consistency


When saying a system is CP (consistent & partitioned), does that mean that we cannot use asynchronous synchronization between replicated data nodes, and that every write must be copied synchronously (and even transactionally)?

As I understand, consistency means that for every write, following reads (from any node) will get the latest update. In case we write to a specific node and synchronize the other nodes asynchronously, the reads that will occur before synchronization ends may not get the latest write.


Solution

  • When saying a system is CP (consistent & partitioned), does that mean that we cannot use asynchronous synchronization between replicated data nodes

    Yes, it's not possible to build CP system on the basis of asynchronous replication.

    Also I can't agree that in CP P stands for "partitioned", because partitioning relates to database scalability problems. I think that CP should be treated as "consistent in case of network partition".

    and that every write must be copied synchronously?

    True, but there is an optimization: replicate data synchronously not to all nodes, but to the majority of nodes, and asynchronously to the rest of nodes.

    (and even transactionally)

    I think it depends on the kind of the database (whether it support transactions or not) and how to define a transaction term itself (e.g., ACID-compatible or not). From my point of view it does not relate to the main points of CAP-theorem actually.

    consistency means that for every write, following reads (from any node) will get the latest update.

    Yes in general, but there are much more consistency models, please refer to https://jepsen.io/consistency

    In case we write to a specific node and synchronize the other nodes asynchronously, the reads that will occur before synchronization ends may not get the latest write.

    True.