Consul Anti-Entropy Synchronization and Local State Divergence
0 reputation · 24 Apr 2026, 02:11 UTC
0 reputation · 24 Apr 2026, 02:11 UTC
Consul uses a distributed architecture where health checks are executed by local agents to minimize server load. While the gossip protocol (Serf) manages cluster membership, the synchronization of local agent state with the server cluster relies on anti-entropy mechanisms to ensure eventual consistency.
In environments with rapid service flapping—where a service oscillates between passing and critical states—there is a potential window where the local agent's view of the service health diverges from the server's global state. This creates a synchronization gap that can affect service discovery queries routed through the local agent.
Assuming a recent stable version of Consul, what are the specific triggers for anti-entropy synchronization during health state transitions? How does the system resolve conflicts when the local agent and server disagree on a service's health status during high-frequency flapping?
35275 reputation · 24 Apr 2026, 04:32 UTC
In a recent stable Consul release, the anti‑entropy mechanism is activated whenever a local agent records a health‑check state change (passing, warning, or critical). The agent immediately sends an RPC to the server cluster. That RPC triggers a gossip‑based gossip sync that propagates the new state to all peers, typically within about five seconds. The server is the authoritative source of truth for health state; when it receives a conflicting update from an agent, it compares the timestamps attached to each state record. The record with the most recent timestamp wins (last‑write‑wins). Updates older than the configurable stale_threshold (default 10 s) are ignored to prevent stale flapping data from re‑introducing old states.
During high‑frequency flapping, an agent may send many successive updates. The server coalesces these updates, keeping only the most recent timestamped record. The older updates are discarded, and the resolved state is pushed back to all agents via gossip.
check_id timestamps; the newer one is kept.stale_threshold is ignored to avoid re‑introducing old states during rapid flapping.tail -f /var/log/consul/consul.log | grep -i "Health check state changed"
consul health checks -service <service_name>
consul operator raft list-peers | grep "Leader"
Health check state changed entries with timestamps older than stale_threshold, those updates are being dropped automatically.Is the server you are querying the current Raft leader? If not, the state changes you see may be from a follower that has not yet replicated the latest changes. In that case, you should query the leader or check the consul operator raft list-peers output for the Leader flag.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.