Skip to content

Food Delivery — Detailed#

flowchart TB
  subgraph Apps[Apps]
    CUST([Customer])
    REST[Restaurant]
    DRV([Driver])
  end

  subgraph Edge
    CDN
    GW
    WS[WebSocket gateway]
  end

  subgraph Discover[Discovery]
    MENU[Menu / Catalog]
    SRCH[Search]
    REC([Recommend])
    SLA[Promised ETA estimator]
    GEOS[Geo serviceability]
  end

  subgraph Order
    ORDSVC[Order Service]
    ODB[(Orders)]
    SAGA([Order saga])
  end

  subgraph Restaurant_Side[Restaurant Side]
    TAB[Tablet / KDS]
    PREP[Prep time tracker]
  end

  subgraph Dispatch[Dispatch / Matching]
    DSVC[Dispatch Service]
    GIDX[(Geo index<br/>geohash / S2)]
    DRVPRE([Driver presence])
    SCORE[Pickup score<br/>distance + cooking time + ratings]
    ASSIGN[Assignment]
    BATCH[Batching multi-orders]
  end

  subgraph Live[Live tracking]
    LOC([Location ingest<br/>500ms-3s])
    ETA[Live ETA]
    GEOFENCE[Geofence events]
  end

  subgraph Pay
    PAYSVC[Payment Service]
    GTW((Payment provider))
    PROMO[Coupons]
    WAL[Wallet]
  end

  subgraph Notif
    PUSH[Push]
    SMS[SMS]
    INAPP[In-app]
  end

  subgraph Pricing[Pricing / Surge]
    BASE[Base fare]
    SURGE[Surge / demand-supply]
    BG[Background pricing]
  end

  CUST --> CDN --> GW
  GW --> Discover
  GW --> Order
  Order --> Restaurant_Side
  Order --> Dispatch
  Dispatch --> Live
  Live --- DRV
  DRV --> WS --> Live
  Order --> Pay
  Order --> Notif
  Pricing --- Order

    classDef client fill:#dbeafe,stroke:#1e40af,stroke-width:1px,color:#0f172a;
    classDef edge fill:#cffafe,stroke:#0e7490,stroke-width:1px,color:#0f172a;
    classDef service fill:#fef3c7,stroke:#92400e,stroke-width:1px,color:#0f172a;
    classDef datastore fill:#fee2e2,stroke:#991b1b,stroke-width:1px,color:#0f172a;
    classDef cache fill:#fed7aa,stroke:#9a3412,stroke-width:1px,color:#0f172a;
    classDef queue fill:#ede9fe,stroke:#5b21b6,stroke-width:1px,color:#0f172a;
    classDef compute fill:#d1fae5,stroke:#065f46,stroke-width:1px,color:#0f172a;
    classDef storage fill:#e5e7eb,stroke:#374151,stroke-width:1px,color:#0f172a;
    classDef external fill:#fce7f3,stroke:#9d174d,stroke-width:1px,color:#0f172a;
    classDef obs fill:#f3e8ff,stroke:#6b21a8,stroke-width:1px,color:#0f172a;
    class CUST,DRV,DRVPRE client;
    class WS edge;
    class REST,MENU,SRCH,SLA,GEOS,ORDSVC,TAB,PREP,DSVC,SCORE,ASSIGN,BATCH,ETA,GEOFENCE,PAYSVC,PROMO,WAL,PUSH,SMS,INAPP,BASE,SURGE,BG service;
    class ODB,GIDX datastore;
    class REC,SAGA,LOC compute;
    class GTW external;

Dispatch logic#

  • New order → query geo index for online drivers near restaurant.
  • Score candidates: distance, prep time, driver rating, idle time, batch potential.
  • Assign top candidate; if reject, fall through next.
  • Multi-order batch when along the same route (5-15 min detour OK).

Live location plane#

  • Driver app sends location every 1-3 s (faster near pickup/drop).
  • Geo index sharded by geohash prefix; updates are write-heavy.
  • Customer subscribes to driver's WS channel for live ETA.

Glossary & fundamentals#

Concepts referenced in this design. Each row links to its canonical page; the tag column shows whether it is a high-level (HLD) or low-level (LLD) concept.

Tag Concept What it is Page
HLD CDN edge caching for static assets cdn
HLD Sharding horizontal partitioning across nodes database-sharding
HLD LSM vs B-Tree engines WAL, memtable, SSTables, compaction storage-engines-lsm-btree
HLD Distributed transactions 2PC, TCC, sagas, outbox/inbox distributed-transactions
HLD Realtime protocols WS / SSE / polling / gRPC streaming realtime-protocols
HLD Geo indexing Geohash, Quadtree, S2, H3, R-tree geo-indexing
LLD REST API design verbs, statuses, pagination, errors rest-api-design
LLD Async models futures / async-await / coroutines / actors async-models