Skip to content

Part 5 · Blueprint 29

Ride-Hailing & Geospatial Matching

14 min reading · Sources · Editorial review pending

A nearby candidate is not proof that the vehicle is still fresh or unassigned.

More
20px
Reading list
Page details

Published date · Last edited:

Draft edition. Editorial review and supplementary reading recommendations are still being completed.

Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Database Sharding & Consistent Hashing, Idempotency Keys & Distributed Retries, Time, Clocks & Distributed Ordering: Lamport to TrueTime.

Sixty-second mental model

Problem: A nearby candidate is not proof that the vehicle is still fresh or unassigned.

Use: Use spatial discovery followed by an exclusive assignment decision.

Design boundary: Find eligible nearby drivers and allocate one driver to one active ride. Candidate discovery is approximate and freshness-bounded; assignment is a guarded state transition. Exclude global route optimization and navigation instructions from the initial dispatch service.

Layer 1 · Intuition

Hypothetical scenario: Northwind is designing ride-hailing dispatch. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one match means and which component owns the assignment record.

Think of a dispatcher matching fresh vehicle reports to waiting riders. Separate the requester from assignment record, then identify the retained evidence needed after failure.

Authority
The entitled state owner.
Invariant
A rule preserved across concurrency and failures.

Architecture and worked reasoning

Design boundary: Find eligible nearby drivers and allocate one driver to one active ride. Candidate discovery is approximate and freshness-bounded; assignment is a guarded state transition. Exclude global route optimization and navigation instructions from the initial dispatch service.

Responsibilities on the request path

Ride-hailing dispatch: responsibilities and request directionFind eligible nearby drivers and allocate one driver to one active ride. Candidate discovery is approximate and freshness-bounded; assignment is a guarded state transition. Exclude global route optimization and navigation instructions from the initial dispatch service.Location ingestSpatial cellsCandidate rankerAssignment owner
Find eligible nearby drivers and allocate one driver to one active ride. Candidate discovery is approximate and freshness-bounded; assignment is a guarded state transition. Exclude global route optimization and navigation instructions from the initial dispatch service.

Domain interface and access patterns

PUT /drivers/{id}/location with location_sequence; POST /rides → trip_id; POST /rides/{id}/claim with expected_driver_version

driver_locations(driver_id, source_sequence, observed_at, cell_id, coordinates); driver_state(driver_id, assignment_version, active_trip_id); trips(trip_id, rider_id, state, assigned_driver_id). Spatial indexes discover candidates; conditional driver state allocates them.

Workload and limiting resource

Hypothetical 100,000 active drivers reporting every five seconds produce 20,000 location updates/s. If nearby search visits nine cells containing 80 candidates each, it examines up to 720 candidates before distance and eligibility filtering. Cell size trades candidate count against boundary fan-out; neither average update rate nor geometric proximity alone determines dispatch latency.

Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.

Mutation or publication path

Ride-hailing dispatch: mutation boundaryAccept monotonic driver-location updates with timestamps. Then: Publish eligible driver candidates into spatial cells. Then: Create a conditional assignment under driver/trip authority.Step 1
Accept monotonic driver-location updates with timestamps.
Step 2
Publish eligible driver candidates into spatial cells.
Step 3
Create a conditional assignment under driver/trip authority.
Accept monotonic driver-location updates with timestamps. Then: Publish eligible driver candidates into spatial cells. Then: Create a conditional assignment under driver/trip authority.
  1. Accept monotonic driver-location updates with timestamps.
  2. Publish eligible driver candidates into spatial cells.
  3. Create a conditional assignment under driver/trip authority.

Observation and recovery path

Ride-hailing dispatch: observation boundarySearch intersecting nearby cells. Then: Filter by location freshness, availability and policy. Then: Rank candidates, then conditionally claim a driver rather than trusting the search result.Step 1
Search intersecting nearby cells.
Step 2
Filter by location freshness, availability and policy.
Step 3
Rank candidates, then conditionally claim a driver rather than trusting the search result.
Search intersecting nearby cells. Then: Filter by location freshness, availability and policy. Then: Rank candidates, then conditionally claim a driver rather than trusting the search result.
  1. Search intersecting nearby cells.
  2. Filter by location freshness, availability and policy.
  3. Rank candidates, then conditionally claim a driver rather than trusting the search result.

Failure that changes the decision

Hypothetical scenario: Two dispatchers choose the same apparently idle driver. Only one conditional assignment may succeed; the loser retries candidate selection without creating a second confirmed ride.

Attempt this decision before reading the explanation

Does choosing the nearest GPS point guarantee the fastest pickup?

No. Stale positions, road topology, travel direction, traffic and driver eligibility affect ETA. Distance narrows candidates; a route/ETA model and current assignment authority decide the useful outcome.

Supporting mechanism analysis

Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.

Hypothetical scenario. Maya adds a delivery dispatch experiment; two nearby orders can choose the same driver unless assignment has an authoritative transition.

In short. Use spatial results only as assignment candidates. Accept an offer through an authoritative conditional transition.

Hypothetical scenario. A dispatch service selects a nearby driver from a location index. Two requests choose the same driver, one location update is old, and the driver accepts after the first offer has expired. A fast nearest-neighbor query does not determine which assignment is valid.

The initial scope is matching one request to one available driver within a bounded search region. It includes location freshness, offers, acceptance, cancellation and recovery. Pricing, navigation, fleet optimization and autonomous control are excluded. Those are separate decisions with their own evidence and constraints.

Define assignment as an authoritative state transition, not a map animation. A candidate can be geographically eligible without being available, authorized or willing to accept. The system must preserve that distinction through retries and delayed messages.

A spatial index narrows the search using a geometric representation. It does not establish road travel time, current availability or the truth of a device's reported position. Location samples age while vehicles move and can arrive out of order.

Searching a larger radius may improve candidate coverage while increasing work and producing less useful offers. Returning the closest point by straight-line distance can be a poor choice where road networks, rivers or access restrictions dominate travel.

PostGIS's ST_DWithin documentation makes coordinate representation and distance semantics explicit. Geometry and geography have different unit considerations. A distance threshold without a declared coordinate system is an incomplete requirement.

Ingest authenticated location samples with device identity, observation time and an ordering rule appropriate to the source. Maintain a derived spatial view with sample age. Query it for candidates, then check current eligibility and create an offer under the driver's authoritative state.

An offer identifies driver, request, generation and expiry policy. Acceptance performs a conditional transition that excludes an incompatible assignment. An outdated offer cannot succeed merely because its response eventually arrived.

Use stable request and action identities across retries. Push delivery is a hint to inspect current offer state; it is not the sole record. A reconnecting driver or requester should reconcile against the authoritative assignment rather than infer the outcome from the last notification displayed.

A location observation and an accepted assignment are different facts. PostGIS can identify candidates satisfying a spatial predicate such as a distance bound, while the assignment store decides whether a driver is still available. The query result is evidence for candidate selection, not a reservation of the driver. Keep those stages explicit even when they share one database.

Consider a hypothetical partner fleet of one thousand drivers sending one position update every five seconds. The mean update rate is 1,000 / 5 = 200 updates per second. If a request considers twenty candidates and fifty assignment requests arrive each second, candidate evaluation accounts for 20 × 50 = 1,000 candidate checks per second. Neither number establishes a database machine size: index selectivity, record width, query shape and competing writes still need measurement.

Distance semantics depend on the representation and reference system. A coordinate difference is not automatically a distance in metres. PostGIS documents geography and geometry operations with their concrete measurement assumptions. Choose the appropriate type and operation for the service area, and keep an observation's age separate from its spatial distance. A recently received old sample is still an old observation.

Hypothetical scenario. Choose 10,000 active drivers reporting once every five seconds. Mean update demand is 10,000 ÷ 5 = 2,000 samples per second under evenly distributed reporting. If all devices synchronize their reports, the burst shape can be much less even despite the same mean.

At a chosen 100 bytes of logical sample payload, arrival payload is 2,000 × 100 = 200,000 bytes per second. Keeping one minute of raw samples requires 200,000 × 60 = 12,000,000 bytes, or 12 MB, before indexes, transport and replication. Keeping only the latest sample serves a different audit and debugging need from retaining history.

For a toy movement bound, choose a speed of 15 meters per second and a sample age of ten seconds. Unobserved travel can be 15 × 10 = 150 meters if that speed bound holds. It does not prove the driver's actual location or road distance. Position uncertainty and false reports remain outside that simple bound.

A request examines 30 spatial candidates. Suppose 12 have stale locations and ten of the remaining 18 are unavailable, leaving 18 −10 = 8 eligible candidates under the chosen checks. Those filters reduce the candidate set; they do not guarantee an acceptance.

In a flat toy coordinate example measured in kilometers, candidate A is three units east and four north of the pickup. Straight-line distance is√(3² +4²) = √25 = 5 km. This Euclidean illustration is not a real latitude/longitude calculation or a travel-time estimate. The distinction matters before implementing a production query.

Primary evidence for coordinate a hypothetical Northwind delivery assignment: Distance semantics depend on geometry/geography representation and units.

Sequential offers can reduce competing acceptances but increase time to assignment. Parallel offers can reduce waiting while creating additional rejection, expiry and fairness questions. Define which acceptance wins and what other recipients see after a winner is established.

Cancellation races with acceptance. The authoritative state machine must decide which transitions are legal and expose the resulting state to both parties. A timer on one phone cannot establish that a remote server canceled an offer.

Location freshness and assignment availability have different consistency needs. A slightly delayed map marker may be acceptable while double assignment is not. Avoid forcing every visual update through the strongest coordination boundary, but keep the assignment invariant protected.

Bind acceptance to the exact offer generation and current driver/request state. Reject obsolete transitions and return the current authoritative result where the caller is allowed to see it. Record why the attempt was rejected so the client does not keep retrying an impossible transition.

Layer 3 · Internals

Trade-offs and limits

ApproachProvidesRequires
Hierarchical spatial coveringNarrows candidate vehicles with reusable cell ownership.Boundary coverage and stale locations still need checks.
Exact geometry after retrievalValidates a candidate against the real distance rule.It does not discover a candidate omitted by an incomplete covering query.

Recovery decision

Hypothetical scenario: Two dispatchers choose the same apparently idle driver. Only one conditional assignment may succeed; the loser retries candidate selection without creating a second confirmed ride.

No. Stale positions, road topology, travel direction, traffic and driver eligibility affect ETA. Distance narrows candidates; a route/ETA model and current assignment authority decide the useful outcome.

Write your design before revealing the review

Does choosing the nearest GPS point guarantee the fastest pickup?

Evidence you can explain in your own design

Drafts and self-review are stored only in this browser. They are separate from reading completion.

Compare your decision

No. Stale positions, road topology, travel direction, traffic and driver eligibility affect ETA. Distance narrows candidates; a route/ETA model and current assignment authority decide the useful outcome.

Two dispatchers choose the same apparently idle driver. Only one conditional assignment may succeed; the loser retries candidate selection without creating a second confirmed ride.

Check your understanding

Does choosing the nearest GPS point guarantee the fastest pickup?

No. Stale positions, road topology, travel direction, traffic and driver eligibility affect ETA. Distance narrows candidates; a route/ETA model and current assignment authority decide the useful outcome.

How would you recover from this failure: Two dispatchers choose the same apparently idle driver. Only one conditional assignment may succeed; the loser retries candidate selection without creating a second confirmed ride.

Start with the exact boundary that failed. Accept monotonic driver-location updates with timestamps. Publish eligible driver candidates into spatial cells. Create a conditional assignment under driver/trip authority. Then recover evidence through the observation path: Search intersecting nearby cells. Filter by location freshness, availability and policy. Rank candidates, then conditionally claim a driver rather than trusting the search result. Preserve the distinction between a confirmed state change and an unavailable response.

Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?

Hypothetical 100,000 active drivers reporting every five seconds produce 20,000 location updates/s. If nearby search visits nine cells containing 80 candidates each, it examines up to 720 candidates before distance and eligibility filtering. Cell size trades candidate count against boundary fan-out; neither average update rate nor geometric proximity alone determines dispatch latency. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Find eligible nearby drivers and allocate one driver to one active ride. Candidate discovery is approximate and freshness-bounded; assignment is a guarded state transition. Exclude global route optimization and navigation instructions from the initial dispatch service.

Which component in this topology could be removed from a smaller first deployment?

Location ingest, Spatial cells, Candidate ranker, Assignment owner name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Accept monotonic driver-location updates with timestamps.

What evidence must a caller have before relying on the observation path?

Search intersecting nearby cells. Filter by location freshness, availability and policy. Rank candidates, then conditionally claim a driver rather than trusting the search result. No. Stale positions, road topology, travel direction, traffic and driver eligibility affect ETA. Distance narrows candidates; a route/ETA model and current assignment authority decide the useful outcome.

45-minute interview rubric

  1. 00–05: scope match and assignment record.
  2. 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
  3. 12–28: draw assignment record, numbered writes and reads.
  4. 28–40: challenge recovery: Use spatial discovery followed by an exclusive assignment decision.
  5. 40–45: defend vehicle_id placement, observations and remaining assumptions.

Go deeper

  • Introduction | H3 · Primary document · h3geo.org. Use spatial discovery followed by an exclusive assignment decision. Verified 2026-10-26.
  • ST_DWithin · Primary document · postgis.net. Use spatial discovery followed by an exclusive assignment decision. Verified 2026-10-26.

Decision log

Use spatial discovery followed by an exclusive assignment decision.

Preserve match identity and assignment record ownership.

Revisit changed workload, observations or recovery objectives.