What does the primary node do?
The primary node in a Replica Set is the main node that accepts every write operation and acts as the source of data for the other nodes. It's the one that defines the "current state" of the collections at any given moment.
The primary's main responsibilities
- Accepts all writes
Every
insert,update,deleteoperation always goes to primary first. Secondaries never write directly, they only copy. - Records changes in the oplog Primary writes every change to the oplog, an operations log. Secondaries read it and replay the same operations on themselves, staying an exact copy.
- Handles reads by default
If the client hasn't changed
readPreference, reads (find,aggregate) also go to primary. That's how consistency is achieved under the read your own writes principle. - Takes part in elections and quorum management
If the Replica Set has a failure and primary disappears, the other nodes hold an
electionand pick a new primary. But while it's alive, it's the center of replication.
Primary's defining characteristics
- the sole write point in the Replica Set
- the source of truth (the actual state)
- every other node stays synchronized with it
Why a primary is needed in this model
To ensure:
- data consistency, no conflicting writes from different nodes
- simplified replication, changes propagate from a single center
- automatic failover, a new primary is elected on failure, and the system doesn't sit idle
Summary
Primary is the central node that accepts writes, records them in the oplog, and serves as the synchronization source for every secondary. It keeps the data current and drives the main flow of operations in the Replica Set.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.