← Lessons

quiz vs the machine

Gold1410

Databases

The Read and Write Concerns

Tuning durability and consistency per operation.

6 min read · core · beat Gold to climb

Choosing Your Guarantees

In a replica set you can tune how durable a write is and how fresh a read is, per operation. These knobs are write concern and read concern.

Write Concern

Write concern says how many members must acknowledge a write before it is reported as successful.

  • A concern of one acks once the primary applies it, fast but losable on failover.
  • A majority concern waits for a majority of members, so the write survives an election.
  • It can pair with a journal flag to require the write is on durable storage.

Read Concern

Read concern says how consistent the data a read returns must be.

  • local returns the most recent data on the queried node, which may roll back.
  • majority returns only data acknowledged by a majority, so it will not be rolled back.
  • linearizable returns the latest majority committed value for a single document.

Stronger concerns add latency. Pairing majority write with majority read gives durable, non rolling back behavior.

Key idea

Write concern sets how many members must ack a write and read concern sets how committed read data must be, with majority on both giving durable rollback safe results at higher latency.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a majority write concern guarantee?

2. What can a local read concern return that majority cannot?