Distributed Database

Chapter 8
Consistency Models and Fundamental Trade-offs

Post Graduate Program in Data science
Distributed Database   •   Post Graduate

Consistency Models and Fundamental Trade-offs

Introduction

Distributed databases replicate data across machines, availability zones, or geographic regions. Replication improves fault tolerance, latency, throughput, and disaster recovery, but it creates a fundamental question: when one client updates data, what are other clients entitled to observe, and when? Consistency models answer this question by specifying the ordering and visibility guarantees provided by a system.

Consistency is not synonymous with correctness. A system may be highly consistent but implement an incorrect business rule; conversely, an eventually consistent system may be correct for workloads that tolerate temporary staleness. The appropriate model depends on the application’s invariants, failure assumptions, latency objectives, and tolerance for stale or conflicting data.

This chapter compares strong, linearizable, sequential, causal, session, and eventual consistency. It then applies CAP and PACELC reasoning, quorum mathematics, consensus, and logical clocks to distributed-database design.

Learning Objectives

By the end of this chapter, you should be able to:

  1. Distinguish major consistency models using formal and operational descriptions.
  2. Explain the CAP theorem and the broader PACELC trade-off.
  3. Calculate quorum conditions for read and write operations.
  4. Explain how consensus and logical clocks support distributed coordination.
  5. Select a consistency model for a given application and justify the choice.
  6. Evaluate operational, governance, and ethical consequences of stale or conflicting data.

1. Foundations: Replicas, Operations, and Histories

A replicated database stores logically identical data at multiple replicas. A client operation usually consists of an invocation and a response. An update may be a write, conditional write, transaction commit, or delete; an observation may be a read or query.

A history is the ordered record of operations and their results. For example, client C₁ may write balance = 80, while client C₂ concurrently reads balance = 50 from a lagging replica. Whether this outcome is acceptable depends on the selected consistency model.

Three distinctions are especially important:

  • Safety: nothing bad happens, such as returning a value that violates the model.
  • Liveness: something good eventually happens, such as completing an operation despite failures.
  • Availability: commonly, every request to a non-failed node eventually receives a non-error response. This is narrower and more precise than the informal claim that a system is “always available.”

A consistency guarantee applies to specified operations and failure conditions. It does not automatically guarantee serializable transactions, durable storage, or application-level correctness.

2. A Spectrum of Consistency Models

2.1 Strong consistency

“Strong consistency” is an umbrella term rather than one universally precise model. In practice it often means that reads reflect the latest completed write according to a system-wide ordering. Documentation should therefore name the exact guarantee—such as linearizability, serializability, or read-after-write consistency—instead of using “strong” alone.

2.2 Linearizability

Linearizability is a single-object, real-time consistency condition. Each operation appears to take effect instantaneously at some point between its invocation and response. If operation A completes before operation B begins, A must precede B in the logical order. Concurrent operations may be ordered either way, provided the result is valid.

For a register, if a write of value v completes before a later read begins, that read must return v or a value from a later write. Linearizability is compositional for suitably defined independent objects, but it does not by itself make a multi-object transaction atomic or serializable.

Linearizability is useful for leader election records, inventory counters, uniqueness constraints, and configuration state. Its costs may include coordination, cross-region latency, reduced availability during partitions, and dependence on a reliable ordering mechanism.

2.3 Sequential consistency

A history is sequentially consistent if its operations appear in one sequential order that preserves the program order of each individual process. Unlike linearizability, it need not preserve real-time order between operations issued by different clients.

Suppose client C₁ completes a write before client C₂ begins a read, but the operations are not in the same process. Sequential consistency may permit the read to precede the write in the global sequence, whereas linearizability may not. Sequential consistency is therefore weaker in its treatment of real time, although it still supplies a coherent global order.

2.4 Causal consistency

Causal consistency preserves the order of causally related operations. If event A influences event B—for example, a user reads a post and then comments on it—every observer must see A before B. Concurrent, unrelated operations may be observed in different orders by different replicas.

A causal order can be represented as a partial order rather than a total order. Causal consistency is often effective for collaborative applications, social feeds, messaging, and geo-distributed workflows because it avoids impossible narratives while allowing more concurrency than total ordering.

The system must track causality. It may use vector clocks, version vectors, dotted version vectors, dependency metadata, or hybrid logical clocks. Metadata size and propagation overhead can become significant in systems with many writers.

2.5 Session guarantees

Session consistency provides guarantees within a client session. Common session guarantees are:

  • Read-your-writes: after a client’s successful write, its later reads do not return an older value.
  • Monotonic reads: once a session has observed version v, later reads do not move to an earlier version.
  • Monotonic writes: writes from one session are applied in the order issued.
  • Writes-follow-reads: a write is applied after the versions that the session previously read.

Session guarantees are weaker than global linearizability but often match user expectations. They can be implemented by routing a session to a suitable replica, attaching a session token, or requiring a minimum version on reads.

2.6 Eventual consistency

Eventual consistency guarantees that if no new updates occur and communication continues to recover, replicas eventually converge to the same value. It does not guarantee when convergence occurs, which value wins under conflicting writes, or whether a read sees the newest value before convergence.

Eventual consistency is valuable for caches, reaction counts, product recommendations, and systems where availability and low latency are more important than immediate global agreement. It must be paired with a conflict-resolution policy, such as last-write-wins, deterministic multi-value resolution, application merge functions, or CRDT-based convergence.

“Eventual” is not a synonym for “random.” A well-designed system specifies convergence rules, repair mechanisms, read-repair behavior, anti-entropy, and observability of replication lag.

Comparison of Models

ModelOrdering guaranteeReal-time requirementTypical costExample use
LinearizableSingle order consistent with real timeYesHigh coordinationInventory reservation
SequentialSingle order preserving each client’s program orderNoModerateShared registers
CausalPreserves causal order; concurrent events may differOnly through causalityModerate metadataSocial interactions
SessionGuarantees within a client sessionSession-specificLow to moderateUser-facing reads
EventualReplicas converge after quiescenceNo immediate guaranteeLow coordinationCaches and feeds

3. CAP Theorem: A Failure-Oriented Constraint

The CAP theorem concerns a distributed data system during a network partition. Its terms are:

  • Consistency (C): generally, linearizable results for the replicated object.
  • Availability (A): every request to a non-failed node eventually receives a non-error response.
  • Partition tolerance (P): the system continues operating despite lost or delayed communication between nodes.

Because partitions are possible in real networks, a system that must tolerate them cannot simultaneously provide both linearizability and availability for all operations during the partition. It must either reject or delay some operations, preserving consistency, or answer independently at separated replicas, preserving availability but potentially returning conflicting or stale results.

CAP does not say that a system permanently chooses only two properties. It describes behavior during a partition, and different operations may have different policies. A system can provide strong consistency when connected and degrade to read-only or restricted behavior during failure.

CAP also does not imply that eventual consistency is the only alternative to linearizability. Causal and session guarantees occupy useful intermediate positions.

4. PACELC: Latency and Consistency Outside Partitions

PACELC extends CAP by asking what happens when there is no partition. The principle is:

  • If there is a Partition, choose between Availability and Consistency.
  • Else, choose between Latency and Consistency.

A geo-distributed database may need synchronous cross-region replication to provide linearizable writes. Even without failure, this adds network round-trip time. An asynchronously replicated system may provide lower write latency but expose stale reads. PACELC makes this normal operating trade-off explicit.

The framework is a design lens, not a complete classification. It does not replace analysis of durability, transaction isolation, cost, workload skew, or recovery behavior.

5. Quorum Reasoning

Let a replicated object have N replicas. Let W be the number of replicas that must acknowledge a write and R the number consulted for a read. A common sufficient condition for read-write intersection is:

R + W > N

This ensures that the read set and write set overlap by at least one replica, assuming the overlapping replica has an appropriate version and the protocol returns the newest valid version. To ensure that two successful writes overlap, a common condition is:

2W > N

These inequalities are quorum conditions, not complete proofs of linearizability. Correct version selection, replica freshness, failure handling, conflict rules, and write ordering are also required.

For N = 5, W = 3 and R = 3:

  • R + W = 6 > 5, so every successful read intersects every successful write.
  • 2W = 6 > 5, so every pair of successful writes intersects.

If N = 5, W = 2 and R = 2, then R + W = 4 ≤ 5. A read and a write can use disjoint replica sets, so the read may miss the write.

A majority quorum is often ⌊N/2⌋ + 1, but majority is not universally required. Weighted quorums, geographic quorums, witness nodes, and rack-aware placement may better reflect failure domains. A quorum also does not solve Byzantine faults; authenticated protocols and stronger assumptions are needed there.

Read and write concerns

A database may expose consistency controls such as local, majority, quorum, bounded-staleness, or linearizable reads. The names differ across products, so engineers must inspect precise semantics: whether acknowledgements imply durable persistence, whether reads consult current leaders, and how failover affects guarantees.

6. Consensus and Ordered Replication

Consensus enables a group of nodes to agree on a value or an ordered log despite crash failures and message delays. Paxos and Raft are prominent crash-fault-tolerant consensus families. A consensus group typically elects a leader, replicates commands, and commits an entry after a quorum acknowledges it.

Consensus provides agreement and an ordered decision process; it does not automatically provide a complete database consistency guarantee. The state machine must apply committed commands deterministically, clients must handle retries, and reads must be served in a way compatible with the desired guarantee. For example, a leader may need to verify leadership or consult a quorum before serving a linearizable read.

A replicated state machine commonly follows this flow:

  1. A client submits a command to a leader.
  2. The leader appends the command to its log.
  3. The command is replicated to a quorum.
  4. The quorum-confirmed entry is committed.
  5. Replicas apply the command in log order.
  6. The leader returns a result, subject to durability and acknowledgement semantics.

Consensus sacrifices availability when a quorum cannot communicate. This is a deliberate CAP trade-off, not an implementation defect.

7. Logical Clocks and Causality

Physical clocks are imperfect because of skew, drift, synchronization delay, and uncertain network timing. Logical clocks order events without claiming that their numeric values represent elapsed time.

Lamport clocks

Each process maintains an integer clock L. Before each local event, it increments L. When sending a message, it includes its clock. On receiving a message with timestamp t, the receiver updates:

L := max(L, t) + 1

If event a causally precedes event b, then L(a) < L(b). The converse is not guaranteed: a smaller Lamport timestamp does not prove causality because concurrent events may also receive ordered numbers.

Vector clocks

A vector clock records one logical component per process. For vector V, a local event increments the process’s component. On message receipt, the receiver takes the component-wise maximum and then increments its own component. For vectors V and W:

  • V < W if Vᵢ ≤ Wᵢ for every i and Vⱼ < Wⱼ for at least one j.
  • If neither V < W nor W < V, the events are concurrent.

Vector clocks detect concurrency more accurately than Lamport clocks but require metadata whose size grows with the number of tracked participants. Version vectors use related ideas for replica versions.

Hybrid logical clocks combine physical-clock readings with logical counters. They are useful when systems need timestamps that roughly follow wall-clock time while preserving causality under bounded clock uncertainty. They should not be treated as proof of exact physical simultaneity.

8. Designing with Invariants and Workload Requirements

Consistency selection should begin with invariants, not product defaults. Ask:

  1. What must never happen? For example, stock must not become negative.
  2. Which operations must observe one another?
  3. How long may data be stale?
  4. What happens during a partition?
  5. Can conflicts be merged safely?
  6. What latency and geographic availability are required?
  7. What audit, legal, or safety obligations apply?

A useful design pattern is invariant partitioning. Enforce safety-critical constraints through a strongly coordinated authority, while allowing less critical projections to be eventually consistent. For instance, an order service may use linearizable reservation of scarce inventory, while search indexes and recommendation features update asynchronously.

Another pattern is escrow. A limited resource is divided into rights held by replicas. A replica may spend only its local allocation without global coordination. This preserves a global bound while allowing availability, but transfers between allocations require coordination.

9. Illustrative Case: Multi-Region Ticket Sales

Background

Consider a fictional ticket platform operating in three regions. Customers expect fast browsing worldwide. A concert has 10,000 seats, and selling one seat twice is unacceptable. Search results, seat recommendations, and popularity counters can tolerate short delays.

Problem

If every regional site accepts seat reservations independently during a network partition, two customers may reserve the same seat. If all reservations require synchronous agreement across regions, a partition may prevent legitimate sales and increase latency for every purchase.

Analysis

The seat-availability invariant is stronger than the freshness requirement for browsing. A simple asynchronous last-write-wins policy is unsafe: it can converge to one record while having temporarily confirmed two customers. CAP and PACELC analysis shows that the reservation path must sacrifice availability or latency under some conditions to preserve the invariant.

Approach

The platform uses a consensus-backed reservation service. Each seat belongs to a partition or shard with a leader and quorum. A reservation is committed only after the quorum records it, with an expiration time enforced by the service. Reads of reservation status use a linearizable or leader-confirmed path. Search indexes and popularity counters are asynchronously replicated and may use causal or eventual consistency.

The client uses an idempotency key so that retries do not create duplicate reservations. The system records an audit trail, exposes reservation uncertainty during failover, and refuses a purchase when the responsible quorum is unavailable.

Outcome

Browsing remains globally responsive, while the scarce-seat invariant is protected. During a regional partition, some purchases fail or wait, but the system does not confirm two sales for one seat. Users may briefly see stale popularity counts, which is acceptable and clearly distinguished from confirmed reservation state.

Learning points

  • Consistency can be selected per data type and operation.
  • Strong guarantees should protect explicit business invariants.
  • Eventual projections should never be mistaken for authoritative state.
  • Idempotency and auditability are essential alongside consensus.
  • A graceful failure message is preferable to an unsafe success.

10. Challenges, Governance, and Contemporary Practice

Consistency failures can cause financial loss, unfair access, privacy exposure, or safety incidents. A stale access-control decision may grant or deny privileges incorrectly; a stale medical or industrial reading may create physical risk. Governance should therefore classify data by impact, define maximum tolerated staleness, retain provenance, and test partition behavior.

Teams should monitor replication lag, quorum failures, conflict rates, read repair, stale-read frequency, clock skew, and rejected operations. Service-level objectives should distinguish availability from correctness. Disaster-recovery exercises should test split-brain prevention, replay, duplicate messages, and recovery ordering.

Modern distributed systems increasingly offer tunable consistency, transactional layers over partitioned storage, CRDTs for mergeable data, and geo-aware placement. CRDTs are useful when operations can be designed to converge mathematically, but they do not make arbitrary business invariants conflict-free. AI and analytics pipelines also require consistency choices: training data, feature stores, labels, and online predictions may observe different versions unless snapshot or version contracts are explicit.

Best practices include documenting guarantees per API, returning version or session tokens where useful, making retries idempotent, using monotonic reads for user workflows, separating authoritative records from derived views, and testing under delay, duplication, reordering, and partition. Never infer linearizability merely from low observed latency or from the presence of replication.

Chapter Summary

Distributed consistency specifies what values and orderings clients may observe from replicated data. Linearizability provides a real-time-respecting single-object order; sequential consistency preserves each client’s program order but not necessarily cross-client real time. Causal consistency preserves cause-and-effect relationships, session guarantees preserve important user-centered properties, and eventual consistency prioritizes convergence with low coordination.

CAP describes the unavoidable choice between consistency and availability during partitions, while PACELC highlights the latency–consistency choice during normal operation. Quorum inequalities such as R + W > N help reason about replica-set intersection, but do not alone prove linearizability. Consensus supplies ordered agreement under crash failures, and logical clocks help represent causality without depending entirely on physical time.

Professional design begins with business invariants and failure assumptions. Strong coordination should protect scarce or safety-critical state; causal, session, or eventual models may efficiently serve derived, social, analytical, and cache data. Correct implementation also requires idempotency, conflict handling, observability, auditability, and explicit governance.

Key Terms

Consistency model: Rules defining the values and ordering that reads may observe.

Linearizability: A guarantee that operations appear instantaneous and respect real-time order.

Sequential consistency: A single operation order preserving each process’s program order.

Causal consistency: A guarantee that causally related operations are observed in causal order.

Session consistency: Guarantees applied within a client session.

Eventual consistency: Convergence of replicas when updates cease and communication recovers.

Read-your-writes: A session guarantee preventing later reads from missing the session’s writes.

Monotonic reads: A session guarantee preventing later reads from returning older versions.

Network partition: A communication failure separating parts of a distributed system.

CAP theorem: A partition-time trade-off among consistency, availability, and partition tolerance.

PACELC: A framework describing partition-time and normal-operation trade-offs.

Quorum: A replica subset sufficient to acknowledge or authorize an operation.

Consensus: Agreement among distributed processes on values or an ordered log.

Replicated state machine: Identical deterministic state machines driven by a common committed log.

Lamport clock: A scalar logical clock that preserves causal precedence.

Vector clock: A vector of logical counters capable of identifying concurrency.

Hybrid logical clock: A clock combining physical-time approximation with logical ordering.

Conflict resolution: A rule or mechanism for reconciling concurrent or divergent updates.

Invariant: A property that must remain true throughout system execution.

CRDT: A data structure designed to converge under defined distributed merge operations.

Review Questions

Short Answer Questions

  1. Why is “strong consistency” less precise than “linearizability”?
  2. State the difference between causal consistency and sequential consistency.
  3. What does the condition R + W > N indicate in quorum reasoning?
  4. Why can a Lamport clock establish causal precedence but not concurrency?
  5. Why does consensus often reduce availability during a network partition?

Long Answer Questions

  1. Compare linearizable, sequential, causal, session, and eventual consistency using ordering, latency, and availability considerations.
  2. Explain CAP and PACELC, including why PACELC applies even when no partition is occurring.
  3. Describe how consensus supports a replicated state machine and identify guarantees it does not provide automatically.
  4. Explain Lamport clocks, vector clocks, and hybrid logical clocks, including their principal trade-offs.
  5. Discuss how business invariants should guide consistency selection in a multi-region database.

Analytical / Application Questions

  1. A database has N = 7 replicas, with W = 4 and R = 4. Determine whether read-write and write-write quorum intersections are guaranteed using the conditions in this chapter. Explain the result.
  2. Design a consistency strategy for an online banking system containing account balances, transaction history, notifications, and analytics dashboards. Justify the model chosen for each data category.
  3. A social platform allows users to reply to posts across regions. Analyze which guarantees are needed to prevent a reply from appearing before its referenced post, while preserving low latency during partitions. Propose suitable metadata or protocol mechanisms.

Multiple Choice Questions with Answers

Question 1

Which property distinguishes linearizability from sequential consistency?

A. Linearizability preserves real-time order across clients.

B. Linearizability permits arbitrary conflicting writes.

C. Linearizability guarantees convergence only after quiescence.

D. Linearizability applies only to physical clocks.

Correct Answer: A. Linearizability preserves real-time order across clients.

Question 2

For N = 5 replicas, which quorum pair satisfies the read-write intersection condition?

A. R = 2, W = 2

B. R = 1, W = 3

C. R = 3, W = 3

D. R = 1, W = 2

Correct Answer: C. R = 3, W = 3

Question 3

What does causal consistency require?

A. All operations must have one globally agreed real-time order.

B. Causally related operations must be observed in causal order.

C. Every read must contact every replica.

D. Concurrent operations must always be rejected.

Correct Answer: B. Causally related operations must be observed in causal order.

Question 4

In CAP, what choice is forced during a network partition for a system that continues to tolerate the partition?

A. Durability versus isolation

B. Latency versus throughput

C. Consistency versus availability

D. Replication versus sharding

Correct Answer: C. Consistency versus availability

Question 5

A Lamport clock receiving a message timestamp t updates its local clock using which rule?

A. L := min(L, t) − 1

B. L := L + t

C. L := max(L, t) + 1

D. L := t ÷ 2

Correct Answer: C. L := max(L, t) + 1

Question 6

Which session guarantee prevents a user from observing an older version after observing a newer one?

A. Monotonic reads

B. Writes-follow-reads

C. Monotonic writes

D. Eventual convergence

Correct Answer: A. Monotonic reads

Question 7

For N = 5 and W = 2, what does 2W > N indicate?

A. The condition is satisfied because 4 > 5.

B. The condition is not satisfied, so two write quorums may be disjoint.

C. It proves linearizability.

D. It proves that all reads are current.

Correct Answer: B. The condition is not satisfied, so two write quorums may be disjoint.

Question 8

What is a principal advantage of vector clocks over Lamport clocks?

A. They eliminate all metadata overhead.

B. They identify concurrency under their tracking assumptions.

C. They measure physical time exactly.

D. They guarantee availability during partitions.

Correct Answer: B. They identify concurrency under their tracking assumptions.

Question 9

Under PACELC, what trade-off is emphasized when there is no partition?

A. Latency versus consistency

B. Durability versus security

C. Sharding versus indexing

D. Throughput versus storage capacity

Correct Answer: A. Latency versus consistency

Question 10

Which design best protects a scarce-seat invariant in a multi-region ticket system?

A. Independent eventual writes with last-write-wins for confirmed sales

B. Consensus-backed reservation with quorum commitment and idempotent retries

C. Random replica selection with no conflict policy

D. Asynchronous popularity counters treated as authoritative reservations

Correct Answer: B. Consensus-backed reservation with quorum commitment and idempotent retries

Distributed Database
Chapter 8 of 15