Fundamentals 7 min read

Understanding the CAP Theorem and Distributed Consistency: A Practical Guide

This article explains the CAP theorem and its trade-offs in distributed systems, compares consistency models like ZAB and Raft, discusses multi‑data‑center support, gossip protocols, watch mechanisms, multi‑language clients, DNS‑based service discovery, and health‑check strategies across tools such as Zookeeper, Consul, and Eureka.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Understanding the CAP Theorem and Distributed Consistency: A Practical Guide

Technology Comparison Table

CAP Model

CAP stands for:

Consistency

Availability

Partition Tolerance

In a distributed system, these three cannot be simultaneously achieved.

Because of network partitions, P is mandatory, so systems must choose either AP or CP.

CP prioritizes data consistency, AP prioritizes availability.

Among the four, only Eureka is AP; it can operate with eventual consistency.

For more on CAP see: CAP and BASE Theory in Architecture Design

Data Consistency

ZAB is Zookeeper's atomic broadcast protocol, derived from Paxos.

Raft is a widely used strong consistency, decentralized, highly available distributed protocol.

Both algorithms are sound and achieve distributed consistency, differing in implementation.

Eureka chooses AP, does not require strong consistency, thus does not use a consistency algorithm.

References for Paxos and Raft:

Distributed Consistency Algorithm Paxos

Distributed Consistency Algorithm Raft

Multi‑Data‑Center

It refers to multiple data centers; only Consul supports it.

Zookeeper does not support multi‑data‑center; deploying across data centers can become unavailable during network partitions.

Consul implements this via the Gossip protocol.

Gossip messages spread exponentially fast across the network.

Node failures do not affect Gossip propagation, giving strong fault tolerance.

Gossip is decentralized; nodes are peers and can disseminate messages without full network knowledge, provided connectivity.

Watch

Zookeeper's watch implementation is simple, using TCP ping.

Long polling is a pull model where the client periodically requests data.

The client initiates long polling; if the server has no data, it waits until data arrives or a timeout, then the client repeats the request.

Multi‑Language Support

Zookeeper has mature multi‑language clients.

Consul's DNS support is interesting and may be unfamiliar at first.

DNS allows applications to perform service discovery without deep integration with Consul.

For example, instead of sending an HTTP request to Consul, you can use DNS to resolve a name such as redis.service.us-east-1.consul, which automatically looks up the us-east-1 data center for the redis service nodes.

Using DNS, you can integrate a DNS resolver library or customize a local DNS server.

Custom local DNS server forwards all .consul domain requests to the Consul agent.

Service Health Checks

Heartbeat is simple: the client reports its liveness.

Liveness does not equal health; an app may be alive but unhealthy due to DB failures.

Eureka supports custom health‑check logic.

Consul offers comprehensive health checks, configurable endpoints, and a UI to view status.

Recommended Reading:

Zookeeper vs Etcd

Frontend Development Tool – Wep Replay

What Does Zookeeper Do in Kafka?

Distributed Unique ID Generation Schemes

How to Determine if an Element Exists in a Billion‑Scale Dataset?

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Distributed SystemsGossip Protocol
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.