Katkat

Design real-time delivery tracking with async updates

Nash AISoftware Engineer · Technical Screen

Last updated

This question tests the ability to design a high-throughput, real-time location tracking system that ensures eventual consistency and correct state representation despite network latency and duplicate events.

System Design: Real-time Delivery Tracking

Design a backend system to track the real-time location of food delivery couriers. The system must support millions of concurrent deliveries with low-latency updates and provide the current location of a courier to the customer's app.

Requirements

  1. Functional:

    • Accept location updates (latitude, longitude, timestamp) from courier devices (e.g., every 5 seconds).
    • Expose an API for customers to fetch the current location and estimated time of arrival (ETA).
    • Support a history view: fetch the path taken by the courier for a specific order.
  2. Non-functional:

    • High write throughput (millions of updates per minute).
    • Low-latency reads for active tracking.
    • High availability and eventual consistency.
    • Handle out-of-order messages and duplicate events gracefully.

Considerations

  • How will you ingest data from mobile devices? (Protocols, load balancing)
  • How do you ensure the "current" location is accurate when events arrive out-of-order?
  • How would you store the trajectory data versus the current status?
  • Discuss the trade-offs between using a SQL database, NoSQL (like Cassandra or DynamoDB), and an in-memory cache (like Redis).

Provide an architecture diagram (description), data model, and API design. Explain how you handle the "thundering herd" problem if many customers track the same courier (e.g., a popular restaurant).

Hints

Hint 1

Consider using an event streaming platform like Kafka to decouple ingestion from persistence and state processing.

Hint 2

Use timestamps to handle out-of-order events; only update the 'current' location if the incoming event's timestamp is greater than the existing record's timestamp.

Hint 3

Distinguish between 'hot' data (current location in cache) and 'cold' data (full path history in persistent storage).

Follow-up questions

  • How would you implement geofencing to trigger notifications when a courier is within 500 meters of the delivery destination?
  • If the courier's device is offline for 2 minutes and then reconnects, how do you process the batch of cached location updates?
  • How would you implement a 'dead-man's switch' or detect if a courier has stopped moving unexpectedly?