Design a Geofencing Service
Design a service to trigger an event when a user enters or exits a predefined geographic area (geofence). Focus on efficient spatial querying for millions of users.
Why Interviewers Ask This
Interviewers at Uber ask this to evaluate your ability to design scalable spatial systems handling millions of concurrent mobile clients. They specifically test your knowledge of geospatial indexing, trade-offs between accuracy and latency, and how to optimize database queries for high-frequency location updates without overwhelming backend resources.
How to Answer This Question
1. Clarify requirements: Define scale (users per second), update frequency, fence complexity (polygons vs circles), and latency tolerance. 2. High-level architecture: Propose a pipeline where mobile devices send coarse updates, filtered by a lightweight service before hitting the core. 3. Data modeling: Discuss storing fences efficiently using R-trees or H3 hexagonal grids rather than raw coordinates. 4. Query optimization: Explain how to use spatial indexes to quickly filter candidate fences for each user position, avoiding full scans. 5. Edge cases: Address battery drain strategies, clock drift, and handling users moving near fence boundaries to prevent 'ping-pong' events.
Key Points to Cover
- Demonstrating knowledge of H3 or R-tree spatial indexing for efficient lookups
- Addressing the specific challenge of reducing mobile battery drain through throttling
- Proposing a solution for boundary oscillation or jitter to prevent false triggers
- Designing a decoupled architecture using message queues like Kafka for high throughput
- Explicitly discussing horizontal scaling strategies for the matching engine
Sample Answer
To design a geofencing service for Uber's ride-hailing scale, I'd start by defining constraints: we need to support millions of active drivers with location updates every few seconds while keeping latency under 200ms. Fi…
Common Mistakes to Avoid
- Ignoring the cost of frequent GPS polling on mobile devices, leading to unrealistic battery usage scenarios
- Suggesting a brute-force check of every fence against every user, which fails at scale
- Failing to define what happens when a user crosses a boundary multiple times in seconds (jitter)
- Overlooking the difference between static database storage and real-time stream processing needs
Sound confident on this question in 5 minutes
Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.