Zones and regions
Keep some customers' data on the machines of one region with zones.
Keep some customers' data only on the machines of one region, for example to meet a data residency rule. Zones restrict the replicas of some shard key intervals to some nodes.
Requirements
- A collection with a shard key that carries the region, such as
{ region: 1, _id: 1 }. - A user with the privileges of the sharding commands.
Assign the nodes to the zone
Each node is a shard whose name is the one listShards shows. Assign the nodes of that region to the eu
zone:
JavaScript
sh.addShardToZone("<shard>", "eu");Assign the interval to the zone
JavaScript
sh.updateZoneKeyRange("shop.orders", { region: "eu", _id: MinKey }, { region: "eu", _id: MaxKey }, "eu");Check
teseladb admin ranges --collection shop.orders shows that the eu ranges only have replicas on the nodes of the zone.
Common problems
- With every replica of a range in one region, each write waits for a majority of that region. With replicas in distant regions, the write waits for the network between them.