Design Uber

 Design Uber

Another possibly interesting problem here. Let's start diving right into this. What is uber. Uber is basically a ride requesting platform where a user can request for a ride and a driver can accept or deny the requested ride. In a nutshell that's all there is when it comes to Uber. So let's now talk about the functional requirements and the non-functional requirements in uber.

Functional Requirements: 

It's pretty obvious that when we talk about functional requirements : 
1. User should be able to request for a ride, put the source and destination, get the ETA and the price estimates.
2. User should be able to send the request for the ride after looking at the estimates.
3. Driver should be able to accept the ride after looking at the request from the user.

Non-functional requirements: 

1. When it comes to ride matching, the system needs to be consistent.
2. All other requirements we can have a highly available system.

Core Entities: 

1. Ride
2. Customer
3. Driver
4. Location


API: 

Before I go to the API's let's just understand the flow of the system properly. We will have a customer and that customer tries to open the app. Once he opens the app, he puts the pick up location and the destination. After putting that, uber will give that a customer a price estimate based on the distance and the ETA. So which means that there is an api in the back end that's giving the price estimate. 

1. Price Estimate

Now after the price estimate is done, the customer clicks on the ride and then the app needs to find the nearby drivers. After that, the customer clicks on book a ride. That's when uber will start sending notifications to the nearby drivers for the ride. When we say click on book a ride, there's something that happens. So there has to be an API for booking a ride which will send notifications to the nearest uber location. 

One thing to note is that, suppose you have 100k people coming out of a taylor swift concert, one needs to recognize that there would be possibly 10 drivers nearby. When 100k people try to request for a ride, only one request should go to each driver. The other people should be in the waiting queue. This means that one driver will only get one request at a time. 

Secondly, understand that driver needs to update the location periodically in the database. So we'll need geohashing or quad tree to update locations. 

Now let's go to API design: 


GET /ride/priceestimate

{
source,
destination
}

A ride id will be created.
return a price estimate like 10$, 20$, etc. This will be shown on the screen. 

POST /ride/book
{
rideId:
}

A notification will be sent to the drivers.They can confirm the ride if they would like to. 


PATCH /driver/confirm
{
status: accept/reject
}
This means that the driver can either accept or reject that particular ride. 

POST /driver/location/update
{
source,
destination
}

PATCH /driver/pickup
{
status: pickup/dropoff
}

Every 20seconds we can have the driver update their locations. So as to find the people in the nearest location.

High Level Design: 

So, what's the higher-level design out here. One part of design is this. We have 2 clients. One is customer and the other is a driver. 



Unfortunately the picture is not that visible. https://excalidraw.com/#json=VLb8-1P-QiA5QVPXFrRfO,bX7cCnIu7qZ87D6e96xyFQ

This is the link to ExcaliDraw. 


 









Comments

Popular posts from this blog

System design topics

Design TicketMaster