Imagine that you are a product manager at Google Maps and you wish to integrate with DoorDash so that users can order delivery. Your task is to design the API.
- Gerard Kolan
I’ll first start by asking a few clarifying questions to the interviewer.
1. It’s already mentioned that we just want to focus on the order delivery business of Doordash. Are we talking about just food or groceries/parcels/flowers etc. as well? To simplify I’ll assume the restaurant business.
2. Since the entire order fulfillment involves multiple stakeholders like user, driver, restaurants, etc. can I focus on the user first & later move to others if time permits?
3. What is the feature set we are looking at? Get a list of restaurants in the vicinity of the user, Distance of the place from the user’s location & time taken to cover it, Live tracking of Dasher from the app including timely updates of his location, and Updates about any delay due to unforeseen circumstances like excess traffic due to rains. Is this exhaustive or am I missing something?
4. Is there a particular scale we are talking about? I’ll assume a scale of around 30Mn users which will increase in the future & has to be kept in mind while designing.
Now moving on to the solution.
First, we need an API to get the address of the restaurant when the name or coordinates (latitude & longitude) is passed as params.
endpoint: /api/getrestaurants; param: radius of the area to be covered; response: list of restaurants with name & distance from the user’s current location
endpoint: /api/getdistance; param: current location of the user, coordinates of the restaurant; response: returns the distance & time taken to cover the distance
endpoint: /api/livetracking; param: current location of the driver, current location of the user; response: time taken to reach the user’s location
endpoint: /api/displaymap; param: current location of the driver; response: image of the neighborhood where the driver currently is with a pin to its exact location
Whenever the user searches for any restaurant, its distance from the user’s current location is calculated by sending its GPS location along with the restaurant’s coordinates to Google’s API which will tell the distance between the 2 points. The other APIs will have similar explanations. The APIs also need to serve the data securely and hence require authentication with every request especially for livetracking API.
30 Mn users mean 30* 0.285 (Avg. no. of orders in a week per user is 2) * 30 minutes (Avg. order time) / 2 minutes (Avg, refresh time) = 128 Mn API requests for livetracking API which will be maximum.
Since there will be a huge number of requests coming up, the APIs need to be optimized for high performance using the Fragmentation technique & a throttle limit of around 1000 requests per second.
Error states should also be covered and responses should be sent accordingly. Example: the restaurant does not exist, unable to fetch the GPS location of the driver, incorrect values in the param, etc.