Uber system design
Company: Uber
Role: senior software engineer
Interview Stage: Onsite
Original Post Content:
Functional requirements ๐
User should be able to book a ride .
System should be able to request nearby drivers within 1 kms .
Should provide the ETA of reaching the destination .
User should be able to make payment after trip ends .
**Non Functional requirements **:
Scalable
Fault tolerant
Highly available
Low latency
**Capacity estimation **
100 million users
10 M DAU
20 million trips per day
1 trip storage 1 KB
Driver location storage per day 500 KB
Data stored for 5 years
QPS : 200
Peak QPS : 400
Total storage cost for trip per day = 20 million *1 KB = 20GB
Total cost for 5 years = 40 TB
*Write heavy system *.
Google S2 library
We will use here Google S2 library to check the nearby cabs which divides the earth in small small cells say 100 mtrs .Let us assume the user is at 3 cell . So ,if our SLA says to look for 1 km radius that how many drivers are available so we can get the drivers at 1 and 4 cell .
We will use here Google S2 library to check the nearby cabs which divides the earth in small small cells say 100 mtrs .Let us assume the user is at 3 cell . So ,if our SLA says to look for 1 km radius that how many drivers are available so we can get the drivers at 1 and 4 cell .
1https://assets.leetcode.com/users/images/6363db22-714d-43c9-a67b-286ce3cd35e5_1719080396.1283402.png1https://assets.leetcode.com/users/images/4f1bd7a7-f1d4-4740-a46a-63d424ecedb5_1719080444.410902.pngDrivers app:
Drivers keep updating the location every 5 seconds via kafka rest api to the system . The location is in the form of tiny cells with cell id . The location will be saved in Nosql and copy of the same will be sent to BigQuery for Analytics like fraud detection , ratings etc.
Ride booking :
User can request a ride . The request reaches to load balancer which acts as a reverse proxy and redirect the request to Demand service . The communication here is via Websockets .
Demand service makes an entry in the trip DB and ask the supply service for match .
Supply service checks if there is any nearby rider in the nearby cells . Once driver accepts it then it calculates the ETA and fare .
The server keeps sending the message to rider and driver using websockets . User also gets the push notification using firebase cloud messaging, a provider used in android for push notifications .
Once the trip ends , the user makes a payment and trips reaches the terminated state .
Every week . there is an archival process which archives the all completed trips from RDBMS trips DB to Cassandra for scalability and to improve performance of RDBMS
Availability :
The entire dispatch component which has Supply and demand service will have a dedicated cluster and can be scaled horizontally for concurrent access .
Resiliency :
To make the system resilient or fault tolerant we can use master slave architecture of trips db and replicate the data . We can also shard the data based on cell id which can avoid hotspots .
Please UPVOTE if you like the solution . Happy for any feedbacks which can make this design more robust or scalable .