Frontend School

Frontend System Design: Real-time Food Delivery Tracking

System Design
medium

Frontend System Design: Real-time Food Delivery Tracking

Medium
Frontend
System Design
Real-time
Food Delivery
WebSockets
State Management

Overview

Airbnb is continuously enhancing its guest experience by exploring integrations beyond traditional stays, including local services like food delivery. A seamless, real-time food delivery tracking experience is paramount to ensuring guest satisfaction and trust, providing transparency from order placement to doorstep delivery. This problem challenges you to design the frontend system responsible for this critical user-facing feature.

What you need to do / Task

You are tasked with designing the frontend architecture for a real-time food delivery tracking page. Your design should encompass the core UI components, data flow, state management, and strategies for efficiently handling and rendering frequent real-time updates to provide a smooth and intuitive user experience.

Scenario

Imagine a guest has just placed a food order through their Airbnb app. They navigate to an "Order Tracking" page where they expect to see the live status of their order, including a map showing their driver's current location and an estimated time of arrival (ETA), alongside a detailed timeline of order events (e.g., "Restaurant preparing," "Driver picked up," "On the way"). The system needs to keep these details updated in real-time as the order progresses.

Constraints

Constraints & assumptions

  • Target Device: Primarily mobile web and native app views (consider responsive design).
  • User Scale: Millions of active users, with thousands concurrently tracking orders during peak times.
  • Update Frequency: Driver location updates are pushed via WebSocket every 3-5 seconds. Order status changes are event-driven.
  • Backend API: Assume a robust backend WebSocket service is available, providing structured JSON payloads for driver location and order status updates. A REST API is available for initial order fetching.
  • Mapping: An existing mapping library (e.g., Google Maps API, Mapbox) can be utilized for rendering the driver's location.
  • Latency: Users expect near real-time updates with minimal perceived lag.

Out of scope

  • Backend API design and implementation.
  • Database schema or storage solutions.
  • Authentication, authorization, or payment processing.
  • The driver-side application or its internal logic.
  • Deep dives into specific map library implementations (focus on integration).

What interviewers evaluate

  • Ability to design a scalable and performant frontend architecture for real-time data.
  • Proficiency in selecting appropriate state management strategies for dynamic UI.
  • Understanding of efficient rendering techniques for frequently updating components.
  • Consideration of error handling and user experience under varying network conditions.

Requirements

1.

Identify and describe the core UI components for the order tracking page and their responsibilities.

2.

Outline the end-to-end data flow for real-time updates from the WebSocket service to the UI components.

3.

Propose a state management strategy, justifying the choice of library/pattern and state structure.

4.

Detail strategies for efficiently rendering frequent driver location updates on the map and other UI elements.

5.

Explain how different order status transitions and event-driven updates are managed and reflected in the UI.

6.

Describe mechanisms to ensure a smooth user experience despite frequent updates, including performance optimizations.

7.

Address error handling for WebSocket disconnections, malformed data, and unexpected order changes.

Design Brief

You are tasked with designing the frontend system for a real-time food delivery tracking experience within the Airbnb app. The core goal is to provide guests with immediate, accurate updates on their order's journey from the restaurant to their doorstep.

Your design should cover the following aspects:

1. Core UI Components

Identify and describe the main UI components that would constitute the order tracking page. Think about their responsibilities and how they would interact. Essential components typically include:

  • Map Component: Displays the driver's current location, the restaurant, and the guest's delivery address.
  • Order Status Timeline: A visual timeline showing the progression of the order (e.g., "Order Placed", "Restaurant Preparing", "Driver En Route", "Delivered").
  • Estimated Time of Arrival (ETA) Display: Prominently shows the dynamic ETA.
  • Driver Information: Displays driver's name, picture, and potentially a contact option.

2. Data Flow & Real-time Updates

Detail the end-to-end data flow for a single order. How does the frontend application subscribe to and receive real-time updates from the backend WebSocket service? How are these updates then propagated to the relevant UI components? Consider:

  • Initial Load: How is the initial order state fetched?
  • WebSocket Integration: How do you connect, listen, and manage the lifecycle of the WebSocket connection?
  • Payload Handling: How are incoming WebSocket messages parsed and validated?
  • Update Frequency Management: Given driver location updates every 3-5 seconds, how do you prevent UI churn while maintaining responsiveness?

3. State Management

Propose a robust state management strategy for the real-time order data.

  • Which parts of the order data should be global vs. local component state?
  • How would you structure the state to be easily consumed by different components?
  • Discuss the choice of state management library/pattern (e.g., Redux, Zustand, React Context API, custom solution) and justify your decision given the requirements.

4. Performance & User Experience

With frequent real-time updates, performance is critical.

  • How do you ensure smooth rendering of the map and other UI elements without lagging, especially on mobile devices?
  • What strategies would you employ to optimize re-renders?
  • How would you handle potential network latency or temporary disconnections to provide a graceful user experience (e.g., showing stale data, loading indicators, retry mechanisms)?

5. Error Handling & Edge Cases

Describe how your system would handle various error scenarios and edge cases:

  • WebSocket connection failures or disconnections.
  • Malformed or unexpected data payloads.
  • Order cancellations or changes in delivery routes.

6. Scalability Considerations

Briefly discuss how your frontend architecture design scales with an increasing number of concurrent users and orders. How would your choices in state management and data flow accommodate future growth?

Be prepared to draw diagrams (e.g., component hierarchy, data flow) using a tool like Excalidraw to illustrate your design.

Loading editor...