KatInterview

Fix a Ride Dispatch Selection Bug

Data Structure DesignModel answer
MediumModel answerData Structure Designdebuggingtestingconcurrency

Last updated

Reproduce and fix a bug causing incorrect driver-to-order matching in a delivery assignment service.

You're working on a ride-hailing or delivery platform. The system assigns available drivers to incoming orders based on proximity and other factors. Recently, customers have complained that they're being matched with drivers who are farther away, while closer drivers remain available.

You have access to the codebase for the driver selection service. Given a specific failing scenario where an order was matched to the wrong driver, your task is to:

  1. Reproduce the incorrect assignment using the provided inputs (candidate driver IDs, their cached GPS coordinates with timestamps, and the pickup location)
  2. Write a minimal test case that fails with the current code
  3. Identify the root cause of the bug
  4. Implement a fix
  5. Explain how you would add observability and resilience features

Discuss your debugging methodology, the time and space complexity of your solution, and how you would handle edge cases like: no available drivers, tied distances, GPS coordinate noise, delayed location updates, service outages, and high request volume.

The service fetches driver locations from a cache, filters for availability and recency, then selects the best match based on distance and load.

Hints

Hint 1

Pay close attention to how timestamps are represented and compared – are all time values using the same units?

Hint 2

Consider what happens when cached location data becomes stale, and how the freshness check actually behaves with mixed units.

Hint 3

Think about making your fix testable by injecting dependencies like the clock, and ensuring deterministic behavior for tie-breaking.