Engineering Case

Engineering Reliable Real-Time Dispatch, Matching & Fare Negotiation

How I designed the backend workflow for driver matching, concurrent ride acceptance, fare negotiation, and real-time synchronization in a production ride-sharing system.

Context

From the customer's perspective, requesting a ride appears simple: request a ride, find a driver, accept the ride, and complete the trip. In production, multiple eligible drivers may receive the same ride opportunity at nearly the same time. Drivers can accept or reject requests, submit fare bids, or become unavailable while the process is running, while customers expect ride status and fare changes to appear immediately.

Constraint

The system needed to guarantee that a ride could not be assigned to multiple drivers when concurrent acceptance requests arrived. It also needed to support fare negotiation, driver eligibility, wallet-related checks, real-time synchronization, ride status transitions, location updates, and recovery when a driver became unavailable or a dispatch workflow could not complete normally.

Approach

  1. Modelled the ride lifecycle as controlled state transitions instead of allowing individual API endpoints to change ride status arbitrarily.
  2. Implemented a short-lived server-side acceptance lock to protect the critical section when multiple drivers attempted to accept the same ride concurrently.
  3. Revalidated ride status, driver availability, eligibility, and account conditions on the server immediately before finalizing an assignment rather than trusting stale client-side state.
  4. Designed fare negotiation as an explicit workflow covering initial fare, driver bids, customer responses, counter-offers, and final confirmation instead of treating each bid as an unrelated message.
  5. Synchronized important state changes between customers and drivers through real-time communication while keeping the backend as the authoritative source of truth.
  6. Separated operations requiring immediate updates, such as ride status, location, and fare changes, from background work that could be processed asynchronously.
  7. Designed recovery paths for disconnects, stale clients, failed updates, driver reassignment, cancellation, and other partial or exceptional states.
  8. Used the backend state to reconstruct the current ride status when a client missed a real-time event, avoiding dependence on every event being delivered successfully.

Result

The resulting dispatch workflow supports concurrent driver interaction while maintaining consistent ride state across matching, acceptance, fare negotiation, status transitions, real-time updates, communication, and reassignment. The system operates as part of a production ride-sharing platform handling 15K+ completed rides per month.

Lesson

Real-time systems are not primarily a WebSocket or messaging problem. The harder engineering problem is maintaining consistent state under concurrency. Real-time communication tells users that something changed, but the backend must guarantee that the underlying state remains valid when multiple users, devices, and services attempt to change it simultaneously.