Skip to content

Dispatch under stale data and contention

10 min reading

A revision for conflicting claims, lost responses and delayed updates

Page details

System Design · Compose complete systems

10 min reading · 25 min with practice

Sources

Published · Last edited:

Prerequisite: Dispatch: fresh locations and exclusive assignments. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. A stadium exit concentrates Northwind dispatch requests. A driver crosses a spatial-cell boundary while old samples remain visible, and an offer response arrives after expiry. Dev lets each cell accept independently. Maya asks which rule prevents two assignments of the same driver.

Dev: “Both cells can discover the driver.”

Priya: “Discovery can overlap; who owns the single acceptance decision?”

Evolve the baseline under contention and stale observation. Keep geographic candidate organization separate from assignment authority, and preserve the original operation when its answer is lost. The burst changes concentration, not what a valid assignment means.

Which responsibility moves with the geographic observation?

Spatial cells can organize candidate observations and distribute queries. They are not automatically permanent ownership of a driver. A vehicle moves while its old sample remains in another cell, so both cells can temporarily return it. Candidate duplication must not become independent assignment authority.

Maintain one coherent accepted driver/request transition or a documented ownership handoff that excludes conflicting writers. Moving an observation and transferring assignment authority are different state changes. A complete design says how in-flight offers and delayed samples behave while either change is occurring.

Two discovery cells lead to one assignment authorityA moving driver can appear in old and new spatial cells during delayed updates. Both cells supply candidates to one guarded driver and request state transition. Offer identity and generation must still match when acceptance arrives.Old cell sampleMay remain staleNew cell sampleCandidate viewOne driver authorityOffer generationAccepted stateOr conflict
Spatial coverage can overlap while accepted ownership remains exclusive.

Count candidate work before choosing a wider search

Hypothetical worked example. Choose fifty assignment requests per second, each examining twenty candidate records. Candidate evaluation is 50 × 20 = 1,000 checks per second. A revised fifty-candidate budget produces 50 × 50 = 2,500 checks per second. The increase is 2,500 − 1,000 = 1,500 checks per second before any extra routing or offer work.

These checks are logical evaluations, not necessarily network calls or physical database reads. A set-based query may combine them, and a poor spatial predicate may examine additional records before returning candidates. Larger coverage can improve the chance of finding someone eligible while spending more work and offering drivers farther away.

For a selected stale observation, retain the baseline fifteen-metre-per-second speed bound. At twenty seconds of sample age, possible travel under that bound is 15 × 20 = 300 metres, compared with the earlier ten-second example’s one hundred fifty. The difference is 300 − 150 = 150 metres. This remains a bound under assumptions, not actual position or road travel time.

Select offer generation 7, then reassignment generation 8. A delayed response naming 7 cannot change a record whose authorized current offer is 8. Comparing 8 − 7 = 1 identifies a generation advance; the authority check, not the numerical difference alone, rejects the obsolete transition.

Define the winner of accept, expire and reassign

Hypothetical scenario. Offer O7 names request K, driver D, expiry and assignment generation 7. Acceptance is a conditional transition on the current offer, not an unqualified message saying yes. When expiry wins first, a new generation may be offered; a late acceptance for O7 must not revive it.

Define the winner of accept, expire and reassign — selected design evidence
Offer fieldExampleCondition
IdentityO7 linked to KSame intention on retry
Stateoffered / accepted / expiredLegal atomic transition
Generation7 then 8Reject obsolete accept
Ownership epochgeographic owner epochFence old dispatcher
Accept and expiry race at the same authority; only one legal transition can win.Accept and expiry race at the same authority; only one legal transition can win. Offered O7 to Accepted O7: accept wins current condition; Offered O7 to Expired / new O8: expiry wins current condition.Offered O7Accepted O7Expired / new O8accept wins current conditionexpiry wins current condition
Accept and expiry race at the same authority; only one legal transition can win. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

A geographic handoff moves assignment ownership, not merely spatial lookup. Transfer the current state and recoverable operation identities, fence the former owner and advance the ownership epoch. A stale dispatcher may still send messages after a partition; the effect target must reject its obsolete generation.

Location freshness and assignment exclusivity remain independent. A fresh driver can already be assigned, and a safely exclusive assignment can rely on a poor arrival estimate. Measure candidate evaluation, offer acceptance and reassignment outcomes separately. During contention, expanding the candidate set increases checks and may improve discovery, but it does not remove the serialized grant boundary.

A lost answer needs the original operation

Acceptance can commit while its response is lost. The driver then sees uncertainty even though the service has an accepted assignment. A matching retry inspects that operation and returns its permitted current result. Creating another assignment intention would bypass recovery of the first.

Similarly, a cancellation click on one phone does not establish a committed cancellation. The server-side state machine resolves its race with acceptance and communicates the resulting state. Local timers can stop waiting or change presentation, but the effect boundary decides which transition occurred.

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 failure 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.

Where location and assignment guarantees stop

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.

In the wild: a grid supports spatial analysis

The H3 project documentation describes a hierarchical spatial index. It supports separating spatial representation from application decisions. The grid does not by itself reserve a driver or establish Northwind’s offer protocol.

Challenge the proposed mechanism

The target enforces the new owner even if the old process resumes.The target enforces the new owner even if the old process resumes. New owner epoch8 to Assignment target: 1 · current generation advances; Old owner epoch7 to Assignment target: 2 · obsolete acceptance rejected.Old owner epoch7Assignment targetNew owner epoch81 · current generation advances2 · obsolete acceptance rejected
The target enforces the new owner even if the old process resumes. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

An old dispatcher resumes after reassignment and reports acceptance. What evidence must the protected target inspect?

Reveal the design reasoning

Offer identity, assignment generation, current state and owner epoch. Checking only message arrival time or driver location is insufficient. Recover any previously accepted result under the original K rather than creating another assignment.

Decision and reconsideration: Fence assignment transitions across expiry and handoff. Test late acceptance after both reassignment and ownership change.

Defend contention and handoff

  1. A driver appears in two cells. May both cells accept a request independently?

    Preserve exclusive authority

    No. Discovery overlap is possible during movement. Accepted assignment still needs one guarded authority or a correct ownership-transfer protocol excluding conflicting writers.

  2. The phone’s offer timer expired. Does that prove the remote acceptance failed?

    Reconcile server-side state

    No. A local deadline bounds waiting or presentation. Inspect the exact offer generation and authoritative accepted state before deciding the next action.

  3. A wider radius finds more candidates. Has it solved double assignment?

    Separate coverage from exclusivity

    No. It changes discovery cost and coverage. The conditional assignment transition still decides which competing request may succeed.

Dispatch separates shared observation from an exclusive effect. Page 55 begins a case with a different goal: preserve multiple legitimate editing operations and define how their concurrent meanings combine.

Northwind decision log

Preserve one accepted authority across overlapping spatial views.
Bind late responses to exact offer identity, generation and current state.
Next, model concurrent document edits before choosing merge behavior.

Go deeper: spatial operations and their limits