Skip to content

Food Delivery System Design (HLD & LLD)

  • Search restaurants
  • Browse menu
  • Add items to cart
  • Place order
  • Online payment / Cash on Delivery (COD)
  • Track order
  • View order history
  • Manage menu
  • Accept or reject orders
  • Update order status
  • Accept delivery requests
  • Pick up orders
  • Deliver orders
  • Update delivery status
  • High availability
  • Low latency
  • Horizontal scalability
  • Fault tolerance
  • Real-time tracking
  • High throughput during peak hours
flowchart TD
    A["Client Apps<br/>Customer / Restaurant / Delivery Partner"]
    A --> B[API Gateway]

    B --> U[User Service]
    B --> R[Restaurant Service]
    B --> O[Order Service]
    B --> P[Payment Service]
    B --> D[Delivery Service]
    B --> N[Notification Service]

    O --> K[(Kafka / Message Queue)]
    K --> W[Tracking / Analytics / Notification Workers]
  • Authentication
  • Rate limiting
  • Routing
  • Logging
  • User profile
  • Addresses
  • Authentication
  • Restaurant data
  • Menu management
  • Availability
  • Cart
  • Order creation
  • Order state management
  • Payment gateway integration
  • Refunds
  • Transaction tracking
  • Assign delivery partner
  • Track delivery status
  • Push notifications
  • SMS
  • Email
  • Order events
  • Delivery updates
  • Notifications
  1. User selects restaurant and menu items.
  2. Client invokes the Create Order API.
  3. Order Service validates items, creates the order, and publishes an event.
  4. Payment Service processes payment.
  5. Restaurant accepts the order.
  6. Delivery partner is assigned.
  7. Order status is updated throughout the lifecycle.
  8. Notifications are sent to the customer.
sequenceDiagram
    participant C as Customer
    participant O as Order Service
    participant P as Payment Service
    participant R as Restaurant
    participant D as Delivery Service

    C->>O: Create Order
    O->>P: Process Payment
    P-->>O: Success
    O->>R: Send Order
    R-->>O: Accept Order
    O->>D: Assign Driver
    D-->>C: Live Status Updates
Users
-----
user_id (PK)
name
phone
email
created_at
Restaurants
-----------
restaurant_id (PK)
name
location
rating
is_open
MenuItems
---------
item_id (PK)
restaurant_id (FK)
name
price
is_available
Orders
------
order_id (PK)
user_id
restaurant_id
status
total_price
payment_status
created_at
OrderItems
----------
id
order_id
item_id
quantity
price
Delivery
--------
delivery_id
order_id
driver_id
status
pickup_time
delivery_time
erDiagram
    USERS ||--o{ ORDERS : places
    RESTAURANTS ||--o{ MENU_ITEMS : offers
    RESTAURANTS ||--o{ ORDERS : receives
    ORDERS ||--|{ ORDER_ITEMS : contains
    MENU_ITEMS ||--o{ ORDER_ITEMS : references
    ORDERS ||--|| DELIVERY : fulfilled_by
stateDiagram-v2
    [*] --> CREATED
    CREATED --> PAYMENT_PENDING
    PAYMENT_PENDING --> PAYMENT_SUCCESS
    PAYMENT_PENDING --> PAYMENT_FAILED
    PAYMENT_SUCCESS --> RESTAURANT_ACCEPTED
    RESTAURANT_ACCEPTED --> PREPARING
    PREPARING --> PICKED_UP
    PICKED_UP --> DELIVERED
    CREATED --> CANCELLED
    RESTAURANT_ACCEPTED --> REJECTED_BY_RESTAURANT

Use:

  • GeoHash
  • Redis GeoSpatial Index

Algorithm:

Find drivers within a 3 km radius
Sort by distance
Assign the first available driver

For the full geospatial matching mechanics (Redis GEOADD/GEORADIUS, handling hundreds of thousands of location updates/sec, and preventing double-assignment race conditions), see the Ride Booking system design case study.

flowchart LR
    A[Driver App] --> B[Location Service]
    B --> C[WebSocket / SSE]
    C --> D[Customer App]

Technologies:

  • WebSocket
  • Redis Pub/Sub
  • Kafka Streaming

Use Redis for:

  • Restaurant list
  • Menu items
  • Active drivers
  • Frequently ordered items

Example key:

menu:{restaurant_id}
  • Read replicas
  • CDN for images
  • Redis cache
  • Shard orders table
  • Partition by order ID or region
  • Kubernetes deployment
  • Autoscaling
  • Queue incoming orders
  • Rate limiting
  • Load balancing
  • Autoscaling

Use the Saga Pattern.

Workflow:

Create Order
-> Process Payment
-> Confirm Restaurant
-> Assign Delivery

Compensation:

Refund Payment
  • JWT authentication
  • HTTPS
  • Rate limiting
  • Fraud detection
  • Secure payment gateway integration
class Order {
String orderId;
Long userId;
Long restaurantId;
List<OrderItem> items;
OrderStatus status;
PaymentStatus paymentStatus;
BigDecimal totalPrice;
}
class OrderItem {
Long itemId;
int quantity;
BigDecimal price;
}
class Delivery {
String deliveryId;
Long driverId;
String orderId;
DeliveryStatus status;
Location currentLocation;
}
POST /orders

Request:

{
"restaurantId": 101,
"items": [
{
"itemId": 1,
"qty": 2
},
{
"itemId": 5,
"qty": 1
}
]
}
GET /orders/{orderId}/status
GET /restaurants/{id}/menu
  • Multi-region deployment
  • ETA prediction using machine learning
  • Dynamic pricing
  • Surge delivery fee
  • Restaurant ranking algorithm
  • Fraud detection
  • Delivery batching
  • Microservices isolate business capabilities and scale independently.
  • Event-driven communication improves resilience and decouples services.
  • Redis and Kafka are critical for low latency and asynchronous workflows.
  • Geo-spatial indexing enables efficient driver matching.
  • Saga pattern provides reliable distributed transaction handling.