GET /restaurants?filters=xyz
Return top restuaratns near user address
GET /restuarant/{id}
Fetch restaurant details and its menu
PUT /users/{id}/cart
req: {
item
}
add item to user cart
POST /delivery
req:
{
restaurantId,
userId,
items[],
paymentMethod
}
GET /delivery/{id}
Fetches delivery status and details
PUT /delivery/{id}
updates delivery status and details
POST /drivers/{id}/status
req: {status} update druver status -> available, reservered, on delivery, offline
POST /drivers/{id}/location
req: {
lat, long, timestamp}
updates driver location
POST /delivery/{id}/accept
Accept delivery order
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.
User Service
Driver service
Restaurant Service
Delivery Service
Location Service
Payment Service
Dispatch Service
Geo Index Service
Websocket gateway
Kafka
PostreSQl
Redis
We use hybrid apporach for Database, using SQL -> PostreSQL for storing strong consisten data where transactrions matter like Users, Drivers, Delivery, Restaurants, MenuItem, Payments etc and NOSqL -> redis for stroing geo index locations of driver
Restaurants
Id -> partition key
Name
Description
Type
Ratings
Location
MenuItem
Id
RestuarantId -> partition key
Name
Description
Price
Type -> appetizer, main course, dessert, drink etc
Image
User
Id -> partition key
Name
Address
Driver
Id -> partition key
Rating
Status -> Avialable, Reserved, On Delivery, Offline
Delivery
Id -> partition key
userId
RestaurantId
DriverId
Status
TotalPrice
PaymentMethod
createdAt
DeliveryItems
Id
DeliveryId -> partition key
MenuItemId
quantity
UnitPrice
Delivery -> Delivery Items = 1 to many relationship
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:
34ascas -> driver1, driver2, driver3
Driver lastes location(comes from api)
driver1 -> lat, long, timesatmp
We will now deep dive into these topics
Most imp and hardest problem.
Delivery Requested and Restuarant accepted order
Dispatch Service:
Score =
ETA weight + distance wight + acceptance rate weight + driver rating weight
Delivery offer workjflow:
Acceptance Race Probmlem:
SELECT *
FROM Delivery
FOR UPDATE;
t5e33 -> driver1, driver2, driver3 etc
HotSpot problme:
-> Driver Disconnect
Heartbeat missing:
30 sec
Mark offline.
Remove from matching pool.
-> Dispatch Service Crash
Dispatch state stored in DB.
Kafka retains event.
New instance resumes.
Redis cluster.
Primary
+
Replicas
Automatic failover.
If full Redis loss:
Replay Kafka location stream
Rebuild index.
Replication Factor:
3
Leader election.