Uber - System Design
First created 2021年01月18日21:50
A system with Write heavy & Read heavy, Transisent data
ttl can be short
Requirements:
Drivers: tell the service the real-time location and availability
Customers: request a ride
Drivers: get notified / accpet a nearby customer
finish a ride and get available for the next ride
Customers: be charged fee/ give feedback and ratings
DAU:
drivers: 500K
customers: 1M
QuadTree: not suitable
since Uber drivers will update their real-time location very frequently (every 3 seconds) from one grid to another
Push Model
Broadcast the location of one driver to all its nearby customers
Servers Infrastructure Picture

customer -(make ride request)-> [Demand Server] -> [Location Server] (different cell IDs within a circle and a given radius (using Google S2 library))
cell ID is performed as the sharding key. So the Location Service querys a few replicas.
All the nearby drivers' info returned to the Demand Server and the Demand Server do a aggregations and sorting.
Then the Demand Server calls Notification Server to pushes message to all the selected drivers. Wait for one of them to choose acceping this ride.
drivers -(accept/reject ride request)-> [Demand Server]
If accept, then the Demand Server calls Notification Server to pushes message to other candidate drivers that the request has been taken.
Credits Server is used for charging fee after the customer finishes the riding.
Notification Server
websocket
Notification Server
websocket
Schema
RideDB
requestId (primary key) | customerId | driverId | latitude | longitude | status | created_timestamp
DriverDB
driverId (primary key) | latitude | longitude | status | updated_timestamp
CustomerProfileDB
customerId (primary key) | profile(email, phone, ...) | paymentInfo | rideHistory [requestId1,2,3,...]
Replication
primary, secondary, ...
Reference
[1] https://www.educative.io/courses/grokking-the-system-design-interview/YQVkjp548NM

浙公网安备 33010602011771号