Is there a way to have one database (MongoDB) that is able to support multi-region applications with minimal latency?
Asked
Active
Viewed 192 times
1 Answers
1
this is a perfect use case for use replica set with 3 members (one per region)
One of them become a master
- that means it will receive all writes and propagate them to others.
This also introduce extra layer of safety as data will be in more than one place, so network outage in one area will not stop entire application.

profesor79
- 9,213
- 3
- 31
- 52
-
If I have three members. Does it mean that I will have 3 differnt separate connection string? Or mongo itself is able to detect which region is the closest. – Shi Wei Jun 12 '16 at 06:54
-
No, replica set use one connection string listing all servers. The primary one is only allowed to write data, but application can read from secondaries – profesor79 Jun 12 '16 at 07:32
-
oh, I just found out that mongoose has this function called read "nearest" preference. Does this function automatically read data from the nearest replica set based on my client's location? – Shi Wei Jun 14 '16 at 03:14
-
Thanks @profesor79 , one last question. I am so eager to mark this as correct. This solves the latency issues on gets. What about writes and updates? Since I am only able to write to one primary (i.e. Singapore as primary, writing from SG to SG has minimal latency), theoretically, other regions will experience latency with write and update commands. Am I making a wrong assumption here or we will need to have other clusters with a primary in the region to handle the write and updates. – Shi Wei Jun 14 '16 at 09:17
-
there could be only one primary and for data safety we need to use `writeConcernt:majority` which will have impact on all clients as confirmation will be given only when write will be on 2 servers - so we can assume that write latency will be similar for all clients as it will touch twoseparate datacenters – profesor79 Jun 14 '16 at 09:33