educative.io

Data Sharding with Many-To-Many relationship

Hi,

I have a question regarding data Sharding on Many-To-Many relationship.

Let’s say we are building a chat app and we have two objects: User and Group, which are Many-To-Many relationship. Now we are going to shard the database and we basically have two options:

  1. Shard by userId
  2. Shard by groupId

If I go with either approach, how do I store the other object ?

Eg: I decide to shard the database using groupId. When what should I do with the group object ?

  1. Duplicate group object in each shard where this shard has user in the group
  2. Store group object somewhere else (A standalone database maybe) and then store User_Group relations in each shard

I think both methods has some drawbacks but I can’t find more information online regarding this point. Does anyone have ideas how to solve this issue?

Thanks

Sorry I made a mistake in the description.\

The Eg should be: I decide to shard the database using userId.Then what should I do with the group object and how should I store all of them ?