Swiggy Navigation Alerts

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2021-05-22

Problem Statement

Design and implement a system to provide real-time navigation and status alerts to users and delivery partners in a food delivery platform. Focus on location tracking, notifications, and event-driven updates.


Functional Requirements (FR)


Delivery Tracking


•Track delivery partner’s real-time location.
•Track order status: Picked Up, On The Way, Delivered, Delayed.
•Calculate estimated delivery time (ETA) dynamically.


Alerts & Notifications


•Notify users when:
•Order is picked up.
•Delivery partner is nearby.
•Delivery is delayed or completed.
•Notify delivery partner of route changes, traffic updates, or missed pickups.
•Support multiple notification channels: push notifications, SMS, in-app alerts.


Route Optimization (Optional)


•Suggest fastest route to delivery partner using mapping APIs.
•Handle dynamic rerouting in case of traffic or roadblocks.


Historical Tracking


•Store past delivery routes and ETA for analytics.
•Generate reports for delivery performance.


Non-Functional Requirements (NFR)


•Scalability → Handle thousands of concurrent delivery partners and users.
•Low Latency → Real-time location updates and notifications.
•Reliability → Ensure alerts are delivered without loss.
•Extensibility → Support future features like multiple stops, live map view, or driver ranking.
•Security & Privacy → Protect user and delivery partner location data.


Core Entities & Attributes


User


•userId, name, contactInfo, currentOrderId


DeliveryPartner


•partnerId, name, currentLocation, availabilityStatus, currentOrderId


Order


•orderId, userId, restaurantId, partnerId, status, estimatedDeliveryTime, currentLocation


Alert / Notification


•alertId, userId / partnerId, orderId, alertType, message, timestamp, deliveryStatus


Route (Optional)


•routeId, orderId, startLocation, endLocation, waypoints[], eta


Core Components


LocationService


•Continuously updates the location of delivery partners.
•Calculates ETA based on current location and route.


NotificationService


•Sends alerts to users and delivery partners.
•Supports multiple channels (push, SMS, email).


OrderService


•Updates order status based on delivery partner events.
•Triggers alerts when status changes.


RouteOptimizer (Optional)


•Suggests fastest route and reroutes dynamically based on traffic.


APIs / Operations


Delivery Partner APIs


•updateLocation(partnerId, location)
•getAssignedOrders(partnerId)


User APIs


•getOrderStatus(orderId)
•subscribeToAlerts(userId, orderId)


Order APIs


•updateOrderStatus(orderId, status)
•getETA(orderId)


Notification APIs


•sendAlert(alert)
•getAlertHistory(userId / partnerId)


LLD Design Goals


•Class Diagram → User, DeliveryPartner, Order, Alert, Route, NotificationService, LocationService, OrderService.


Design Patterns:


•Observer Pattern → For real-time alert delivery to users and partners.
•Strategy Pattern → For different alert channels (push, SMS, email).
•Singleton Pattern → For NotificationService and LocationService.
•Concurrency Handling → Handle simultaneous location updates and notifications efficiently.
•Trade-offs → Polling vs. push-based updates; real-time ETA calculation vs. periodic update.


Solution

Comments