Skip to content
LESSON 45 / 50Advanceddistributed

Read Concerns: local vs majority vs linearizable vs snapshot

Read Concerns control the consistency and isolation of data read from MongoDB: from fast uncommitted local reads to strictly serializable linearizable queries.

Interactive Engine Simulator

Replica Set Raft Consensus & Heartbeat Election Lab

Simulate 3-node replica set heartbeats, failovers, oplog replication, and write concern guarantees.

Consensus Term
Term 1
Monotonically increasing
Voting Quorum
2 / 3 Majority
Strict floor(N/2) + 1
Heartbeat Interval
2000 ms
10s election timeout
Write Concern
node-1PRIMARY
Host:mongo-node-1:27017
Oplog Sequence:#1045
Voted Term:Term 1
Accepts all driver write and read traffic (ReadPreference: primary).
node-2SECONDARY
Host:mongo-node-2:27017
Oplog Sequence:#1045
Voted Term:Term 1
Tails primary local.oplog.rs in background thread.
node-3SECONDARY
Host:mongo-node-3:27017
Oplog Sequence:#1045
Voted Term:Term 1
Tails primary local.oplog.rs in background thread.
REPL_LOG:Replica set stable on Term 1. Primary node-1 actively serving writes.

1. Formal Definition & Architecture Intent

A Read Concern specifies the consistency and isolation guarantees of read operations across a replica set. The five levels are: "local" (default: returns node's latest data, may be rolled back), "available" (same as local, fastest in sharding), "majority" (returns data committed to a majority, immune to rollbacks), "linearizable" (guarantees real-time serializability), and "snapshot" (point-in-time ACID snapshot).

2. Explain Like I'm 5 (Mental Model)

"local" is listening to rumors in the hallway: usually true, but might turn out false. "majority" is waiting for the official school newspaper to confirm it. "linearizable" is calling the principal on the phone right now to verify before taking another step.

3. Real-World Architecture Example

Financial ledger reading an account balance that must never be rolled back.

Sample BSON Documents:
Collection: db.accounts
{
  "_id": "acc_01",
  "balance": 50000,
  "readConcern": {
    "level": "majority"
  }
}

Reading with level: "majority" guarantees the balance cannot be reverted by a primary failover.

4. MQL Implementation Steps

Step 1: Query with majority read concern
db.accounts.find({ _id: "acc_01" }).readConcern("majority");
Guarantees the returned data is committed to a majority of replica members.
Step 2: Query with linearizable read concern (prevents stale reads from partitioned primaries)
db.accounts.find({ _id: "acc_01" }).readConcern("linearizable");
Primary contacts a quorum of peers before returning to confirm it is still the true primary.

5. Critical Engineering Rules

Rule / ConstraintUnderlying Reason & Impact
localFastest; returns current node data. Vulnerable to reading data that gets rolled back.
majorityReads from in-memory WiredTiger snapshot representing majority-committed state. Immune to rollbacks.
linearizableExecutes quorum check; blocks until current primary verifies it has not been deposed by a split-brain.
snapshotOnly usable inside multi-document transactions. Reads consistent point-in-time snapshot across all collections.

6. Deep Dive: How "linearizable" Prevents Phantom Reads from Deposed Primaries

Suppose a primary is partitioned off from the network. A new primary is elected, but the old primary does not know it yet. A client reading from the old primary with readConcern: "local" would read stale data. With readConcern: "linearizable", the primary MUST successfully communicate with a majority of members BEFORE returning the read result. If it is deposed, the read fails, preventing stale reads.

// Linearizable read syntax:
db.locks.find({ resource: "engine_mutex" }).readConcern("linearizable");
Production Warning: Linearizable reads must target the Primary node only and add latency equal to a network round-trip.

7. Architectural Trade-offs

Advantages
  • •majority read concern guarantees that data read by the application will never be rolled back
  • •linearizable read concern provides true recency guarantees even during active network partitions
  • •snapshot read concern delivers ACID snapshot isolation across collections in multi-doc transactions
Disadvantages & Gotchas
  • •linearizable reads incur quorum network round-trip latency on every read operation
  • •majority reads require WiredTiger to maintain in-memory historical snapshot versions

8. Technical Interview Questions

Q1: What is the risk of using readConcern: "local" on a primary node?

With readConcern: "local", the query returns the latest data from the primary's memory, which may include writes that have not yet been replicated to secondaries (issued with w: 1). If the primary crashes before replicating those writes, the data is rolled back, meaning the client read "dirty" data that ultimately disappeared from the database.

9. Staff-Level Ready Answer

"Read Concerns govern read isolation. "local" returns the node's latest data but risks reading un-replicated writes that could roll back. "majority" reads from WiredTiger's majority-committed snapshot, guaranteeing the data will never be rolled back. "linearizable" verifies primary quorum in real-time. "snapshot" provides ACID point-in-time isolation inside transactions."

10. Quick Knowledge Check

Which Read Concern level is required inside multi-document transactions to guarantee consistent point-in-time reads across collections?