Data Consistency across Continents

video locked
Enroll to watch

9 mins

Chapters
About
Discussion0
Notes
Be the first to start a conversation!

Data Consistency across Continents

Consistency means that multiple copies of the same data are the same.

A cache on the Harvard server reduces latency for Oxford profiles. The Harvard server checks its cache, fetches a missing profile from the Oxford server, stores it and returns it. A cache miss still goes to Oxford.

The practical fix is multiple copies of the data, one in the US and one in Europe.

  1. No single point of failure. If one server crashes, the other serves the data.
  2. Network issues are solved. A user who belongs to Europe is read from the copy in the US.
  3. Latency is low. An update to C is made locally and the response is sent back.

The update then has to propagate to the other copy. Done manually, it suits infrequent updates: a bank notes the change in a ledger, and it reflects on the statement in a few days. A real time system sends the update over TCP, which gives reliable and ordered delivery, and Europe applies it. The open problem is a failed transmission.

Leader-follower architectures

A leader-follower architecture lets only one server, the leader, commit writes. The followers receive its updates and serve reads.

The chain that leads to it:

  1. The US server sends an update to the Europe server, and the transmission fails. The fix is an acknowledgement.
  2. The acknowledgement fails too. The US server retries, every five seconds forever, or five times before it gives up.
  3. A server that commits locally cannot depend on its peer to commit, because the network is unreliable. A server that waits hands the same problem to the peer, which never knows whether its acknowledgement arrived. An acknowledgement of the acknowledgement is an infinite process. This is the two generals problem.

So the US server becomes the leader, the only one that writes to the database. The Europe server is a follower: it gets regular updates from the leader and serves reads.

If an update does not go through, a follower that answers gives a dirty read, and a follower that waits is not available. Pure consistency costs availability, and availability brings inconsistencies.