educative.io

Broadcast a message to all WaitingUserService servers

Broadcast a message to all WaitingUserService servers that are holding waiting users of that Show to figure out the longest waiting user. Consistent Hashing scheme will tell what servers are holding these users.

why do we need to broadcast to all servers. aren’t we partitioning by show id. then we only need to send to the server that covers the relevant show id.

Hi @Dewey_Munoz

We will broadcast a message to only those servers that are holding waiting users, not broadcasting message to every server. Since data is partitioned on different servers, after getting the longest waiting users from each server will then prioritize who will be served first.
If you face still any confusion, feel free to ask.

Happy learning,

@Shaheryaar_Kamal, so what is the partition key for the WaitingUserService? if it is ShowID, then all the users for a specific show wouldn’t be on just one server?

as far as I know, consistent hashing helps only with two things:

  • to make it easier to add/remove servers
  • virtual nodes, in the context of consistent hashing, help to almost uniformly distributes the hashes amongst the servers

so if ShowID = 32 -> Hash=3ERTF -> it would always end up in just one server (S1). that server can then choose to replicate its data on k more servers, but that’s just replication, it doesnt help with the workload of server S1.

correct me if i am wrong.

maybe its better not to use the ShowID as the partition key, how about this:

for the ActiveReservationsService# -> partition key =bookingID -> on the server: Hashtable{BookingID, timestamp}
(these servers dont even need to know the ShowID, they just need to know the current time and talk to DB to be able to expire a booking)

for the WaitingUsersService# -> partition key=UserID
on the server: Hashtable{ShowID, LinkedhashMap(UserID, wait_startTime)}

then for ShowID = 32, we query all the WaitingUsersService servers, aggregate the results, to find the longest waiting user…

Hi @Dewey_Munoz
Consistent hashing doesn’t mean only replicating the data. It also includes data partitioning. You can check out this lesson for more details. And in your case i.e., replication, yes you are correct :slight_smile: , but through consistent hashing data is also partitioned(the process of distributing data across a set of servers).

@Shaheryaar_Kamal - Still, why do we broadcast? The result from each server will be the same. Why not just call one server?