I have a huge number of users so I am needed to shard the databases in n shards. So to proceed with this I have below options-
Divide my data in n shards basis userId modulus n operation. i.e. if I have 10 shards userId 1999 will be sent to 1999%10=9th shard
Problem- The problem with this approach is if the number of shard increases in future reference to previous will not be maintained.I can maintain a table with UserId and ShardId
Problem- If my users increase in future to billions I'll need this mapping table to be shared which doesn't seem to be good solution.I can maintain static mapping in code like 0-10000 in Shard 1 and more on.
Problem-- With the increase in shards and Users Code needed to be changed more often.
- If any specific User in shard has huge data It'd get difficult to separate out the shard.
So, these are the three ways I could have found but all having some problem. What would be an alternate or better approach to shard the MySQL tables which can compensate with increased number of shards and users in future.