liveBook · Manning

Consistency model

As explained in Crack Any Codebase with AI

A consistency model specifies what values concurrent readers and writers are guaranteed to observe in a distributed or concurrent system.

A consistency model states what concurrent readers and writers are guaranteed to observe. It becomes visible when two people claim the last slot or two browser tabs update the same record: the promise determines which races are safe and which bugs remain possible. section 9.5

Useful guarantees form a spectrum:

  • Linearizable reads see the latest write system-wide. section 9.5
  • Serializable execution preserves one operation order, while read-your-writes ensures users see their own updates. section 9.5
  • Eventual consistency permits temporary disagreement while replicas converge. section 9.5

Preventing a double booking

Cal.com keeps Postgres as the source of truth and treats Redis as disposable cache. For bookings, a Prisma extension derives a shared idempotency key from the slot and host; the database UNIQUE constraint makes concurrent inserts collide. The preceding availability read alone cannot protect against a race. section 9.5

Table 9.5 What each consistency model promises when two writers race
Model
What it promises
Examples
What it buys
What it costs
Linearizable
Every read sees the most recent write, system-wide
Single-primary Postgres/MySQL writes, etcd, Spanner
One global order; the easiest model to reason about
Coordination on every write; the slowest and least available under partition
Sequential/serializable
All clients see operations in the same order, not necessarily real-time
SERIALIZABLE isolation, FoundationDB
Safe concurrent transactions without manual locking
Aborts and retries under contention
Read-your-writes
You always see your own writes; others may lag
Sticky sessions to primary, "read from primary after write"
A user never loses their own edit
Doesn't help two different users racing
Bounded staleness
Reads lag the truth by at most X seconds
DynamoDB strong-vs-eventual toggle, Cosmos DB tunable
Tunable freshness-vs-cost dial per query
You must pick the bound, and pick wrong somewhere
Eventual
All replicas converge given no new writes
DynamoDB default reads, Cassandra ONE, DNS
Highest availability and throughput
Stale reads, lost-update and conflict-resolution headaches

Compare consistency models by promise, examples, operational benefit, and coordination cost. section 9.5

How Crack Any Codebase with AI covers it

How deep it goes
Explains consistency guarantees, database defaults, locks, isolation, and unique constraints, but does not develop formal semantics.
Examples
Uses Cal.com’s Postgres–Redis split and concurrent booking inserts as concrete consistency examples.
What it assumes
Assumes familiarity with concurrent requests, databases, caches, and writes; grounds the analysis in practical race scenarios.
What you can do after
Diagnose/debug with it: identify drift and double-booking risks by naming guarantees and inspecting database constraints.
How it connects
Connects consistency models with caching, transactions, database isolation, idempotency, unique constraints, and eventual consistency.

Also explained in

Compare how 7 books explain consistency model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Crack Any Codebase with AI. The section links point to the parts of the book it draws on.