Careeroza
Write & Read
Write and Read Concerns
๐น 1. Write Concern
Write Concern defines how safely data is written to the database.
It decides:
- How many nodes must confirm the write
- Whether data is fully saved before success is returned
๐น Common Write Concern Levels
1. w: 1 (default)
Write is acknowledged by primary only
- Fast
- Less safe
2. w: "majority"
Write is confirmed by majority of nodes
- Slower
- Very safe
3. w: 0
No acknowledgment
- Very fast
- Risky
๐น Extra Options
- j: true โ ensures data is written to disk (journal)
- wtimeout โ timeout for write
๐น 2. Read Concern
Read Concern defines how consistent the data is when reading.
It decides:
- Whether you read latest data or possibly stale data
๐น Common Read Concern Levels
1. local (default)
Reads data from node without guarantee of replication
- Fast
- May not be fully consistent
2. majority
Reads only data confirmed by majority
- Strong consistency
3. linearizable
Reads most recent data (strict consistency)
- Slowest
- Strongest guarantee
๐น Why They Matter
- Balance between performance vs data safety
- Important in distributed systems
Simple Understanding
- Write Concern โ how safely data is written
- Read Concern โ how consistent data is read
Example Idea
- Banking app โ use majority (safe)
- Social media โ use default (fast)