In a distributed system what is the relationship between database architecture and CAP theorem?

41 Views Asked by At

I know that there are a few database architecture out there like master-slave , master-master etc. Now my question is in a distributed system :

  1. Is there a relationship between a database following AP or CP and having a master node or not?
  2. Can a database following a masterless architecture ever be strongly consistent?
  3. Similarly can a database having a single-master node be highly available?

My understanding here is that in a master-slave/single-master architecture if a master node goes down the database would become unavailable until another node is promoted to master so low availability, similarly in case of a masterless architecture (all nodes act as master) if I am free to perform read and write operations on any node, maintaining a strong consistency across all nodes would be very difficult.

So Would I be right to say as the number of master node increases in a database( assuming the case of masterless indicates all the nodes behave as master) Consistency becomes eventual (from strong in case of single master) & availability becomes high ?

1

There are 1 best solutions below

0
AndrewR On

CAP theorem is a great topic to talk about - very engaging :)

I am going to point out a few links from Martin Kleppmann (the author of Data Intensive Apps book

In practice, I do use CP/AP terminology around databased. I choose to call systems CP if I am guaranteed to get the latest value (or error) with a read after a write is done. For example:

  • I send a write to a leader
  • the leader replicates the data to followers
  • the leader reports back to me that the write is done
  • I send a read - I expect to see latest data, or an error

Basically, I choose (I emphasize "choose") to think about CP and a recency thing - do I see the latest data, or an error. The point of thinking CP - it makes the system much simpler to reason about, I don't need to guess if some data (or part of data) is stale.