educative.io

Educative

Sharding on UserId? How does the other user get their messages?

The recommendation is to shard on user id but doesn’t that mean that the other user will not be able to easily retrieve their messages? Otherwise you need to replicate the messages per user? I’m a little confused by this recommendation.

There are a few mistakes in your problem statement, but according to my understanding, the answer to your question can be, “We can introduce a software load balancer in front of our chat servers; that can map each UserID to a server to redirect the request.”

A load balancer doesn’t help in this case. The data is sharded on the userid. A load balancer would only help you distribute the load across the shards.

I had the same question.

I agree with @Samer_Abraham.

If you partition and store messages per UserId, you will have to query multiple shards in most cases to build up single one-to-one chat because you need to query messages sent to “me” as well as to the “other” person. UNLESS you decide to duplicate message for both users, which will double the storage requirements.

@fahim Can you please clarify or include someone who can assist?
Thanks in Advance