Design a food delivery platform (Swiggy/Zomato style)

Learn how to design a three-sided marketplace for food delivery, focusing on order state machines, geospatial dispatching, and live tracking.

intermediate9 min readBy CureBugs EditorialUpdated 5 Nov 2026

Designing a food delivery platform like Swiggy, Zomato, or UberEats is a classic system design interview question. It is fundamentally a three-sided marketplace connecting users, restaurants, and delivery partners. The complexity lies in orchestrating distributed transactions (orders), real-time geospatial matching (dispatch), and high-throughput data ingestion (live location tracking) while maintaining a seamless user experience during massive traffic spikes.

Requirements (functional and non-functional)

Before jumping into the architecture, it is crucial to align with your interviewer on the scope of the system. Food delivery platforms are massive; we need to narrow our focus.

Functional Requirements

  1. Search and Discovery: Users can search for restaurants based on their location and view menus.
  2. Order Management: Users can place an order, pay, and track its status.
  3. Restaurant Operations: Restaurants can accept/reject orders and update preparation status.
  4. Dispatch and Delivery: The system must find the nearest available Delivery Partner (DP) and route them to the restaurant and then to the user.
  5. Live Tracking: Users can track the DP's live location on a map.

Non-functional Requirements

  1. High Availability: The search and menu discovery services must be highly available. If users can't browse, they can't order.
  2. Strong Consistency: Order placement and payments require strong consistency. A user shouldn't be charged for a failed order.
  3. Low Latency: Live location tracking and dispatching need real-time or near real-time latency (sub-second).
  4. Scalability: The system must handle massive, predictable traffic spikes (e.g., lunch at 1 PM, dinner at 8 PM, or special events like the IPL finals).

Capacity estimates

Let's assume the platform operates at a scale similar to a leading Indian food delivery app.

  • Daily Active Users (DAU): 10 million
  • Orders per day: 2 million
  • Active Delivery Partners: 200,000

Order Throughput: Food delivery is highly seasonal. Let's assume 50% of the daily orders happen during a 2-hour dinner window.

  • Peak orders = 1,000,000 orders / 7200 seconds ≈ 140 orders/second.
  • To be safe, we should design our order system to handle 300 to 500 TPS (Transactions Per Second).

Location Tracking Throughput: If 100,000 DPs are active during peak hours and their app sends a GPS ping every 10 seconds:

  • Location writes = 100,000 / 10 = 10,000 writes/second.
  • This is a write-heavy workload that will dictate our choice of database for location tracking.

API design

Let's define the core APIs for our system. We will use RESTful conventions.

1. Search Restaurants

GET /v1/restaurants/search?lat={lat}&lng={lng}&radius={radius_km}&query={keyword}

  • Response: Returns a list of restaurant objects containing id, name, rating, and estimated_delivery_time.

2. Place Order

POST /v1/orders

  • Request Body:
    json
    {
      "user_id": "u123",
      "restaurant_id": "r456",
      "items": [{"item_id": "i789", "quantity": 2}],
      "total_amount": 450.00,
      "user_lat": 12.9716,
      "user_lng": 77.5946
    }
  • Response: Returns order_id and status.

3. Update DP Location

PUT /v1/delivery/location

  • Request Body:
    json
    {
      "dp_id": "d999",
      "lat": 12.9720,
      "lng": 77.5950,
      "timestamp": 1698765432
    }

Data model

We need a mix of databases to handle the different access patterns of our system.

EntityDatabase TypeWhy?
Users/RestaurantsRelational (PostgreSQL)Structured data, infrequent updates, requires ACID properties for account management.
OrdersRelational (PostgreSQL)Financial transactions require strict ACID compliance. Read replicas can handle status polling.
Restaurant SearchSearch Engine (Elasticsearch)Fast geospatial queries (geo_distance) combined with full-text search for food items.
DP LocationsIn-Memory (Redis)10,000+ writes/sec. Ephemeral data (we only care about the latest location for dispatch).

High-level architecture

Here is the high-level architecture connecting the three clients (User, Restaurant, DP) through an API Gateway to our microservices.

Deep dives

Let's explore the three most complex parts of a food delivery system: Order Management, Dispatching, and Live Location Tracking.

1. Order State Machine and Event-Driven Architecture

An order in a food delivery app goes through a complex lifecycle: CREATED -> PAYMENT_SUCCESS -> ACCEPTED_BY_RESTAURANT -> PREPARING -> DP_ASSIGNED -> PICKED_UP -> DELIVERED.

Because multiple microservices are involved, relying on synchronous HTTP calls is a recipe for failure. If the Dispatch Service is down, the Order Service shouldn't crash. We use an Event-Driven Architecture with a message broker like Kafka (refer to message-queues-kafka-vs-rabbitmq).

  1. User places an order. Order Service creates a record in PostgreSQL with status CREATED.
  2. Once payment succeeds, Order Service updates status and publishes an OrderPaid event to Kafka.
  3. The Restaurant Service consumes this event and pushes a notification to the Restaurant App.
  4. When the restaurant accepts, the Restaurant Service publishes an OrderAccepted event.
  5. The Dispatch Service consumes OrderAccepted and begins the search for a Delivery Partner.

To prevent invalid state transitions (e.g., an order going from CREATED directly to DELIVERED), we implement a strict State Machine in our code.

class OrderStateMachine:
    def __init__(self):
        self.state = "CREATED"
        self.valid_transitions = {
            "CREATED": ["PAYMENT_SUCCESS", "CANCELLED"],
            "PAYMENT_SUCCESS": ["ACCEPTED_BY_RESTAURANT", "CANCELLED"],
            "ACCEPTED_BY_RESTAURANT": ["PREPARING"],
            "PREPARING": ["DP_ASSIGNED"],
            "DP_ASSIGNED": ["PICKED_UP"],
            "PICKED_UP": ["DELIVERED"]
        }

    def transition(self, new_state):
        if new_state in self.valid_transitions.get(self.state, []):
            self.state = new_state
            return True
        raise ValueError(f"Invalid transition from {self.state} to {new_state}")

2. Dispatch and Geospatial Matching

When an order is accepted, we need to find the best Delivery Partner. The naive approach is to calculate the distance between the restaurant and every active DP. With 100,000 DPs, this is computationally impossible in real-time.

Instead, we use Geospatial Indexing.

  1. Data Structure: We divide the map into grids using systems like Uber's H3 (hexagons), Google's S2, or Geohashes.
  2. Storage: We use Redis with its built-in Geospatial commands (GEOADD, GEORADIUS, GEOSEARCH). Redis stores the DP's ID, Longitude, and Latitude.
  3. Matching Logic:
    • The Dispatch Service queries Redis: GEOSEARCH dp_locations FROMLONLAT {rest_lng} {rest_lat} BYRADIUS 3 km.
    • Redis instantly returns a list of DPs within a 3km radius.
    • The Dispatch Service filters this list. It removes DPs who are currently assigned to an order (unless they are eligible for batching) and ranks the remaining DPs based on distance, historical SLA, and vehicle type.
    • It sends a push notification to the top candidate. If they reject or timeout after 15 seconds, it moves to the next candidate.

3. Live Location Tracking

Once a DP is assigned, the user wants to see their little motorcycle icon move on a map.

Polling the server every second from the User App would overwhelm our API Gateway. Instead, we use WebSockets for a persistent, bi-directional connection.

  1. The DP App sends location updates via HTTP PUT or a WebSocket connection to the Location Service every 5-10 seconds.
  2. The Location Service updates the DP's coordinates in Redis (for future dispatching).
  3. The Location Service also publishes this location payload to a Redis Pub/Sub channel specific to that order (e.g., channel:order_123).
  4. The User App establishes a WebSocket connection to a WebSocket Gateway, subscribing to channel:order_123.
  5. As soon as the DP's location hits Redis Pub/Sub, it is pushed down the WebSocket connection to the user's screen with sub-second latency.

Bottlenecks and trade-offs

1. Redis Memory Limits vs. Ephemeral Data Storing live locations in Redis is fast, but memory is expensive. Trade-off: We only store the current location of active DPs in Redis. Historical location data (used for analytics, dispute resolution, and machine learning) is asynchronously dumped from Kafka into a cheaper data lake (like Amazon S3 or Hadoop) via a consumer.

2. Polling vs. WebSockets for Restaurant App While we use WebSockets for live tracking, what about the Restaurant App receiving new orders? WebSockets are stateful and harder to scale. Since orders arrive less frequently than GPS pings, many platforms use Server-Sent Events (SSE) or simply long-polling for the Restaurant App. It is simpler to implement and perfectly adequate for the required latency.

3. Database Contention on Orders Table During peak hours, the Orders table in PostgreSQL will experience heavy write contention. To mitigate this, we can shard the database by geography (e.g., city_id). A user in Bangalore will never order from a restaurant in Delhi, making geography a perfect shard key.

Questions an interviewer will ask next

Q: What happens if two Delivery Partners accept the same order simultaneously? We handle this using Optimistic Concurrency Control (OCC) in our database. When the Dispatch service assigns the order, it includes a version number in the SQL query: UPDATE orders SET dp_id = 'd1', version = 2 WHERE order_id = '123' AND version = 1. The first request succeeds, increments the version, and the second request fails, prompting the app to tell the second DP the order is no longer available.

Q: How do you handle a Delivery Partner losing internet connection while on a trip? We implement a heartbeat mechanism. If the Location Service doesn't receive a ping from a DP for a threshold (e.g., 3 minutes), it marks them as DISCONNECTED. For active orders, the system might alert customer support or attempt to call the DP via a telephony API (like Twilio). The User App is designed to gracefully handle missed pings by interpolating the route or showing a "Signal lost" UI state.

Q: How would you design order batching (assigning two orders from the same restaurant to one DP)? Batching requires evaluating time and distance constraints. When a new order arrives, the Dispatch Service checks if there is an existing unassigned order at the same restaurant, or an assigned order where the DP hasn't picked up the food yet. We calculate the detour distance to the second customer. If the detour adds less than X minutes to the first customer's SLA, we merge them into a single dispatch request.

Mock interview

Now design it with an interviewer in the room

Reading a design is the easy part. In the round you have to drive it yourself: ask the right questions, sketch it, and defend each choice when the interviewer pushes back.

  • Starts from this exact problem, on a shared whiteboard
  • Follow-ups on scale, failure and trade-offs
  • A scored report that quotes your answers and says what to fix
Run this as a mock design round Voice or text. Pause whenever you need to.

Applying somewhere? Start with the company filled in

Go deeper elsewhere

The best material we've found on these topics.

Practise this

Reading builds understanding. Practice makes it stick.

Keep reading

All articles
Case studies•intermediate

Design Uber: ride matching and live location

13 min read
Case studies•intermediateStart here

System design case studies: which to practise, in what order

4 min read
Case studies•intermediate

Design YouTube: video upload and streaming

11 min read
Case studies•intermediate

Design WhatsApp: real-time chat at scale

13 min read