Design an ETA (Estimated Time of Arrival) and Location Sharing service between driver and rider in a ride-hailing system like Uber or Lyft:
Let's see FR
FR
1.The system shall receive periodic location updates from drivers (and optionally, riders).
2.The system shall persist the latest known location of drivers in a time-series fashion for recent history (e.g., last X minutes).
3.The system shall support updating location with high frequency (e.g., every 2–5 seconds).
4.he system shall calculate the estimated time of arrival (ETA) from the driver's current location to the rider's pickup location.
5.The system shall recalculate ETA in near real-time as the driver moves.
6.The system shall consider traffic conditions and route constraints in ETA computation.
7.The system shall allow a rider to view the real-time location of the driver once the trip is accepted.
8.The system shall notify the rider when the driver is a few minutes away (configurable threshold) and also when driver has arrived preferred location.
9.The system shall show meaningful messages if ETA is not available due to failure.
NFR
1.The system shall process and propagate location updates with a latency of under 500ms end-to-end (from driver to rider). and ETA calculation should be happen with minimal latency
2.System should be highly scalable to support millions of concurrent location updates per second from active drivers globally.
3.It should support real-time location streaming to a large number of active riders simultaneously.
4.The system shall be highly available with a target of 99.99% uptime, ensuring real-time updates are always accessible.
API’s
1. POST /location/update
request {
"driver_id": "drv_12345",
"ride_id": "ride_abcde",
"latitude": 12.9716,
"longitude": 77.5946,
"timestamp": "2025-04-17T09:30:00Z"
}
response {
"status": "success",
"message": "Location updated"
}
2.GET /eta
/eta?driver_id=drv_12345&ride_id=ride_abcde
{
"ride_id": "ride_abcde",
"eta_seconds": 300,
"distance_meters": 2100,
"updated_at": "2025-04-17T09:30:01Z"
}
3.GET /location/live
/location/live?ride_id=ride_abcde
Rider gets real-time location of driver
response {
"driver_id": "drv_12345",
"latitude": 12.9720,
"longitude": 77.5950,
"bearing": 115.0,
"updated_at": "2025-04-17T09:30:03Z"
}
4.GET /notifications
Rider polls for relevant location-based notifications
/notifications?ride_id=ride_abcde
{
"notifications": [
{
"type": "driver_arriving",
"message": "Your driver is 2 minutes away",
"timestamp": "2025-04-17T09:31:00Z"
}
]
}
5.POST /location/share-link
Generate a shareable link to live driver location
request {
"ride_id": "ride_abcde",
"expires_in_seconds": 900
}
response {
"share_url": "https://app.example.com/share/ride_abcde/loc123",
"expires_at": "2025-04-17T09:45:00Z"
}
Database Schema
Database Schema Design
1. driver_location_realtime (e.g., Redis / DynamoDB)
Stores most recent location per driver.
{
driver_id: "drv_12345", -- Partition Key
ride_id: "ride_abcde", -- Optional (null if not on ride)
latitude: 12.9716,
longitude: 77.5946,
bearing: 125.0,
speed_kph: 32.4,
updated_at: "2025-04-17T09:30:00Z"
}
2. driver_location_history (e.g., Cassandra or Bigtable)
Stores time-series location history for diagnostics / audit.
{
driver_id: "drv_12345", -- Partition Key
timestamp: "2025-04-17T09:30:00Z", -- Clustering Key
latitude: 12.9716,
longitude: 77.5946,
ride_id: "ride_abcde"
}
3. ride_eta_snapshot (e.g., Redis for hot, PostgreSQL for cold)
Keeps latest ETA estimate per ride.
{
ride_id: "ride_abcde", -- Primary Key
driver_id: "drv_12345",
eta_seconds: 300,
distance_meters: 2100,
updated_at: "2025-04-17T09:30:01Z"
}
4. ride_state (e.g., PostgreSQL)
Tracks ride progress and metadata.
{
ride_id: "ride_abcde", -- Primary Key
rider_id: "rider_9876",
driver_id: "drv_12345",
pickup_lat: 12.9716,
pickup_lng: 77.5946,
drop_lat: 12.9081,
drop_lng: 77.6476,
status: "ARRIVING", -- Enum: REQUESTED / ACCEPTED / ARRIVING / ONGOING / COMPLETED
created_at: "2025-04-17T09:00:00Z",
updated_at: "2025-04-17T09:30:00Z"
}
5. location_share_links (e.g., Redis / SQL)
Tracks short-lived location-sharing URLs.
{
share_token: "loc123", -- Primary Key
ride_id: "ride_abcde",
driver_id: "drv_12345",
expires_at: "2025-04-17T09:45:00Z"
}
Optional Enhancements
Geo-indexing: Use PostGIS or ElasticSearch with geo-point indexing for querying nearby drivers.
Kafka: Stream driver location updates for downstream services (analytics, fraud, ML).
TTL & archiving: Apply TTL to real-time stores and periodically move data to cold storage (S3, BigQuery).
HLD
Driver Sends Location Update
Driver App
⬇
[API Gateway]
⬇
Location Ingestion Service
⬇
Location Store (latest + history) ➡️ Kafka (optional fan-out)
⬇
ETA Service (trigger async if ETA is impacted)
2. Rider Requests Live Location & ETA
Rider App
⬇
[API Gateway]
⬇
Ride Manager ➡️ (valid ride? driver assigned?)
⬇
Location Sharing Service ⬅️ Location Store (get latest driver location)
⬇
ETA Service ⬅️ Routing Adapter ⬅️ External Maps
⬇
Combine response to rider: { driver location + ETA }
3. Generate Location Share Link
Rider App
⬇
[API Gateway]
⬇
Location Sharing Service
⬇
Generates token, stores metadata in DB
⬇
Returns URL
4. Driver Nearing Pickup
ETA Service
⬇
Pushes event to Kafka/EventBus
⬇
Notification Service
⬇
Sends push/SMS/email to Rider


