Zafgo
On this page

BLOGTechnical

How ride-hailing matching works: a dispatch architecture guide

What happens between a rider's tap and a driver's accept: the data, the search, the offer rounds and the edge cases every dispatch system has to handle.

Short answer

A ride-hailing matching system keeps a live index of where available drivers are, searches around the pickup when a request arrives, and offers the trip to one or more drivers in rounds with a time limit. The key design choices are how far to search, whether to offer to one driver at a time or to many at once, how to keep work fair between drivers, and what to do when nobody accepts. Most operators start with simple distance-based rings and clear timeouts; optimisation such as batching only pays off at high volume. Zafgo's matching engine uses two search rings and lets you choose a balanced mode or a first-to-accept mode.

The matching flow, step by step

  1. Drivers report location. Each online driver app sends its position to the server at a regular interval, together with its status: available, on the way, on a trip or offline.
  2. A rider requests a trip. The request carries the pickup point, the destination, the vehicle type and any options such as a payment method or a preference for a woman driver.
  3. The server finds candidates. It looks up available drivers of the right vehicle type within a search radius of the pickup.
  4. The trip is offered. The candidates see an offer screen with a countdown. The offer goes to one driver at a time, to a small group or to everyone in the radius, depending on the dispatch rules.
  5. A driver accepts, or the search widens. The first valid accept wins and the other offers close. If nobody accepts in time, the system widens the radius or ends the search and tells the rider.
  6. The trip starts. Rider and driver see each other on the map, and the system tracks the driver to the pickup and through the trip.

The building blocks

Components of a matching system
ComponentWhat it doesDesign questions
Location storeHolds the latest position and status of every online driverHow often drivers report; how stale a position may be before the driver is skipped
Spatial indexFinds drivers near a point quicklyGrid cells, geohashes or a spatial database; straight-line distance or road distance
Offer managerSends offers, runs countdowns and records accepts and declinesOne driver at a time or many at once; how long each offer stays open
Rules layerApplies fairness, vehicle type, rider preferences and driver eligibilityWhich rules are strict filters and which only change the order
Trip state machineMoves each trip through requested, accepted, arrived, started, finished or cancelledWhich transitions are allowed, and who can trigger each one
Real-time channelPushes offers and status changes to the appsPush notifications, WebSockets or both; what happens when a phone is offline

The trip state machine is the part teams most often underestimate. Every rule elsewhere, from cancellation fees to driver payouts, depends on knowing exactly which state a trip is in and who moved it there.

Offer strategies: one at a time or everyone at once

Common offer strategies
StrategyHow it worksStrengthsWeaknesses
Nearest first, one at a timeOffer to the closest driver; on decline or timeout, move to the nextShort pickups; simple to explainSlow when drivers decline; the nearest driver gets most of the work
BroadcastOffer to every available driver in the radius; first to accept winsFast acceptance in busy areasDrivers race each other; quieter drivers may get little work
Balanced roundsOffer first to drivers with the least work so far, then open to everyoneSpreads work more evenly, which helps keep driversSlightly slower than pure broadcast
Batched matchingCollect requests for a short window and solve the best assignment for all of themBetter total pickup times at high volumeMore complex; adds a small delay; needs many requests to pay off

There is no single best choice. In a new market with few drivers, speed of acceptance usually matters most. Once you have more drivers than requests, fairness becomes important, because drivers who wait a long time between trips leave for other apps. Our guide to getting your first 100 drivers explains why keeping drivers busy matters so much early on.

Search radius and timeouts

A small radius keeps pickups short but may find nobody. A large radius finds someone but sends drivers on long, unpaid drives to the pickup. A common answer is to search in rings: start with a small radius, and widen it only if nobody accepts within a set time.

Timeouts need the same care. An offer that stays open too long makes the rider wait; one that closes too fast gives drivers no time to read it, especially while driving. Scheduled bookings need different settings again, because there is time to search further and longer before the pickup.

Straight-line distance is cheap to calculate, but rivers, one-way streets and motorways can make a driver 500 metres away much further by road. Many systems use straight-line distance to find candidates and road distance or travel time, from a routing service, only to rank the short list. That also keeps the cost of map API calls under control.

Edge cases to plan for

  • Two accepts at once. Two drivers accept the same offer within milliseconds. The server must accept exactly one, atomically, and close the other offer.
  • Stale locations. A driver's phone loses signal and their last position is minutes old. Skip drivers whose position is too old.
  • Driver goes offline after accepting. Detect it, tell the rider and search again without making them start over.
  • Rider cancels mid-search. Close all open offers immediately so drivers don't accept a trip that no longer exists.
  • Preferences that shrink the pool. A rider asks for a woman driver or a larger vehicle and nobody matches. Decide whether to offer a wider search, with the rider's consent.
  • Airports and events. Queues at airports and crowds after events need their own rules, such as a driver queue or a pickup zone.

How Zafgo's matching engine works

Zafgo searches in two rings around the pickup. If nobody accepts within the first ring's wait time, the search widens to the second ring, while drivers in the first ring keep seeing the request. Scheduled bookings have their own rings with longer distances and times.

You choose one of two platform-wide modes. Normal offers each request first to the nearby available drivers with the fewest jobs that day, then to every available driver in the ring. Open to everyone shows the request to every eligible driver in the ring at the same moment, and the first to accept gets it. Dispatchers can also assign instant requests by hand from the console. See dispatch and the matching engine guide for the settings.

Questions people ask

How does Uber-style matching find the nearest driver?

The server keeps the latest location of every available driver in a spatial index, such as a grid or a geospatial database, and looks up drivers within a radius of the pickup. It then ranks them by distance, travel time or other rules and sends offers.

Should I offer a trip to one driver or to all drivers?

One at a time gives short pickups but can be slow when drivers decline. Offering to everyone at once is faster but makes drivers compete. Balanced modes, which favour drivers with less work first, are a middle path that helps keep drivers.

What is batched matching?

Instead of matching each request on its own, the system collects requests for a few seconds and finds the best assignment for all of them together. It improves total pickup times when there are many requests and drivers, but adds complexity and a short delay.

How often should driver apps send their location?

Often enough that positions are fresh when a request arrives, but not so often that it drains batteries and data. Many apps send updates more often during a trip than while the driver waits for requests.

Can I build my own matching on top of Zafgo?

The matching engine is part of the platform and is configured in the console. If you license Zafgo's source code, your developers can change the matching logic themselves.

Sources

  1. Zafgo help: matching engine and dispatch modes checked
  2. Zafgo dispatch: rings, modes and manual assignment checked
Book a demoSee pricing