Driver APIs
Update driver status -> AVAILABLE, RESERVED, ON TRIP
POST /drivers/{id}/status
request: {
status
}
Location Update
POST /drivers/{id}/location
req:{
lat,
long,
timestamp
}
Accept ride
POST /rides/{id}/accept
Rider APIs
Request Ride/trip
POST /rides
req:{
riderId,
pickup: {
lat,
long
}
dest:{
lat,
long
}
}
Get ride status
GET /rides/{id}
Update ride status ->Requested, Matched, In progress, Completed, Cancelled
POST /ride/{id}/status
API Gateway
Acts as the entry point for all client requests.
Responsibilities:
Distributes traffic across multiple instances of all services to improve scalability and availability.
Rider Service
Driver service
Location Service
Trip Service
Payment Service
Matching Service
Notification Service
Geo Index Service
Websocket gateway
Kafka
PostreSQl
Redis
We use hybrid apporach for Database, using SQL -> PostreSQL for stroing strong consisten data where transactrions matter like Users, Drivers, Trips etc and NOSqL -> redis for stroing geo index locations of driver
Riders
id
name
rating
Drivers
id
name
status -> AVAILABLE, RESERVED, ON TRIP
vehicle type
rating
Trip
id
riderId
driverId
pickup_lat
pickup_long
dest_lat
dest_long
status -> Requested, Matched, In progress, Completed, Cancelled
UserPaymentMethods
id
userId
method_id -> id from payment provider
providerId
Payments
id
tripid
amount
status -> PENDING, SUCCESS, FAILEd
provider_id
Geo Index -> stored in Redis
structure:
Driver -> cell mapping
eg:
der334s -> driver1, driver2, driver 3
Driver latest location (comes from the api)
driver1 -> lat, long, timestamp
We will now deep dive into these topics
-> Problem: how do we find nearyby drivers efficiently?
Doing:
Select * from drivers where distance <1km
is impossible at scale
Solution: Use GeoHash
eg: each smaller location is divided into a cell, for eg
Cell A
Cell B
Cell C
Eg
CellA -> driver1, driver2, driver3
in our sytem this is done via:
eg ->
ds3dwad -> driver1, driver2
-> now rider requests ride
End to end flow:
Score = eta weight + distance weight + acceptance weight
-> Two riderss request same driver at the same time
Eg: Ride A and Ride B reqeust comes in
Driver Disconnects
Matching/Location service crash
Websocket gateway crash
Redis crash