educative.io

A few questions about fulfillment, concurrency and data store modelling

I apologize for all the questions , the design is great but it led me to ask myself a lot of questions which i put in here.
Lets say the Quad Tree lookup comes back with 10 drivers that can fulfill a riders request. When the notification is sent to the drivers, say 3 of them accept this request. The acceptances come back , how do we pick one and only one and avoid issues with concurrency? Sending a cancellation request seems to a poor customer service experience, correct? Also is the design missing a ride metadata store?

Also, “The Aggregation server will send a notification to the top (say three) drivers simultaneously, … the Aggregator will request a ride from the next three drivers from the list”. In this case , how do you know where are the next three drivers? do you have to persist the driver list? or are you going to query again ? if so how do you know the list of drivers the request has already been sent to.

While the quad tree design is awesome, i think storing this in a MySQL table solves the issue in a simple manner doesn’t it? Let’s say we store this with DriverId,LocationId,TimeStamp in a MySql table. Given there are say 1M drivers in the United States this is not a whole lot to query upon. You can create a secondary index on LocationId and query for all Driver Ids that match a location id. I understand this might not work for Yelp but for uber it seems like a reasonable solution given there cant be more than say 100 cars in a cell (or the cell will be covered by cars). The above table can answer questions for both a) given driver what is the current cell id and for updating it and b) given a cell get all drivers.

Thank you for taking the time to respond to my questions.

Hi Sandhya,

We are looking into your query and will get back to you soon.
Thank you for reaching out to us. Please let us know if you have any further queries.

@sandhya We can have a ride details service talking to a ride details storage(can be cache/DB). When a user asks for the booking a ride, we send the notification to top 3 drivers and give them sometime say 15 sec to respond. If they don’t , we persist their ids in a map say M1 and make a request again fetching the results (this will not be time taking as the user was pulling data every 5 sec, instead now data is pulled by this service ). We select the next three drivers who are not in M1 and send the booking request. Next when a ride is booked, we can flag data in the quad tree and keep updating the location of driver and customer here itself instead of the regular process of updating in table and tree (as once the ride is booked no one else wants to look at that driver) and also using a pub/sub keep updating customer and driver. When a ride ends we delete all the data from here and insert it into tree and table for others to start seeing.
For handling concurrency problems, we can insert a customer-driver row in the storage as soon as the user books a ride. We can use locks(postgres/redis locks).