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 orderIdassignAgent(orderId)→ assigns nearest available agentupdateLocation(agentId, lat, lng)— agent broadcasts locationmarkDelivered(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 …