Design Find My Friends
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2020-05-17
Problem Statement
Design a location-sharing application that allows users to share their real-time location with friends, see friends’ locations on a map, and receive notifications about nearby friends or location changes. The system should be scalable, secure, and low-latency.
Functional Requirements (FR)
User Management
•Users can register/login using email, phone, or social accounts.
•Manage profile information (name, profile picture, privacy settings).
•Maintain friend lists and friend requests.
Location Sharing
•Share real-time location with selected friends.
•Allow temporary or permanent sharing.
•Support location updates every few seconds or as needed.
Friend Tracking
•Display friends’ locations on a map.
•Filter by proximity, availability, or groups.
•Optional: “Check-in” at places.
Notifications
•Notify when a friend is nearby or starts/stops sharing location.
•Notify for friend requests and updates.
Privacy & Permissions
•Users control who can see their location.
•Option to hide location temporarily or permanently.
History & Analytics (Optional)
•Track past locations for a limited period.
•Analytics for user’s movement trends or frequent locations.
Non-Functional Requirements (NFR)
•Scalability: Handle millions of users sharing real-time locations.
•Low Latency: Location updates and queries should be near real-time.
•Availability: System should be available 24/7.
•Security & Privacy: Encrypt location data, enforce access controls.
•Consistency: Ensure users see accurate friend locations.
Suggested Components / System Architecture
Client App
•Mobile apps (iOS/Android) that send location updates and display friends on a map.
API Gateway
•Entry point for client requests, handles authentication and routing.
User Service
•Manages user profiles, friends, and permissions.
Location Service
•Receives real-time location updates from users.
•Stores the latest location in a fast-access storage (e.g., Redis).
Notification Service
•Sends push notifications for location changes, friend activities, or alerts.
Database Layer
•Relational DB: Store user profiles, friends, and privacy settings.
•NoSQL / In-Memory DB: Store real-time locations for quick access.
1.Map/Visualization Layer
•Integrates with map APIs to render friends’ locations on client devices.
Data Flow (High-Level)
1.User opens app → app authenticates with User Service.
2.User sends location updates → Location Service stores latest location.
3.Friends query their friends’ locations → Location Service retrieves data from in-memory store.
4.Notifications triggered if a friend is nearby or privacy settings change → Notification Service sends alerts.
5.Optional analytics processed asynchronously → stored in a separate DB for historical data.
Key Design Considerations
•Real-Time Updates: Use WebSockets, MQTT, or push notifications for near real-time location updates.
•Data Partitioning: Shard users by region or ID to scale location services.
•Privacy & Security: End-to-end encryption for location data; strict access control.
•Caching: Use in-memory databases like Redis for fast friend-location retrieval.
•Offline Handling: Queue location updates if the user is offline and sync when back online.