Hypothetical scenario. Northwind’s dispatch experiment finds a nearby driver for a request. Dev calls the spatial match assigned. Priya runs a second request against the same driver and asks whether either result establishes exclusive acceptance.
Maya: “The map helps us discover candidates.”
Dev: “The actual assignment needs its own freshness, eligibility and authority rules.”
Build a baseline separating location samples, candidates, offers and accepted assignments. A late offer response and an old location must not silently redefine who owns the work. The selected fleet and report rates are a teaching cohort, not actual Northwind workforce measurements.
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.
Which fact turns a nearby candidate into an assignment?
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.
Separate location observation from assignment authority
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.
Use spatial candidates before conditional assignment
Hypothetical scenario. A driver near a spatial-cell edge may be closer to a request in the neighboring cell. Candidate discovery must cover the query neighborhood rather than only the request's own cell. Resolution trades candidate count against indexing and neighbor work; the exact geometry and distance predicate belong to the selected spatial implementation.
| Record | Example fields | Responsibility |
|---|---|---|
| Location | driver D, sample sequence, time, cell | Fresh candidate evidence |
| Spatial membership | cell → driver identities | Neighborhood discovery |
| Assignment | request K, D, generation, state | Exclusive conditional grant |
A location sample carries driver identity, sample sequence, observed time and coordinate evidence. Ignore reordered older samples under the declared update rule. Sample freshness limits uncertainty but cannot prove a driver's future position or exact arrival time. Use a distance or travel estimate as a ranking input with stated limits.
After discovery, a conditional authoritative assignment grants the driver to one request. Two dispatchers can examine the same fresh candidate set; the spatial index cannot decide their exclusive winner. The accepted assignment records its request identity, driver, generation and state so retries can recover the same grant. Keep location-update demand separate from assignment-transition demand.
Derive freshness, search and update demand
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. The squared offsets sum to 3 × 3 + 4 × 4 = 9 + 16 = 25. Straight-line distance is √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.
In the wild: distance has representation-specific semantics
PostGIS documents ST_DWithin with geometry and geography distance semantics. This is a concrete check on candidate discovery. It does not establish a driver’s current availability or authorize an exclusive assignment.
Two valid searches choose one driver
Hypothetical failure scenario. Two request handlers obtain the same nearby available driver before either commits. Each treats its index result as a reservation and sends a confirmation. The spatial predicate was evaluated correctly, yet the system has created incompatible assignments.
Make acceptance conditional on the current authoritative driver and request state. A winning transition excludes the conflicting one; the loser reevaluates rather than relying on its older candidate list. Stable operation identity recovers a lost acceptance response without creating a new assignment.
Keep observation and exclusive authority distinct
Start with a bounded search area, declared sample-age policy and explicit offer state machine. PostGIS can support candidate discovery while a PostgreSQL transaction protects accepted assignment where the chosen ownership permits it. The design does not require a separate service for every map operation.
Record which location observation supported an offer and how stale it was. Recent receipt is not recent observation if the sample spent time offline. Driver reports also need authentication and validation; the simple motion calculation cannot prove the truth of a reported coordinate.
Retain the state required for both parties to reconcile cancellation, expiry and accepted assignment. A notification is a hint to inspect that state, not the only evidence. The next page tests delayed acceptance, concentrated search work and handoff across spatial cells.
Challenge the proposed mechanism
D crosses a cell boundary while two requests select D. Which two different mechanisms are needed?
Reveal the design reasoning
A location/index update rule preserving neighborhood coverage, and an exclusive assignment transition at the owner. Better spatial accuracy cannot replace conditional assignment, and a safe assignment does not guarantee candidate completeness.
Decision and reconsideration: Keep geographic discovery and assignment authority separate. Reconsider cell resolution using coverage, candidate work and movement evidence.
Defend candidate and assignment
A point is geographically close but its sample is old. What does matching need?
Inspect observation age
The original sample time, ordering evidence and declared freshness rule. Network receipt now does not make the observed position current.
Two requests choose the same driver. Does a smaller radius enforce exclusivity?
Protect acceptance
No. The spatial predicate selects candidates. A conditional authoritative transition decides which assignment may be accepted.
A geometry threshold is specified as five. Is the distance contract complete?
Name the representation and unit
No. State the coordinate system and operation’s units. A raw latitude/longitude difference is not automatically a distance in metres or road travel time.
The baseline gives assignment its own authority. Page 54 keeps that contract while requests concentrate geographically, samples arrive late and a moving driver appears around a cell boundary.
Northwind decision log
Use location observations for candidates, with explicit age and units.
Accept exclusive assignment through one guarded authority.
Next, preserve that authority through expiry, contention and cell movement.
Go deeper: spatial meaning and ownership
- Book chapter: PostGIS in Action, third edition, chapter 3: Spatial reference systems — Leo S. Hsu and Regina O. Obe. Establish coordinate meaning and units.
- Book chapter: PostGIS in Action, chapter 9: Proximity analysis — the same authors. Inspect nearby-candidate operations.
- Video lecture: PostGIS Day 2023: Ask us anything — Paul Ramsey and Regina Obe. Examine spatial database operations and their limits.
- Primary document: ST_DWithin — PostGIS. Inspect the actual distance predicate.