HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

mongodb: replica-set with load balancer

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
withreplicamongodbloadbalancerset

Problem

Is there an option for load balancing with mongodb replica sets?
I am not asking for a HAProxy or similar, but for a built-in feature from mongodb.
Could not find tips for this in the docs.

Solution

If you are using sharding, then the "load balancer" is the mongos process - actually it is more like a router - it keeps an in-memory copy of the config database and can make decisions based on the shard key.

If you mean load balancing across identical replica sets or across the members of the set, then there is a feature request to have mongos handle that scenario too (https://jira.mongodb.org/browse/SERVER-1594), however given how the drivers operate it is not really necessary (it would make the drivers less complex though).

In a single replica set, you cannot distribute writes, they all must go to the primary. You can distribute reads to the secondaries already, via Read Preferences as you deem appropriate. The driver keeps track of what is a primary and what is a secondary and routes queries appropriately.

Context

StackExchange Database Administrators Q#19921, answer score: 11

Revisions (0)

No revisions yet.