Back to blog
Series · Day 2
Distributed Systems in 30 Days
View all lessons →
The CAP Theorem Bug Already Living in Your Agent Stack

Consistency vs Availability

A GPU node in your inference cluster goes dark mid-request. Your load balancer has about a millisecond to decide: answer anyway with data that might be stale, or make the caller wait until you're sure it's right. Nobody sits down and consciously "chooses" this — it just happens, over and over, at machine speed. And whatever it defaults to becomes your architecture, whether you meant it to or not.

What consistency means

Consistency is the guarantee that every read sees the most recent write, and every node agrees on what's true right now. Write X, then read it back from any replica, and you get X — never last week's value, never what node 3 thinks happened. It's the property behind your bank balance being right, and behind actually knowing whether that deploy is live yet.

What availability means

Availability is a different promise. It doesn't say the answer is fresh — it says there is an answer. Success or failure, you get a response, even with half the nodes unreachable. A genuinely available system never just sits there waiting on a node that might not come back; it works with whatever it's got.

Why you can't always have both

The moment the network splits — a node goes deaf to the rest of the cluster — you're stuck picking a side. Wait for the other half to confirm and you're consistent, but the caller might time out staring at a spinner. Answer from what's local and you're available, but you might be wrong. That's the CAP theorem, and it's not a whiteboard abstraction. It's the exact call your load balancer makes the instant an inference node stalls.

Where this shows up in AI systems today

  • LLM inference load balancing: a request landing on a GPU replica running config that's slightly behind is usually harmless. Take the availability.
  • Agent memory / shared state — the blackboard multiple agents write to: let two agents act on different ideas of "what's already decided" and you get duplicate work, or worse, agents actively working against each other. The decision log needs consistency, even if nothing else does.
  • RAG vector stores: a document that just got ingested but isn't indexed everywhere yet is a perfectly acceptable kind of stale. Take availability, just be honest about the lag.
  • Multi-agent orchestration state — who owns which task: this needs one source of truth, full stop, or you'll watch two agents grab the same task at once. Consistency, usually enforced with a lock or an elected leader.
  • Rate limits and cost guardrails across an agent fleet: if the counters are only eventually consistent, the whole fleet can burst past budget before the numbers catch up. This is the one spot where "slightly available" quietly turns into "slightly bankrupt."

Here's the rule I actually use: consistency for anything that represents a decision or a claim on a resource — task ownership, spend, safety config, leader election. Availability for anything that's just an observation or a suggestion — cached context, retrieved docs, a model's answer. Nearly every agent bug I've chased down traces back to someone treating a decision field like it was eventually consistent.

text
# Same lookup, two different consistency choices — pick per field, not per database

# Consistency-first (CP): confirm quorum before you answer
read_task_owner(task_id, consistency="QUORUM")
# -> slower, sometimes unavailable mid-partition, but never double-assigned

# Availability-first (AP): answer from whatever replica is nearest
read_cached_context(session_id, consistency="ONE")
# -> always fast, occasionally stale by a few hundred ms — fine for a suggestion

Common pitfalls

  • Defaulting the whole database to "strong consistency" because it feels safer — you pay the latency and availability cost everywhere, including the places that never needed it.
  • Defaulting the whole system to "eventually consistent" for scale, then finding out the hard way that your task-assignment or billing logic silently double-processes mid-partition.
  • Mistaking "my system feels consistent in testing" for "my system is consistent." A single-node dev environment never shows you a partition — you have to force one, kill a node, inject latency, to see the real tradeoff.
  • Treating this as one big architecture decision instead of a per-field one. Most systems that actually hold up in production are consistent for some data and available for the rest, on purpose, field by field.
Flashcards
Check yourself

Extend your knowledge

  • Chapter 9, "Consistency and Consensus," in Martin Kleppmann's Designing Data-Intensive Applications — he's actually skeptical of CAP as it's commonly stated, but the chapter is still the clearest treatment of what the underlying tradeoffs (linearizability vs. availability) really are.
  • Kyle Kingsbury's Jepsen test reports — he runs real databases through real partitions and shows which choice they actually made, not the one on the marketing page.
  • AWS's docs on DynamoDB's "eventually consistent" vs. "strongly consistent" reads — a live, tunable version of this exact knob, in a system you can spin up this afternoon.
  • Werner Vogels' "Eventually Consistent" post — Amazon's CTO explaining, in plain language, why availability was the right call for the shopping cart.
Test yourself on this lesson

Discussion

Chat with Chi Cong (AI) about this article. Your conversation is private to you — you can publish a summary for others when you're done.

Ask me anything about “The CAP Theorem Bug Already Living in Your Agent Stack” — trade-offs, decisions, or the story behind it.