Food Delivery Platform
A three-sided marketplace connecting customers, restaurants and delivery partners with menus, ordering, prep-time prediction, rider dispatch, live tracking, payments and payouts.
[!ASSUMPTION] Scope "QuickBite", a hypothetical food delivery company in 50 cities with 1.5 M orders/day. Numbers are assumptions.
1. Business problem and objectives
Deliver food fast and hot while keeping restaurants busy and riders earning. Objectives:
- Median delivery time < 30 minutes; on-time rate ≥ 90% against the promised ETA.
- Order placement success ≥ 99.9% during dinner peaks.
- Rider utilization ≥ 60% of online time on deliveries.
- Restaurant onboarding in < 48 hours.
2. Business model and revenue generation
| Stream | Notes |
|---|---|
| Restaurant commission | Percentage of order value |
| Delivery fees | Distance/demand based; free delivery for members |
| Membership | Monthly fee for free delivery and discounts |
| Ads | Sponsored listings in search and home |
| Small-order and platform fees | Per-order fees |
3. Functional requirements
- Customer: browse restaurants by location, menus with modifiers, cart, checkout, payment, live tracking, ratings, refunds.
- Restaurant: menu management, availability toggles, order acceptance, prep time input, payouts.
- Rider: online status, order offers, navigation, pickup and drop confirmation (photo/OTP), earnings.
- Dispatch: assign riders considering prep time, location, batching of orders.
- ETA: promise time at checkout, updated live.
- Support: missing items, refunds, chat.
- Promotions, membership, ads.
4. Non-functional requirements
| Attribute | Target |
|---|---|
| Availability | 99.95% for ordering; 99.9% for tracking |
| Latency | Restaurant list p95 < 400 ms; checkout p95 < 1.5 s |
| Peak | 5× normal at dinner; 10× during big sporting events |
| Consistency | Order and payment exactly once; rider assigned to orders without conflicts |
| Freshness | Restaurant open/closed and item availability reflected within 1 minute |
5. Expected user base and traffic assumptions
- 1.5 M orders/day, 60% in two daily peaks of 2 hours → ~125 orders/s at peak per region aggregate, bursts to 300/s.
- Browse-to-order ratio ~20:1 → ~6K RPS for listings and menus at peak.
- 150K online riders at peak, location every 5 s → 30K updates/s.
- 200K restaurants; menus ~100 items each; menu updates frequent (availability toggles).
6. High-level architecture
Customer, restaurant and rider apps → API gateway/BFFs → services: discovery (restaurant search by location), menu, cart/checkout, order, payment, restaurant integration, dispatch, rider location, ETA/ML, notifications, support, payouts. Event backbone (Kafka) links the order lifecycle across services. Per-city partitioning for dispatch.
7. Detailed component architecture
| Component | Design choice | Reason |
|---|---|---|
| Discovery | Search engine with geo-filters (delivery polygons), ranking by ETA, rating, ads | Location + relevance |
| Menu | Document store per restaurant + cache; availability toggles as small updates | Read-heavy, nested modifiers |
| Order | Relational with state machine; outbox | Money and lifecycle correctness |
| Restaurant integration | Tablet app + POS integrations via adapters; acknowledgement timeouts | Restaurants vary widely |
| Dispatch | Per-city batched optimization considering prep-ready time and order batching | Reduces rider idle time and food wait |
| ETA/prep prediction | ML models (prep time per restaurant/time/items, travel time) | Promise accuracy |
| Rider location | Kafka + in-memory geo index (H3) | Real-time and high write rate |
| Payouts | Ledger for restaurant and rider earnings | Financial correctness |
8. Architecture diagram
flowchart LR CUST[Customer app] --> GW[API gateway / BFFs] REST[Restaurant tablet / POS] --> GW RIDER[Rider app] --> GW GW --> DISC[Discovery<br/>geo search] GW --> MENU[Menu service] GW --> CHK[Checkout] CHK --> ETA[ETA & prep-time ML] CHK --> PAY[Payments] CHK --> ORD[Order service<br/>state machine] ORD --> K[[Kafka: order events]] K --> RINT[Restaurant integration] RINT --> REST K --> DISP[Dispatch<br/>per city, batched] RIDER -->|location| LOC[Location ingestion] --> GEO[(Geo index H3)] DISP --> GEO DISP --> ETA DISP -->|offers| RIDER K --> TRACK[Live tracking] --> CUST K --> LEDGER[Earnings ledger & payouts] DISC --> OS[(Search index)] MENU --> DOC[(Menu store + cache)] ORD --> SQL[(Orders DB)]
9. Frontend architecture
- Customer app: location-first home, cached restaurant lists, optimistic cart, live tracking map with smooth rider animation.
- Restaurant tablet app: loud, simple order acceptance UI; offline tolerance with retries; printer integration.
- Rider app: battery-aware GPS, offline queue for status updates, proof of delivery (photo/OTP).
10. Backend architecture
- Order lifecycle:
PLACED → RESTAURANT_ACCEPTED → PREPARING → READY → PICKED_UP → DELIVEREDwith branches for rejection, cancellation and refunds; timeouts escalate (auto-call restaurant if not accepted in 2 minutes). - Dispatch timing: assign rider so arrival ≈ predicted ready time (not too early → rider waits; not too late → food cools).
- Batching: combine two orders from the same or nearby restaurants going in similar directions when ETAs allow.
11. API design with sample endpoints
GET /v1/restaurants?lat=..&lng=..&cuisine=pizza&sort=eta
GET /v1/restaurants/{id}/menu
POST /v1/checkout/quotes { cartId, addressId } -> { quoteId, total, promisedEta: "35-45 min" }
POST /v1/orders Idempotency-Key: ... { quoteId, paymentMethodId, tip }
GET /v1/orders/{id}/tracking (or WebSocket subscription)
POST /v1/restaurant/orders/{id}/accept { prepMinutes: 15 }
POST /v1/rider/offers/{id}/accept
POST /v1/rider/orders/{id}/picked-up
POST /v1/rider/orders/{id}/delivered { proof: { otp | photoId } }12. Database schema and data model
CREATE TABLE food_order (
order_id text PRIMARY KEY, city_id int, customer_id text, restaurant_id text, rider_id text,
status text, subtotal numeric(10,2), delivery_fee numeric(10,2), tip numeric(10,2), total numeric(10,2),
promised_at timestamptz, ready_predicted_at timestamptz, created_at timestamptz, version int
);
CREATE TABLE order_item (order_id text, line int, item_id text, qty int, modifiers jsonb, price numeric(10,2),
PRIMARY KEY (order_id, line));
CREATE TABLE earnings_entry (entry_id text PRIMARY KEY, party_type text, party_id text, order_id text,
amount numeric(10,2), kind text, created_at timestamptz);Menu document: { restaurantId, categories[{ items[{ id, name, price, available, modifierGroups[{ min, max, options[] }] }] }], version }.
13. Database technology selection and reasoning
| Data | Store | Reason |
|---|---|---|
| Orders, payments, earnings | PostgreSQL (sharded by city) or distributed SQL | Transactions and reporting |
| Menus | Document store (MongoDB/DynamoDB) + Redis cache | Nested structure, read-heavy |
| Restaurant discovery | OpenSearch/Elasticsearch with geo_shape delivery zones | Geo + text + ranking |
| Rider locations | In-memory geo index + Kafka | Ephemeral, high rate |
| ML features | Feature store | ETA and prep-time models |
14. Authentication and authorization
Customers via phone OTP/social login; restaurants via staff accounts with roles (owner, manager, staff); riders via verified accounts with document checks. Object-level authorization: riders see only customer address and masked phone for assigned orders, only until delivery completes.
15. Security architecture
Payment tokenization via PSP; masked phone numbers; location data retention limits; fraud controls for promo abuse, fake accounts and rider GPS spoofing; refund abuse detection.
16. Caching strategy
Restaurant lists per geo cell cached for 30–60 s; menus cached with version-based invalidation; item availability toggles propagated via events to caches within seconds; ETA estimates cached per restaurant-area pair briefly.
17. Messaging and event-driven architecture
Order events drive restaurant notifications, dispatch triggers, tracking updates, customer notifications, earnings postings and analytics. Kafka partitioned by order ID; restaurant tablet delivery via persistent connections with acknowledgement and fallback to phone calls.
18. Cloud deployment architecture
Regional deployments near operating countries; dispatch per city; multi-AZ for all stateful stores; separate PCI scope for payments; real-time gateways on dedicated pools.
19. CI/CD and DevOps
City-level feature flags; dispatch algorithm simulation on historical data before rollout; switchback experiments (alternate algorithms by time window per city) for marketplace changes; peak-time change freezes.
20. Monitoring and observability
Marketplace metrics per city: orders/min, restaurant acceptance time, prep-time error, rider wait at restaurant, delivery time vs promise, cancellations. Alert on restaurant integration failures (orders not acknowledged).
21. Scalability and performance optimization
Pre-scale for known peaks (dinner, sports events); discovery cached by geo cell; dispatch batches per area; drop stale location updates; limit menu payload size with lazy-loaded sections.
22. High availability and disaster recovery
Ordering path multi-AZ; if dispatch fails in a city, fall back to simpler greedy assignment; if a restaurant tablet is offline, auto-call or mark restaurant temporarily unavailable; regional DR with warm standby for orders and payments.
23. Cost optimization
Rider location history downsampled; ML inference batched; spot capacity for analytics; CDN for menu images; right-sizing by city peaks with scheduled scaling.
24. Architecture trade-offs and alternatives
| Decision | Chosen | Alternative | When |
|---|---|---|---|
| Rider assignment time | At predicted ready time | Immediately on order | Very short prep times |
| Batching | Selective batching | Never batch | Premium "single order" promise |
| Restaurant integration | Tablet + POS adapters | POS-only | Markets with standardized POS |
| Fleet | Gig riders | Employed fleet | Regulatory or quality reasons |
25. Technology stack recommendations
Kotlin/Java or Go services; PostgreSQL; MongoDB/DynamoDB; Redis; OpenSearch; Kafka; Flink; H3; ML platform; Kubernetes; push and WebSocket infrastructure; PSP integration.
26. Common architecture mistakes
- Assigning riders too early, so they wait at restaurants and drop out.
- Stale menus causing orders for unavailable items.
- No acknowledgement tracking for restaurant notifications.
- Promising ETAs without prep-time prediction.
- Ignoring refund and promo abuse in early design.
27. Senior architect interview questions and answers
How do you compute the promised delivery time at checkout?
Sum predicted restaurant prep time (ML model on restaurant, time of day, items, current queue), rider assignment time and travel time to restaurant (supply density), and travel time to customer, with a buffer from historical error distribution to hit the on-time target.
How do you handle a restaurant that does not accept an order?
Timer escalates: re-notify, then automated call, then cancel and refund with customer notification; mark the restaurant as temporarily unavailable if repeated.
28. Enterprise architect interview questions and answers
How do you integrate hundreds of POS systems?
An integration layer with a canonical order model and adapters per POS vendor, certification process, monitoring per integration, and a fallback tablet app.
29. CTO-level business and technology questions
What matters most for unit economics?
Orders per rider hour (batching, dispatch efficiency), average order value, take rate, cancellation and refund costs, and marketing spend per order.
30. Real-world implementation roadmap
| Phase | Duration | Outcomes |
|---|---|---|
| 1. MVP city | 0–4 months | Ordering, restaurant tablet, manual-assisted dispatch, payments |
| 2. Real-time dispatch | 3–7 months | Rider app, location index, automated dispatch, tracking |
| 3. ETA ML | 6–10 months | Prep and travel time models, promise accuracy |
| 4. Scale cities | 9–18 months | City partitioning, POS integrations, membership |
| 5. Monetization | 12+ months | Ads platform, batching optimization |