Real-Time APIs · Capstone
Capstone: Real-Time Order Tracking
Design live updates for customers, drivers and support agents.
Scenario
A delivery company needs: customers watching their order status and courier location live (web + mobile), couriers' apps sending GPS every 3 s, support agents watching dashboards of thousands of active deliveries, and restaurants receiving new orders instantly. Peak: 300k active customers, 40k couriers, 2k agents.
Requirements
- Courier location updates visible within 2 s
- No missed order-status changes
- Mobile battery-friendly
- Secure per-order access
Constraints
- Two regions
- Existing Redis and Kafka
Deliverables
- Choose transports per client and justify.
- Design fan-out, ordering and recovery.
- Security and scaling plan.
Draft each deliverable below before revealing the model answer and rubric.
Further reading: Server-sent events
Deliverables
Choose transports per client and justify.
Model answer
Customers web: SSE for status + location (server→client only), HTTP/2. Customers mobile: WebSocket/SSE in foreground; push (FCM/APNs) for status changes in background; sync on resume. Couriers: HTTPS batched GPS posts (or WebSocket while active) with backoff; push for new assignments. Agents: WebSocket (filters/subscriptions change frequently). Restaurants: WebSocket + webhook option for POS integrations.
Rubric
Strong answers pick different transports per client type and account for mobile background limits.
Design fan-out, ordering and recovery.
Model answer
Location: couriers → ingest → Kafka (key = courier id) → conflator (latest per courier every 1 s) → Redis pub/sub channels order:{id} → gateways. Status: outbox → Kafka → gateways + durable per-order event list with seq numbers; clients resync with since=seq; snapshots on long disconnect. Agents' dashboards subscribe to region channels with conflated aggregates.
Rubric
Look for conflation of high-frequency location data, durable sequenced status events and resync.
Security and scaling plan.
Model answer
Short-lived tickets for socket auth; per-channel authorization (customer only their order, courier only assigned orders, agents by role/region); Origin checks. Scale gateways by concurrent connections; drain on deploys; jittered reconnects; per-user connection limits; load test 2× peak with reconnect storms.
Rubric
Strong answers authorize per channel and plan for deploy draining and reconnect storms.
Open in the app to mark lessons complete, take notes and track your progress.