0

I have a mongo cluster as follows:

  1. 3 shards, located in the 3 main global regions (APAC/EMEA/AMER)
  2. The shardKey is "Region".
  3. 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!

2
  • Is your full shard key only the field 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
  • The full shard key is Region+"externally formed unique identifier". I am trying to achieve data locality in fact guided by that tutorial :) was just curious as to what was happening under the hood. seems answered now as per the below. – ubienewbie Aug 2 '17 at 7:12
0

It does the second option 'route the insert to the correct regional shard directly`.

See this answer for details.

Where to insert data after sharding?

More resource:

https://docs.mongodb.com/manual/core/sharded-cluster-query-router/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.