Design Uber (Mobile)
Concepts Utilized: Real-Time Location (GPS/Core Location), WebSocket for Updates, Map Rendering, Geofencing, Battery Optimization, Push Notifications, Payment SDK Integration, Offline Handling
This document covers the mobile architecture for a ride-sharing application with real-time location tracking, map rendering, and ride state management.
Features
| Feature | Description |
|---|---|
| Real-time location tracking | Continuous GPS updates during active rides |
| Map display | Rendering driver positions and route visualization |
| Ride request and matching | Driver assignment and acceptance flow |
| ETA updates | Dynamic arrival time calculations |
| Payment processing | In-app payment via integrated SDKs |
| Push notifications | Ride status and driver arrival alerts |
Real-time Location
Location Service
The location service manages GPS accuracy levels and transmits coordinates to the server.
Implementation approach: Create a location manager and configure desired accuracy and distance filter. Start tracking to receive location updates. In the delegate callback, extract the latest location, send it to the server via WebSocket, and update local state for UI rendering.
WebSocket for Real-time Updates
WebSocket connections provide bidirectional communication for ride state changes.
Implementation approach: Create a WebSocket connection to a ride-specific endpoint. Set up a message handler that decodes incoming messages and dispatches appropriate state updates based on message type (driver location, ETA update, or ride status change). The unidirectional data flow updates the UI automatically when state changes.
Map Rendering
Marker Update Optimization
Differential updates minimize rendering overhead when driver positions change.
Implementation approach: Compare current marker IDs with new driver IDs. Remove markers for drivers no longer in the set. For drivers in the new set, either animate the existing marker to the new position or create a new marker. This differential approach avoids recreating all markers on each update, providing smooth animations and better performance.
Battery Optimization
Location accuracy settings vary based on ride state to balance precision and power consumption.
Implementation approach: Adjust location manager settings based on ride state:
- Searching: Use low accuracy (hundred meters) and large distance filter to conserve battery while still showing approximate location
- Matched/In ride: Use best accuracy and small distance filter for precise tracking during active rides
- Idle: Stop location updates entirely to minimize battery drain
Technical Constraints
| Constraint | Impact | Mitigation |
|---|---|---|
| Battery drain | Continuous GPS polling depletes battery within hours | Adaptive accuracy based on ride state |
| Bandwidth | Frequent location updates consume data | Batch coordinates and compress payloads |
| Offline maps | Connectivity loss renders maps unusable | Cache map tiles for the local region |
| Location accuracy | High accuracy increases power consumption; low accuracy causes marker jitter | Use appropriate accuracy for each ride state |