Food Delivery — Masterclass
Three additional artifacts a Staff/Principal candidate should be able to produce for this problem: an Architecture Decision Record, a business-driven design exercise, and a production incident scenario.
1. Architecture Decision Record
The format working architects use to document a decision so future teams understand context, options, and reversal conditions.
Redis Cluster (32 shards) for driver location + Kafka event stream + ML dispatch service with prep-time prediction (DeepETA-style) + real-time surge pricing per hex + hybrid driver marketplace (exclusive scheduling + multi-app-aware scoring) + WebSocket for live tracking + async fulfillment via Sidekiq — over naive-nearest dispatch, PostGIS single-region, third-party Uber Direct integration, or Cloudflare Workers for edge dispatch.
- 50 cities × 500K orders/city/month = 25M orders/mo; dinner rush 30x baseline
- 5000 restaurants + 2000 drivers active per city
- Match latency budget: <30s from order-accepted to driver-dispatched
- Dispatch cancellation rate: <5% (currently 15% with naive-nearest)
- 3-sided marketplace: customer + restaurant + driver — each has different SLAs
- Real-time surge: driver-supply/customer-demand ratio per H3 hex, updated every 60s
- Regulatory: California AB5 (gig worker classification), EU Platform Work Directive (2024), state-by-state marketplace tax
- Multi-app driver reality: 40% of drivers work DoorDash + Uber Eats + Grubhub simultaneously — dispatch scoring must account for this
- Team: 60 engineers total, 20 dedicated to dispatch platform
Redis Cluster + Kafka + ML dispatch + WebSocket tracking (chosen)
- Redis GEOADD/GEORADIUS for driver location — 100K+ writes/sec across 32 shards
- ML dispatch predicts prep-time + delivery ETA + driver acceptance rate — reduces cancellation 15%→5%
- WebSocket for live tracking = sub-second position updates to customer's phone
- Kafka event stream decouples order lifecycle: OrderPlaced → RestaurantAccepted → DriverDispatched → PickedUp → Delivered
- Async fulfillment via Sidekiq for email/warehouse notifications keeps request path fast
- Multi-app-aware scoring: penalize driver acceptance score if they've been reject-happy on our app recently
- DoorDash + Uber Eats + Deliveroo actual production pattern
- Redis SPOF per shard — plan for shard failover during peak
- ML dispatch requires GPU inference tier ($50K+/mo)
- Real-time surge PR risk (customers complain about dynamic pricing) — be transparent
- Kafka + Redis + Postgres + Sidekiq = 4 stateful surfaces to operate
- WebSocket infrastructure = new discipline (connection management, reconnect storms)
Naive-nearest dispatch on PostGIS
- Simplest architecture — one Postgres does everything
- Team already knows PostGIS + Rails
- Zero ML infrastructure
- Ignores prep time — dispatches driver to restaurant before food is ready → driver waits → churn
- 15% cancellation rate — drivers reject dispatches that are too far or wrong direction
- PostGIS single-primary write ceiling ~500 writes/sec (well below 2K driver-location-updates/sec)
- No real-time tracking (SMS-only)
Third-party (Uber Direct — Uber Eats's platform-as-a-service)
- Uber Direct handles dispatch + driver marketplace + surge + tracking
- Zero infrastructure to run
- Sub-30s dispatch guaranteed by Uber
- $2-5 per delivery × 30M deliveries/mo = $60M-$150M/yr — kills unit economics
- Uber sees all your customer + restaurant data (competitive intelligence)
- Uber owns the customer relationship at drop-off (their driver app, not yours)
- Strategic dependency on competitor
Cloudflare Workers for edge dispatch
- 300+ edge PoPs — sub-30ms globally
- Edge KV for driver location
- DDoS-protected at edge
- Cloudflare Workers KV eventual consistency (30-60s) unacceptable for dispatch decisions
- Edge compute cost per invocation × 1M RPS × 30d = $500K+/mo
- ML inference at edge is expensive ($100K+/mo for GPU inference)
- Doesn't solve driver marketplace or compliance
Vertical Postgres + Sidekiq for dispatch
- Simpler than Redis + Kafka
- Team knows Rails stack
- Postgres write ceiling well below driver location update rate
- No real-time tracking
- Sidekiq FIFO queue doesn't handle dispatch priority
Redis Cluster + Kafka event stream + ML dispatch (DeepETA-style) + WebSocket tracking + async Sidekiq fulfillment + hybrid driver marketplace
- Naive-nearest on PostGIS — 15% cancellation rate + no prep-time awareness = wrong architecture
- Uber Direct — $60-$150M/yr destroys unit economics + strategic dependency on competitor
- Cloudflare Workers edge dispatch — 30-60s KV eventual consistency breaks dispatch accuracy
- Vertical Postgres + Sidekiq — ceilings at 5 cities; doesn't scale to marketplace
- Accept Redis SPOF per shard — plan for shard failover during dinner rush (30-60s of degraded dispatch)
- Accept ML dispatch GPU infrastructure ($50K+/mo) — pays for itself via 15%→5% cancellation reduction
- Accept real-time surge pricing PR risk — mitigate with transparent 'demand pricing' UI language
- Accept 4 stateful surfaces (Kafka + Redis + Postgres + Sidekiq) — dedicated Data Platform SRE team
- Accept WebSocket infrastructure discipline — reconnect storm handling on deploy is documented runbook
- Accept multi-app driver reality — dispatch scoring includes 'multi-app penalty' for detected double-booking
- Accept 20-30 engineer Dispatch Platform team — foundational + high-leverage warrants first-class ownership
- Dispatch accuracy improves 15%→5% cancellation, saves ~$30M/yr in wasted driver dispatches
- Compound ETA UX becomes trustworthy — customers see 'delivery in 25 min' + it happens
- Real-time surge pricing generates surge margin ~20% of total revenue during peak periods
- Kafka event stream becomes reusable primitive for fraud detection, analytics, driver-marketplace incentives, and A/B testing
- Driver marketplace features (exclusive scheduling, tiered pay, benefits) become strategic moat vs competitors
- GDPR compliance-as-code discipline flows through every dispatch decision (EU driver classification, data residency)
- Multi-app-aware scoring becomes competitive advantage — we know which drivers are loyal to us
- If ML dispatch model degrades below simple-nearest baseline for 2+ quarters → simplify to rules-based dispatch + reserve ML for surge pricing only
- If dispatch platform team drops below 10 engineers → migrate to Uber Direct (accept unit economics hit)
- If regulatory environment eliminates gig worker classification (all drivers become employees) → rebuild dispatch for W2 scheduling not marketplace
- If autonomous delivery becomes 60%+ of volume → dispatch architecture shifts from driver-marketplace to route-planning + fleet management
2. Business constraint exercise
Given real-world constraints (team size, budget, deadline), what architecture do you propose — and how do you push back when leadership asks for the wrong thing? This teaches engineering judgment.
You are engineer #4 at a 2-year-old food delivery startup ($30M ARR, 100 engineers, 15 cities). CTO says Monday: 'Cloud kitchens are 20% of DoorDash's volume by 2028. We need a cloud-kitchen platform. Options: (1) partner with existing cloud kitchen operators (CloudKitchens/REEF/Kitchen United) for revenue share, (2) build our own cloud kitchen software + operate physical kitchens, (3) build software-only cloud kitchen platform (like Shopify for kitchens), or (4) stay out of cloud kitchens entirely and focus on marketplace. Board wants a strategy this Friday. Which do we pick?'
- 1$30M ARR food delivery marketplace, 15 cities, growing 40% YoY
- 2100 engineers total, 25 on Dispatch Platform team, 10 on Marketplace team
- 3$50M cash runway (Series C in progress)
- 4Current unit economics: $2.50 margin per order, 30M orders/mo target
- 5Cloud kitchens grow 40%/yr — 5% of our volume now, projected 20% in 3 years
- 6Existing cloud-kitchen partners: 3 (CloudKitchens, REEF, Kitchen United) — small deals
- 7Regulatory: local health inspection per physical kitchen (state-by-state), commercial kitchen zoning
- 8Real-estate: cloud kitchen physical footprint = 1000-3000 sq ft + refrigeration + hood ventilation
- 9Competitive: DoorDash + Uber Eats + Deliveroo all making cloud kitchen investments; Meituan operates 500+ cloud kitchens in China
What do you recommend Friday? Frame as 3-year plan with unit economics, strategic control, and reversibility. Address the CTO's likely follow-up: 'why not all of them?'
3. Production incident scenario
You are on-call at 3:47am. p99 has spiked. Walk through the investigation, hypothesis, mitigation, and postmortem. This teaches real production reasoning — not just design.
PagerDuty alert at 5:47pm ET on Super Bowl Sunday. Order volume at 4.2x baseline (400% higher than a normal Sunday). Dispatch cancellation rate spiked from 5% to 34% in 15 minutes. Customer complaints about 'driver never came' up 800%. Push notification queue lag 45 seconds (baseline 200ms). ML dispatch GPU inference latency 850ms (baseline 30ms). Redis Cluster shard-12 at 98% CPU. Marketing texting: 'we are losing $2M/hour in cancelled orders and customer refunds. Fix this NOW.'
- orders.per_second: 12,400 (baseline 2,900 = 4.2x)
- dispatch.cancellation_rate: 34 pct (baseline 5 pct = 6.8x)
- push_notification.queue_depth: 47,000 (baseline 500 = 94x)
- push_notification.queue_lag_seconds: 45 (baseline 0.2s)
- ml_dispatch.inference_latency_p99_ms: 850 (baseline 30ms)
- ml_dispatch.gpu_utilization_percent: 100 (baseline 65 pct — saturated)
- redis.shard12.cpu_percent: 98 (baseline 40)
- redis.shard12.mem_percent: 91 (baseline 60)
- driver.acceptance_rate: 42 pct (baseline 82 pct — drivers rejecting because dispatch info stale)
- customer.support_tickets_per_second: 34 (baseline 4)
- estimated_revenue_loss_per_hour: $2.1M
- restaurants.average_prep_time_delay_min: 18 (baseline 4 = 4.5x — restaurants overwhelmed too)
- 17:47:03 dispatch-service: 'ML inference queue depth 8000 (target <100) — scaling up GPU pool from 4 to 8 nodes'
- 17:48:12 gpu-inference-pool: 'ERROR: cannot allocate GPU node — AWS regional capacity exhausted'
- 17:48:45 dispatch-service: 'falling back to rules-based dispatch (nearest-driver algorithm)'
- 17:49:30 push-notification-service: 'FCM API rate-limited (10K/sec cap hit, we are at 12K/sec)'
- 17:50:14 redis-shard12: 'MEMORY OK 91 pct, evictions starting'
- 17:51:00 driver-app: '30 pct of drivers report they are receiving stale dispatch info'
- 17:52:23 customer-support: 'flood of tickets, hold time 25 minutes'
- 17:53:45 dispatch-service: 'cancellation rate 34 pct, above 20 pct threshold — triggering emergency mode'
- 17:54:30 marketing-dashboard: 'projected revenue loss $2.1M/hour'
- 17:55:00 executive-slack: 'Get this fixed. Now.'
- Redis Cluster: DEGRADED — shard-12 at 98% CPU, other shards healthy
- ML dispatch: DEGRADED — GPU pool saturated, fell back to rules-based
- Kafka: HEALTHY — event stream flowing
- Postgres: HEALTHY at 65% CPU — read replicas handling browse traffic
- Push notification (FCM): RATE-LIMITED — Google's FCM API 10K/sec cap hit
- APNS (iOS push): DEGRADED — Apple's API queuing our requests
- WebSocket gateway: HEALTHY — connections stable
- AWS: DEGRADED — regional GPU capacity exhausted (Super Bowl affects many services)
- Restaurants (external): OVERWHELMED — real dependency, we cannot fix from our side
It's 5:53pm. Cancellation rate is 34%, revenue loss $2.1M/hour, ML dispatch fell back to rules-based, GPU pool exhausted regionally. What's your SINGLE highest-priority action in the next 5 minutes?
Assume push notification queue is now clearing. But ML dispatch is still on rules-based fallback because GPU pool is exhausted. Rules-based dispatch is 15% worse than ML. Should we accept the 15% degradation or try to restore ML dispatch?
It's now 6:15pm — 22 minutes after alert fired. Push notifications flowing, ML dispatch running cross-region. But restaurants are STILL overwhelmed — average prep time delay 18 minutes (baseline 4). We can't fix the restaurants from our side. What's your customer-facing action?
Postmortem the next day. Name 3 action items ranked by impact reduction for future 4x-baseline events (Super Bowl, New Year's, Valentine's Day).
Draft the customer-facing status page update at T+40 minutes (6:27pm — after push queue cleared + ML dispatch restored, but restaurants still overwhelmed). Constraint: honest, no jargon, sets correct expectations without over-promising fix time.
Learn these first
- 3-sided marketplace dynamics (customer + restaurant + driver)
- Compound ETA (browse + order + accept + prep + dispatch + delivery)
- ML dispatch with prep-time prediction (DeepETA-style)
- Real-time surge pricing per H3 hex + regulatory (gig worker classification)
Where this appears in the curriculum
This is the Gold Standard.
Every other system will eventually have a masterclass tab like this one. The pattern proven here — ADR + business exercise + incident scenario — scales to all 50+ problems on the platform.