Design a Food Delivery Assignment System

Problem

Design the OOP model for a food delivery assignment system that assigns orders to delivery agents.

Requirements

  • placeOrder(customerId, restaurantId, items[]) → returns orderId
  • assignAgent(orderId) → assigns nearest available agent
  • updateLocation(agentId, lat, lng) — agent broadcasts location
  • markDelivered(orderId) — frees the agent

Key classes

Order, DeliveryAgent, Restaurant, Location, AssignmentEngine

Design decisions to discuss

  • How do you find the nearest agent efficiently? (Grid-based spatial index)
  • Agent state machine: available → assigned → en_route → delivered
  • What happens if the assigned agent cancels? (reassignment strategy)

Extension

Support batching — one agent picks up multiple orders from the same restaurant.

added …
LeaderboardSalaryAccount