CAP Theorem But Better? Introduce the PACELC Theorem

In the previous blog, I introduced the famous CAP Theorem (please give it a read if you haven’t already before you start reading this one). It involves a trilemma of needing to give up one of the following three qualities: consistency, availability, and partition tolerance. Since all three are desirable features of modern-day distributed systems, determining which one to relinquish has become one of the most important and delicate decisions for designers of complicated distributed systems. While the CAP Theorem is widely-known in computer science, its extension, the PACELC theorem, has received less attention. Today, I will shine a long-overdue spotlight on the PACELC theorem.

PACELC-theorem-diagram

First, let’s start with what the PACELC theorem states. We can split the PACELC theorem into “PAC” and “ELC.” “PAC” means if there is a network “partition,” a distributed system has to choose between “availability” and “consistency.” This part is equivalent to the CAP theorem, except it assumes that we always prioritize and consider “partition tolerance” a given. “ELC” is the novel idea that the PACELC theorem has brought to the table. “E,” “L,” and “C” respectively stand for “else,” “latency,” and consistency.” “ELC” states if there is not a network partition (“else”), a distributed system needs to make a trade-off between “latency” and “consistency.”

Since we have already covered the CAP theorem in the previous blog, let’s focus on the “ELC” part for now. What are the definitions of latency and consistency?

Latency (or Low Latency)

Oxford Languages defines latency as “the delay before a transfer of data begins following an instruction for its transfer.” Saying the “L” stands for latency is inaccurate since we usually aim to minimize latency in computing systems to speed up operations. To make the “L” a sought-after quality that we want in distributed systems, I prefer to think of it as “low latency.”

Consistency

The consistency in “ELC” is the same as that of the CAP theorem. If a distributed system is consistent, every read request receives the most recent write or an error. In other words, with consistency, no matter which node users make a read request to, they always receive the most recent data written to the distributed system or an error if the most recent data is not currently available.

An obvious question to ask at this point is: why can’t we have low latency and consistency when there is no network partition? I will answer this question with a simple example.

distributed system

Assume we have a distributed system of two nodes: Node A and Node B. In the absence of network partitions, these two nodes can easily communicate with each other via messages. Node A just received the most recent write. At the same time, Node B received a read request asking for that particular write. If that distributed system aims to achieve consistency, Node B has to send the most recent write in response to the read request. Therefore, Node B has to wait to receive the most recent data from Node A before it can update its old data and respond to the read request. This delay essentially increases latency in the distributed system.

Now that we are sure we cannot have the best of both worlds, it begs the question, which one should we pick in what situation? Similar to what I mentioned in the previous blog, the rule of thumb is to choose consistency over low latency when the accuracy and timeliness of data are of vital importance. Some great examples of applications in pursuit of consistency at all times include fintech applications and bank ATMs. If data accuracy and timeliness are not that important, then low latency should have priority. Social media platforms and games are great examples of applications aiming for low latency.

To summarize, I briefly introduced the PACELC theorem in this blog. I touched upon how the PACELC theorem extends the CAP theorem and the definitions of latency (or low latency) and consistency. Then, I demonstrated why we cannot achieve low latency and consistency simultaneously in a distributed system not experiencing a network partition. In the end, I offered some tips on when to choose consistency and when to choose low latency. I hope this article has helped you gain insight into the PACELC theorem and how to apply it to system design.

おすすめ記事