I guess it should again add this customer to these new entrying driver’s subcription list.
And here comes a new question, what to do with the driver leave the rider’s area?
I can think of 2 solutions.
-
Every time the rider pulls the nearby driver list, the backend will do 2 things,
a. add this rider to the diver’s consumer’s list.
b. send back this list to the client backend
Then, the client’s backend can filter the driver is not in the latest list (because we have not delete it from the driver’s list). To clean up the stale data in the driver’s consumer’s list, we need to set a time-to-live parameter for every rider in the list, e.g. after 10min this rider will delete from the list(we can maintain this with a set data structure in case we add duplicate rider in to the same consumer’s list). By this way, we achieve eventually consistence. The cons are we use extra resources in client’s backend and also the publish useless information to rider who does not need it.
-
Every time the rider pulls the nearby driver list, the backend will do 2 things,
a. add this rider to the diver’s consumer’s list.
b. we also maintain a reverse mapping from rider to driver info, let’s call it rider2driver mapping
Every time the rider pulls the nearby driver info and call this new rider2driver mapping, we first delete every this rider from all the driver’s consumer list using the old rider2driver mapping, and then we add the rider to the driver’s consumer list using the new rider2driver mapping.
pros: here is we don’t have stale data any more and will not send useless driver update to rider does not need it.
cons: this will limit our through put, we have more write/update operation on the driver’s consumer list and will have exclusive lock on it(writing lock).
I think performace is more important, so I personally would choose the first solution.