skip to content

What is the difference between MongoDB's readConcern levels local, majority and linearizable?

level: seniorimportance: should knowfreq 48%

answer

  1. one level can show writes that later vanish
  2. durable is not the same as newest
  3. the strictest level talks to the primary only
  4. single-document filter, and bring a timeout

basics

~20 s

local returns whatever the queried member has, including writes that may later be rolled back. majority returns only majority-committed data, which is durable but can be slightly behind. linearizable is primary-only and confirms in real time that the returned data is majority-committed.

solid answer

~50 s

Read concern controls **which version of the data a read is allowed to see**, independently of which member serves it. `local` returns the most recent data on the queried member with no durability filter, so it can show a write that a later election discards. `majority` returns only data that has been acknowledged by a majority — nothing you read can be rolled back — at the cost of possibly lagging the primary's newest writes, because each member serves its own view of the majority-committed data. `linearizable` is the strongest: it runs on the primary only, applies to a query filter matching a single document, and confirms before returning that the primary is still primary and that prior writes are majority-committed, so the result reflects real time. It is materially slower and should always carry a `maxTimeMS`. A fourth level, `snapshot`, reads from a single consistent point-in-time view of majority-committed data.

code

javascript · 7 lines
javascript
// Durable read: nothing returned here can be rolled back
db.accounts.find({ _id: "a-1" }).readConcern("majority")

// Real-time read on a single document, always bounded
db.accounts.find({ _id: "a-1" })
  .readConcern("linearizable")
  .maxTimeMS(2000)

go deeper

for a junior

Know that read concern decides which version of the data a read may see, and that the default local can briefly show a write that a failover later erases.

for a middle

Explain the majority commit point: why majority excludes rollback-eligible writes, and why that makes it durable but potentially behind the primary's newest state.

for a senior

Show where each level belongs in a real system — which reads gate irreversible actions and need majority, why linearizable is primary-only, single-document and needs a timeout, and how read concern interacts with the member you chose to read from.

for a principal

Own the default read-concern policy and its cost model: which service tiers pay for stronger reads, how the choice interacts with topology and latency budgets, and how to keep linearizable from spreading into paths that cannot afford it.

## Read concern versus read preference These are two independent dials that beginners conflate. **Read preference** chooses *which member* answers. **Read concern** chooses *which version of the data* that member may show you. You can send a `majority` read to a secondary, or a `local` read to the primary; the combination is what determines what you actually see. ## `local` The default for most reads. The member returns the most recent data it has, with no check on whether that data has replicated anywhere else. On a primary this is the freshest possible view. Its weakness is precise: a write that has been applied on the primary but has not yet reached a majority is visible, and if the primary steps down before that write becomes majority-committed, the write is discarded during rollback — so a client can genuinely read a value that later ceases to have ever existed. That is acceptable for most application reads and unacceptable for a read whose result triggers an external, irreversible action such as shipping goods or calling a payment API. ## `available` A close relative of `local`, relevant on sharded clusters. It behaves like `local` but skips the extra work of filtering out orphaned documents — documents left on a shard after a chunk migration. It offers the lowest latency and the weakest guarantee, and it can return duplicates for documents in flight between shards. It is not usable with causally consistent sessions. ## `majority` The member returns only data that has been acknowledged by a majority of the set — the **majority commit point**. Nothing you read at this level can be rolled back later. The subtlety that catches people: `majority` is a *durability* filter, not a *freshness* guarantee. Each member maintains its own view of what is majority-committed, so a `majority` read on a lagging secondary can be well behind, and even on the primary a `majority` read can be slightly behind the primary's newest local writes, because those writes have not yet been confirmed by other members. "Cannot be rolled back" and "is the newest value" are different properties, and `majority` gives only the first. In currently-shipping versions majority read concern is always available and cannot be disabled. ## `linearizable` The strongest level, and the most constrained: - It is accepted **only on the primary** — it cannot be combined with a read preference that allows secondaries. - Its guarantee applies to a query filter that **uniquely identifies a single document**; it is not a level for range scans or aggregations. - It is not usable inside multi-document transactions. Before returning, the primary confirms that prior writes have been majority-committed and that it has not been superseded — in effect proving it is still the primary at the moment of the read. That makes the result reflect the real-time ordering of writes, which `majority` alone does not: with `majority` you could read from a member that has not learned about a newer, already-committed write. The cost is a round trip to a majority of members on the read path, and a read that can block indefinitely if the primary cannot reach a majority. **Always pair it with `maxTimeMS`.** Reserve it for the handful of reads that genuinely need a real-time answer, such as a leader-election check or a critical uniqueness test. ## `snapshot` Reads from a single, consistent point-in-time view of majority-committed data, so multiple reads see one coherent state rather than a moving target. Its natural home is multi-document transactions, and recent versions also allow it on certain read commands outside transactions, optionally pinned to a specific cluster time. A snapshot may be slightly behind the newest data by design — consistency across the read, not maximal freshness, is the point. ## Choosing A workable default policy: - Ordinary application reads: `local` (the default) is fine. - Reads that gate an irreversible action, or that must not show data a failover could erase: `majority`. - A read that must reflect the true current state in real time, matched on a unique key: `linearizable`, with a timeout, used sparingly. - Multiple related reads that must agree with each other: `snapshot`. And remember the interaction with read preference: `majority` on a secondary bounds durability but not staleness. If freshness is what you actually need, that is a question of where you read and whether you are using a causally consistent session, not of raising the read concern level.

  • Why can a readConcern majority query on the primary still return data older than the primary's latest write?
    Because `majority` returns the majority commit point, not the primary's local state. A write that the primary has applied but that has not yet been acknowledged by enough other members is deliberately excluded, precisely because it is still rollback-eligible. Durability and freshness are different properties, and this level buys the first.
  • Why does linearizable read concern require a filter that matches a single document?
    Its guarantee is about the real-time ordering of operations on one document — that the value returned reflects the latest majority-committed write to it. There is no equivalent guarantee for a multi-document result set, whose members would be read at different instants, so MongoDB restricts the level to reads identified by a unique filter.
  • When would you choose readConcern snapshot over majority?
    When several reads must agree with each other. `majority` is evaluated per operation, so two successive reads can straddle a write; `snapshot` pins them to one point-in-time view of majority-committed data. It is the natural level inside multi-document transactions and for report-style reads that must be internally consistent.

saying these in an interview costs you the question

  • Says readConcern majority guarantees the freshest data
  • Confuses read concern with read preference
  • Uses linearizable reads on ranges or aggregations
  • Runs linearizable reads without maxTimeMS
  • Believes local reads can never return data that later disappears

context