MongoDB

Designing a Ride-Sharing System

Architecture of an Uber-like ride-sharing system — covering geo-location, driver matching, surge pricing, and real-time tracking.

S

srikanthtelkalapally888@gmail.com

Designing a Ride-Sharing System

A ride-sharing platform matches riders with nearby drivers in real-time.

Core Features

  • Request a ride
  • Match with nearby driver
  • Real-time GPS tracking
  • Dynamic pricing (surge)
  • Payments

Location Service

Drivers send GPS updates every 4 seconds.

Driver App → Location Service → Redis (Geo)

Redis GEO commands:

GEOADD drivers:active lng lat driver_id
GEORADIUS drivers:active -73.9 40.7 5 km

Driver Matching

  1. Rider requests ride with pickup coordinates
  2. Find all drivers within 5km using GeoSearch
  3. Filter: available, correct vehicle type
  4. Rank by ETA (maps API)
  5. Send request to best driver
  6. 10s timeout → try next driver

Real-Time Tracking

  • WebSocket connection between rider/driver apps and server
  • Driver location pushed to rider every 4s
Driver → Location Service → Kafka → Rider WebSocket

Surge Pricing

Surge = f(demand / supply)
If demand > 2x supply: 1.5x price

Calculate per geographic zone (H3 hexagons) in real-time.

Trip Storage

  • Active trips: Redis
  • Completed trips: PostgreSQL
  • Analytics: Redshift

Maps & ETA

Integrate Google Maps or build routing engine using road graph + Dijkstra's algorithm.

Conclusion

Ride-sharing is a geo-intensive real-time system. Redis GEO, WebSockets, and fast matching algorithms are the core building blocks.

Share this article