Coordinate a hypothetical Northwind delivery assignment
Outcome. After this optional chapter, you can separate spatial candidate selection from exclusive assignment.
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.
The nearest driver may no longer be available
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.
An index result is only a candidate
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.
Work through coordinate a hypothetical Northwind delivery assignment
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.
Two searches can return the same available driver before either assignment commits. Protect the accepted transition with the chosen conditional update or transaction boundary. If one request wins, the other must reevaluate rather than treating its earlier candidate list as continuing authority. A larger search radius can find more candidates; it cannot enforce exclusivity.
An offer response also needs identity, generation and expiry. After reassignment, a delayed acceptance from the earlier offer should not change the current assignment merely because its request identifier is recognizable. Reconcile retries against the original operation and check the current generation where the effect is accepted. Begin with a bounded local search and a clear race policy; optimize routing and prediction after the authoritative state machine is explainable.
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. 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.
In the wild: Coordinate a hypothetical Northwind delivery assignment
Primary evidence for coordinate a hypothetical Northwind delivery assignment: Distance semantics depend on geometry/geography representation and units.
Offers need a race policy
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.
A late acceptance arrives after reassignment
Hypothetical scenario. The service expires one offer and assigns the request elsewhere. A delayed acceptance from the previous driver arrives with the original request identifier but no offer generation. A handler that checks only request existence can create a second valid-looking assignment.
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.
If the database response is lost after acceptance commits, preserve uncertainty and reconcile the same operation. Creating a new assignment request to recover a missing response can bypass the original invariant. The same effect-boundary reasoning used for payments applies here without importing payment-specific policy.
Three dispatch misconceptions
“Closest means fastest arrival.” Geometric distance is one input. Road routing, current conditions and availability determine a different estimate.
“Recent receipt means recent observation.” A delayed sample can arrive now while describing an earlier position. Preserve origin and ordering evidence.
“An expired screen means an expired server operation.” Local presentation and authoritative offer state can diverge. Reconcile before assuming a business transition.
Bound the search before optimizing the map
Start with a declared region, freshness threshold and candidate budget. Expand deliberately when no acceptable candidate exists, recording the cost and resulting user wait. Do not silently scan the entire fleet to make every query appear successful.
Monitor stale-sample rejection, candidate counts, offer acceptance, obsolete transitions, assignment conflicts and unresolved outcomes. Separate location pipeline health from assignment success. A perfectly fresh map can coexist with a broken offer state machine.
Partition candidate discovery geographically where useful, but preserve a coherent assignment authority for drivers crossing cells. A boundary handoff must not make the driver independently available in two partitions. Reject a design that equates a spatial cell with permanent ownership of a moving person.
Limits of coordinate a hypothetical Northwind delivery assignment
The partner fleet size and update intervals are illustrative. Position age, spatial representation and query selectivity affect real candidate quality and cost. An exclusive assignment also needs an authoritative acceptance rule, and a late response must satisfy the current offer generation rather than only its original request identity.
Check yourself: review assignment
A candidate is close but its sample is old. What should matching know?
The observation age and chosen freshness policy, not just distance. A recent network receipt alone does not establish a current location.
Two requests select the same candidate. What protects against double assignment?
A coordinated conditional transition at the authoritative driver/assignment boundary. Independent spatial queries do not enforce exclusivity.
An offer response arrives after reassignment. Can request identity alone validate it?
No. Check offer generation, expiry and current state. Reconcile retries against the original operation rather than creating a new effect.
Two valid nearby-candidate queries return the same available driver. Does a smaller distance radius prevent double assignment?
No. Radius changes candidate selection, while exclusivity belongs to the accepted state transition. Both requests can still race for the same close candidate. Use the chosen conditional assignment or transaction boundary, and reevaluate the losing request against current availability. A late response must also satisfy the accepted offer generation and expiry.
Northwind decision log
Use spatial results only as assignment candidates.
Accept an offer through an authoritative conditional transition.
Check freshness, offer generation and expiry before changing state.
Go deeper into distance and authoritative state
- Book chapter: PostGIS in Action, Third Edition, chapter 3: Spatial reference systems — Leo S. Hsu and Regina O. Obe. Use Spatial reference systems when reviewing coordinate a hypothetical Northwind delivery assignment.
- Book chapter: PostGIS in Action, Third Edition, chapter 9: Proximity analysis — Leo S. Hsu and Regina O. Obe. Use Proximity analysis when reviewing coordinate a hypothetical Northwind delivery assignment.
- Video lecture: CSE138 (Distributed Systems) L15: introduction to sharding; consistent hashing — Lindsey Kuper. Watch for the partitioning and authoritative API boundary.
- Primary documentation: ST_DWithin — PostGIS project. Inspect coordinate type, units and operator behavior before implementing distance eligibility.
Related blog: Retrying LLM Tool Calls Without Double-Charging: Idempotency Keys and Reconciliation.