Skip to content

Instantly share code, notes, and snippets.

@tiry
Last active May 8, 2018 14:57
Show Gist options
  • Save tiry/4069333e430b41510a67d7d83bad74ae to your computer and use it in GitHub Desktop.
Save tiry/4069333e430b41510a67d7d83bad74ae to your computer and use it in GitHub Desktop.

Why does most of the traffic go to the primary MongoDB node?

In a MongoDB cluster:

  • all write traffic has to go to the primary node
    • it is responsible for dispatching to the other nodes
  • by default, most of the read traffic also goes to the primary node
    • this is the default and safest option

You can alter that behavior by using Read and Write concerns

Write Concern

Allows you to define how you want writes to be handled by the MongoDB cluster. The write operation will always be done first on the Primary node, but then the question is to know if you also wait for the acknowledgment on the secondary (none, all, majority ...). This setting allows you to define if you want to favor performance over consistency.

Read Concern

Allow you to define if you want to read operations to be dispatched to secondaries or not. Reading from secondaries may result is some inconsistencies, depending on how you configured write concerns. Here again, this settings allows you to define if you want to favor performance over consistency.

You can define Read and Write concern as part of the connection string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment