educative.io

Question on the Data Sharding Section

In the initial section where we define our data model, the article suggests using a NoSQL wide column store where the rowID would be user_id and then we can store a list of user_follows and user_photos.

In the data sharding section, the article suggests sharding by photo_id. Does this imply that our wide column store rowId would now be the photoId? In this case, wouldn’t it be extremely difficult to get the list of photos/user_follows for a given user?

Thanks!

2 Likes

I have the same question, it’s very unclear how this approach would fit the wide column store.

I had the same question too. It’s unclear what the actual design is supposed to be.

I am not clear on how will we find a shard number through “PhotoID % 10” ? can so ebody explain what is meant here

Consider there is a list of photos with photoID as 1256, 1373, 1739, 1920.
In this case,
PhotoID 1256 - 1256 % 10 = 6 - This photo is stored in shard 6
PhotoID 1373 - 1373 % 10 = 3 - This photo is stored in shard 3
PhotoID 1739 - 1739 % 10 = 9 - This photo is stored in shard 9
PhotoID 1920 - 1920 % 10 = 0 - This photo is stored in shard 0
PhotoID 1743 - 1743 % 10 = 3 - This photo is stored in shard 3
i.e., we store the photo based on the last digit of the photoID. This will work if we are using 10 shards (as we are mod 10).
I hope this point is clear regarding how shard number through “PhotoID % 10” works.