Problem statement
Design a service that decides, for a given coordinate, which delivery zones (and their owning stores) cover it, resolving overlaps by priority, at the read scale of a marketplace checkout and browse flow.
Operating context. Merchants draw polygonal serviceable areas around their stores. At checkout and while browsing, the product asks: for this address, which stores can deliver here, and is store X serviceable? Zones overlap (competing stores, tiered coverage), so a lookup must resolve them deterministically. Merchants edit zones frequently and expect changes to take effect quickly, but a lookup must never block on a config write. Reads dominate heavily.
Out of scope. The delivery-fee and pricing rules beyond identifying the covering zones, the merchant onboarding UI, dispatch and driver assignment, and store inventory/availability. Assume those consume your coverage result.
What to produce. A high-level architecture covering: how zone polygons are stored and spatially indexed so a lookup tests only nearby candidates; the point-in-polygon evaluation at scale, including complex polygons; deterministic overlap resolution by priority or smallest-area; caching coverage results by cell and invalidating on edits; zone versioning and how an edit propagates within a bounded staleness window; regional partitioning; and failure behavior when the config store is degraded. Sketch the components and the flow of one coverage lookup; we will probe specifics in checkpoints.
Functional requirements
- Given a coordinate, return all delivery zones and owning stores that cover it.
- Resolve overlapping zones deterministically by priority or smallest-area rule.
- Let merchants create, edit, and deactivate polygonal zones.
- Answer a fast boolean 'is store X serviceable at this coordinate?' check.
- Propagate zone edits so lookups reflect them within a bounded staleness window.
Non-functional requirements
- Serve 100,000 coverage checks/sec; per-lookup p99 < 60 ms.
- Index 500,000 active zones, polygons up to a few thousand vertices each.
- Zone edits visible to lookups within 60 seconds globally.
- 99.95% availability of the lookup path; serve last-known zones during a config outage.
- Durable, versioned zone geometry; no lost edit on an AZ failure.
- Cache hit rate >90% via cell-based caching of coverage results.
Topics
- System Design HLD
- Geo Spatial-Index
- Geo Polygon
- Data Cache
- Scaling Read-Heavy