Skip to content

Part 9 · Blueprint 60

Proximity Service & Business Discovery

11 min reading · Sources · Editorial review pending

A matching spatial cell can contain distant or ineligible places and omit neighbors at boundaries.

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, Ride-Hailing & Geospatial Matching.

Sixty-second mental model

Problem: A matching spatial cell can contain distant or ineligible places and omit neighbors at boundaries.

Use: Search covering cells, then apply exact geometry and product filters.

Design boundary: Find eligible nearby businesses with exact distance filtering after spatial candidate discovery. Proximity discovery does not include road routing or ETA estimation.

Layer 1 · Intuition

Hypothetical scenario: Northwind is designing nearby-place search. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one place query means and which component owns the place version and geometry.

Think of a map directory narrowing candidates before exact distance checks. Separate the requester from place version and geometry, 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 businesses with exact distance filtering after spatial candidate discovery. Proximity discovery does not include road routing or ETA estimation.

Responsibilities on the request path

Nearby-place search: responsibilities and request directionFind eligible nearby businesses with exact distance filtering after spatial candidate discovery. Proximity discovery does not include road routing or ETA estimation.Place updatesSpatial cellsCandidate filterResult ranking
Find eligible nearby businesses with exact distance filtering after spatial candidate discovery. Proximity discovery does not include road routing or ETA estimation.

Workload and limiting resource

Hypothetical search intersects 12 cells with 100 candidates each: up to 1,200 candidate records need filtering before deduplication. Returning 20 results does not mean only 20 distance calculations. Smaller cells can reduce per-cell population while increasing the number intersected.

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

Nearby-place search: mutation boundaryValidate place coordinates and visibility. Then: Update cell membership with a source version. Then: Publish searchable candidates and retain deletion evidence.Step 1
Validate place coordinates and visibility.
Step 2
Update cell membership with a source version.
Step 3
Publish searchable candidates and retain deletion evidence.
Validate place coordinates and visibility. Then: Update cell membership with a source version. Then: Publish searchable candidates and retain deletion evidence.
  1. Validate place coordinates and visibility.
  2. Update cell membership with a source version.
  3. Publish searchable candidates and retain deletion evidence.

Observation and recovery path

Nearby-place search: observation boundaryFind all cells intersecting the search radius. Then: Compute the required distance/relation for candidates. Then: Filter policy and rank with stable pagination.Step 1
Find all cells intersecting the search radius.
Step 2
Compute the required distance/relation for candidates.
Step 3
Filter policy and rank with stable pagination.
Find all cells intersecting the search radius. Then: Compute the required distance/relation for candidates. Then: Filter policy and rank with stable pagination.
  1. Find all cells intersecting the search radius.
  2. Compute the required distance/relation for candidates.
  3. Filter policy and rank with stable pagination.

Failure that changes the decision

Hypothetical scenario: A place moves between cells and remains in both projections. Deduplicate by identity/version and reconcile stale membership.

Attempt this decision before reading the explanation

Is searching only the cell containing the user sufficient?

No. A nearby place may lie just across its boundary. Cover the query geometry, then calculate actual distance/eligibility.

Supporting mechanism analysis

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

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.

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 candidate can be stale or selected by another request. Trace the exclusive transition and its response before claiming that the driver belongs to this request.

This lets the map optimize finding candidates without becoming independent authority to commit the effect. The baseline must also explain uncertain and late responses.

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.

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.

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.

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.

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.

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.

Layer 3 · Internals

A proximity query first finds a bounded set of spatial candidates, then evaluates the actual distance or shape relation. Geohashes, quadtrees and hierarchical cells provide different covering and neighborhood properties. A cell prefix match alone does not answer an exact radius query, especially near cell boundaries. Query the necessary covering neighbors and apply a final geometry predicate.

PostGIS ST_DWithin has semantics that depend on geometry versus geography and the associated coordinate reference system; a distance value is meaningless without the unit and model. Business discovery adds eligibility beyond coordinates: category, opening hours, visibility and location version. These mostly stationary records have different write patterns from moving vehicles, so a high-read replicated index can be appropriate. Cache keys must include query and filter context, and invalidation must cover a moved or withdrawn place. Never describe a coarse candidate index as proof that a result is both nearby and currently open.

Trade-offs and limits

ApproachProvidesRequires
Hierarchical cell coveringNarrows candidates and supports reusable spatial partitions.Cell boundaries require neighbor coverage and exact filtering.
Database spatial indexCombines geometric predicates with stored records.Query selectivity and coordinate-system semantics still determine cost and meaning.

Recovery decision

Hypothetical scenario: A place moves between cells and remains in both projections. Deduplicate by identity/version and reconcile stale membership.

No. A nearby place may lie just across its boundary. Cover the query geometry, then calculate actual distance/eligibility.

Write your design before revealing the review

Is searching only the cell containing the user sufficient?

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. A nearby place may lie just across its boundary. Cover the query geometry, then calculate actual distance/eligibility.

A place moves between cells and remains in both projections. Deduplicate by identity/version and reconcile stale membership.

Check your understanding

Is searching only the cell containing the user sufficient?

No. A nearby place may lie just across its boundary. Cover the query geometry, then calculate actual distance/eligibility.

How would you recover from this failure: A place moves between cells and remains in both projections. Deduplicate by identity/version and reconcile stale membership.

Start with the exact boundary that failed. Validate place coordinates and visibility. Update cell membership with a source version. Publish searchable candidates and retain deletion evidence. Then recover evidence through the observation path: Find all cells intersecting the search radius. Compute the required distance/relation for candidates. Filter policy and rank with stable pagination. 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 search intersects 12 cells with 100 candidates each: up to 1,200 candidate records need filtering before deduplication. Returning 20 results does not mean only 20 distance calculations. Smaller cells can reduce per-cell population while increasing the number intersected. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Find eligible nearby businesses with exact distance filtering after spatial candidate discovery. Proximity discovery does not include road routing or ETA estimation.

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

Place updates, Spatial cells, Candidate filter, Result ranking name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Validate place coordinates and visibility.

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

Find all cells intersecting the search radius. Compute the required distance/relation for candidates. Filter policy and rank with stable pagination. No. A nearby place may lie just across its boundary. Cover the query geometry, then calculate actual distance/eligibility.

45-minute interview rubric

  1. 00–05: scope place query and place version and geometry.
  2. 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
  3. 12–28: draw place version and geometry, numbered writes and reads.
  4. 28–40: challenge recovery: Search covering cells, then apply exact geometry and product filters.
  5. 40–45: defend place_id placement, observations and remaining assumptions.

Go deeper

  • ST_DWithin · Primary document · postgis.net. Search covering cells, then apply exact geometry and product filters. Verified 2026-10-26.

Decision log

Search covering cells, then apply exact geometry and product filters.

Preserve place query identity and place version and geometry ownership.

Revisit changed workload, observations or recovery objectives.