I have a mongo cluster as follows:
- 3 shards, located in the 3 main global regions (APAC/EMEA/AMER)
- The shardKey is "Region".
- Each region has a mongos running locally, "close" to its users, "close" to its mongods.
Question: when the mongos receives an insert request for a document who's region is not the mongos "close" region, does the mongos:
a) route the insert into its "close" regional shard then let the balancer sort out moving the document to its correct shard. OR b) route the insert to the correct regional shard directly.
It seems to me that a) would give faster inserts than b) but takes longer for the database to settle down to its eventual state.
Which one is what mongos actually does?
Thanks!
Region
with 3 values? If so, this is a poor choice for sharding as your maximum number of shards will be 3 and this shard key will not support useful queries on data. Presumably you have a more relevant (and higher cardinality) identifier which you would be querying on more commonly, so you could use a compound shard key instead. For data locality you want to look into zone sharding which allows you to associate ranges of shard keys to specific shards: docs.mongodb.com/manual/tutorial/…. – Stennie Aug 1 '17 at 14:10