Design a Location Sharing Service: Junior, Senior, and Staff Answers
When an interview asks you to design a location-sharing service (think of a "share my live location" feature), the goal is to see how you balance real-time data flow, massive read traffic, and privacy. The interviewer wants to know whether you can break a user-centric request into a clear path, choose the right data store, and think about failure and operational concerns at scale.
What the Interviewer Is Testing
- Scalability – can you support millions of users and thousands of location updates per second?
- Latency – location updates must appear within a few hundred milliseconds for a good UX.
- Consistency vs. Availability – how do you ensure a user sees the latest location without sacrificing uptime?
- Privacy & Security – how do you enforce sharing permissions and protect sensitive coordinates?
- Operational Insight – do you think about monitoring, cost, and fault isolation?
Core Requirements and Driving Numbers
| Requirement | Reasoning |
|---|---|
| Functional | Users can turn sharing on/off, invite a set of friends, and see a real-time map of invited friends’ locations. |
| Non-functional | Availability: 99.9% uptime for the API layer. Latency: < 100 ms for a location read. Throughput: Roughly 10 M users, of whom about 10 k are sharing at any moment, each sending an update every 10 seconds → about 1 k updates/second. Storage: Keep last 24 h of location per user (up to ≈ 8 640 points for someone sharing all day). |
| Privacy | Sharing list is per-user; only invited friends may read a location. |
The two numbers that drive the design are the update rate (≈ 1 k updates / sec) and the read latency target (< 100 ms). Both are ball-park figures; you can adjust them during the interview.
Request Path – One Hop at a Time
- Client → API Gateway – The mobile app sends a
POST /locationwith userId, lat/lon, timestamp. API Gateway validates auth tokens. - API → Lambda (or ECS) – The Lambda checks the user’s sharing list in a fast cache (ElastiCache Redis). If the user is not sharing, it returns an error.
- Write Path – The Lambda writes the location point to DynamoDB (partition key = userId, sort key = timestamp). DynamoDB’s write throughput easily scales to the 1 k updates / sec target.
- Read Path – A friend’s app calls GET /location?friendId=XYZ. The request hits API Gateway → Lambda. The Lambda fetches the latest point from DynamoDB or from Redis if the recent point is cached. The response is returned within the latency budget.
- Background Processing – A Kinesis stream (or MSK Kafka) captures every write event. Consumers persist data to S3 for long-term analytics and optionally feed a machine-learning model for activity prediction.
Data Model
- DynamoDB Table
UserLocations - PK:
userId(string) - SK:
timestamp(number) - Attributes:
lat,lon,accuracy - ElastiCache (Redis) stores the most recent location per user: key
loc:{userId}→ JSON blob with a TTL of a few seconds. - Sharing List stored in a separate DynamoDB table
SharingLists(PK =ownerId, attribute = set offriendIds). This table is read-heavy; it can be cached in Redis as well.
Key Choice
We pick DynamoDB for the primary store because it offers single-digit millisecond latency, automatic scaling, and fine-grained access control via IAM policies. Alternatives like Aurora would add latency and operational overhead for a write-heavy, low-complexity workload.
What a Complete Junior Answer Covers
- High-level diagram showing client, API Gateway, Lambda, DynamoDB, and Redis.
- Basic flow for update and read requests.
- Data model with the two tables (locations and sharing list).
- Simple scalability argument: DynamoDB can scale to 1 k writes/sec; API Gateway can handle the traffic.
- Mention of authentication (e.g., Cognito) and a brief note on privacy (only friends can read).
- Potential bottleneck: single DynamoDB table without sharding, but acceptable for the given numbers.
What a Senior Answer Adds
- Sharding strategy: Partition keys include a region prefix (
us-east-1#userId) to distribute load across partitions. - Cache hierarchy: Use Redis for the latest point, fall back to DynamoDB for older data. Explain cache-aside pattern.
- Event streaming: Kinesis or MSK captures every write for async processing (analytics, audit logs).
- Consistency handling: Explain eventual consistency of DynamoDB reads and why it’s fine for a few-second stale data.
- Security details: IAM policies scoped to
userId, and signed URLs for temporary access. - Monitoring: CloudWatch metrics for write latency, cache hit ratio, and error rates.
- Cost awareness: Rough cost estimate for DynamoDB reads/writes and Redis nodes at the given scale.
What a Staff Answer Adds
- Failure modes: Discuss partial outage of Redis and fallback to DynamoDB, handling throttling, and circuit-breaker patterns in Lambda.
- Operational runbooks: Automated alerts for latency spikes, scripts to warm-up cache after a cold start, and disaster-recovery plan (cross-region replication of DynamoDB).
- Cost-performance trade-off: Defend the choice of DynamoDB on-demand vs. provisioned capacity based on traffic variability; argue for reserved capacity if the service becomes a core feature.
- Privacy audit: Explain how to log sharing-list changes and provide a GDPR-compliant delete path.
- Scaling beyond the baseline: If the service grows to 100 M users (≈ 10 k updates/sec), we would add more shards, increase Redis cluster size, and consider DynamoDB Accelerator (DAX) in front of DynamoDB for reads.
- Latency budgeting: Break down the 100 ms target (API Gateway 5 ms, Lambda 10 ms, Redis 2 ms, network 20 ms, etc.) and show where headroom exists.
Common Mistakes That Sink This Question
| Mistake | Why It Hurts |
|---|---|
| Ignoring privacy | The core of a location service is who can see the data. No access control leads to an unrealistic design. |
| Over-engineering early | Jumping to a micro-service mesh or custom replication adds complexity without justification at the given scale. |
| Forgetting latency | Assuming eventual consistency is fine for all reads ignores the user-experience requirement of sub-100 ms updates. |
| Single point of cache | Relying on one Redis node creates a bottleneck; a cluster or fallback to DynamoDB is needed. |
| No monitoring | Without metrics you cannot detect the throttling that will appear once traffic spikes. |
How to Practice This
- Study a related worked design in the System Design AI library, one that ingests a stream of live location updates. Read its walkthrough and click the components for their notes.
- Draw your own canvas on the practice board. Replicate the flow, then try variations: replace DynamoDB with Aurora, or add a CDN for static map tiles.
- Run a mock interview with a peer. Explain the junior, senior, and staff layers, then ask for feedback on missing failure modes or cost considerations.
Questions people ask
What is the typical read-write ratio for a location sharing service?
Most services see far more reads than writes because each location update is broadcast to many friends. A common pattern is 5–10 reads per write, but the exact ratio depends on how many friends each user shares with.
Why use DynamoDB instead of a relational database?
DynamoDB offers millisecond latency, automatic sharding, and a simple key-value model that matches the "latest location per user" access pattern. A relational store would add join complexity and higher latency for the same workload.
How do you enforce that only invited friends can see a location?
Store the sharing list in a DynamoDB table and cache it in Redis. At request time, the Lambda checks the list before fetching the location. IAM policies can also restrict read access to the owner’s partition key.
What happens if the cache is cold after a deployment?
The first read will miss Redis and hit DynamoDB, which is still fast enough for the latency budget. A warm-up script can pre-populate the cache for active users to avoid the initial miss spike.