Design Radius-Based Notifications from Mobile Locations
Company: Fora Travel
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Technical Screen
# Design Radius-Based Notifications from Mobile Locations
Design a system in which mobile applications periodically send their users' locations to a server. Given a target latitude, longitude, and radius `x`, the server finds users whose latest non-stale locations fall within the radius and sends each of them a notification.
Cover the location-update API, latest-location storage, geospatial candidate search, exact distance filtering, stale-data policy, and notification delivery. Explain how the design behaves when many users update at once.
### Constraints & Assumptions
- Only a user's latest accepted location is needed for the proximity decision.
- Location updates have timestamps and may arrive late or out of order.
- A geospatial index may return a coarse candidate set that needs exact radius filtering.
- Notification delivery is asynchronous and may be retried.
### Clarifying Questions to Ask
- How often does the mobile app update location, and how long before a location is stale?
- What notification latency is required after the radius query begins?
- What range can `x` take, and what user count and update rate must the system support?
- May one campaign notify the same user more than once?
```hint Index a coarse cell, verify exact distance
A cell or bounding-box lookup narrows candidates quickly, but points near the boundary still require a distance calculation.
```
```hint Decouple selection from delivery
Persist the intended recipients before fan-out so a notification worker retry does not rerun a changing location query.
```
### What a Strong Answer Covers
- Authenticated, timestamp-aware location updates with stale-write rejection.
- A latest-position store plus a geospatial index and exact radius filtering.
- Expiration of stale locations and clear boundary semantics for `x`.
- Durable recipient fan-out, idempotent notification attempts, and delivery observability.
- Partitioning, hotspot handling, backpressure, privacy, and deletion controls.
### Follow-up Questions
- How would you prevent a user near a cell boundary from being missed?
- What changes if the notification must follow moving users continuously rather than run once?
- How would users opt out and request deletion of stored location data?
Quick Answer: Design a mobile location service that finds users within a radius from their latest non-stale positions and sends notifications. Cover geospatial indexing, exact distance checks, stale updates, durable fan-out, privacy, and hotspot handling.