You open Uber. You request a ride. In 10 seconds a driver is assigned. But how? 500 drivers are moving around your city RIGHT NOW. How does Uber find the nearest one instantly? Why does normal SQL fail at this scale?
This project demonstrates the solution using a microservices architecture with Redis Geospatial for efficient location queries, Kafka for event-driven communication, and Spring Boot for building scalable, distributed services.
| Service | Port | Responsibility |
|---|---|---|
| location-service | 8082 | Tracks real-time driver locations via Redis Geospatial |
| ride-service | 8083 | Manages ride lifecycle, publishes events to Kafka |
| matching-service | 8084 | Consumes ride events, finds & assigns best driver |
Driver Phone → Location Service → Redis (GEOADD)
Rider App → Ride Service → Kafka (ride.requested)
↓
Matching Service (consumer)
↓
Location Service (find nearby drivers)
↓
Matching Algorithm (score drivers)
↓
Kafka (ride.matched)
↓
Ride Service (update ride with driver)
docker-compose up -dThis starts Redis, MySQL, Zookeeper, and Kafka.
Wait 30 seconds for Kafka to fully start before running services.
cd location-service
mvn spring-boot:runcd ride-service
mvn spring-boot:runcd matching-service
mvn spring-boot:runPOST http://localhost:8082/api/v1/locations/drivers/update
{
"driverId": "driver:1",
"latitude": 12.9716,
"longitude": 77.5946
}
POST http://localhost:8082/api/v1/locations/drivers/update
{
"driverId": "driver:2",
"latitude": 12.9800,
"longitude": 77.5800
}
POST http://localhost:8082/api/v1/locations/drivers/update
{
"driverId": "driver:3",
"latitude": 12.9600,
"longitude": 77.6100
}
POST http://localhost:8083/api/v1/rides/request
{
"riderId": "rider:1",
"pickupLatitude": 12.9716,
"pickupLongitude": 77.5946,
"pickupAddress": "MG Road, Bangalore",
"dropLatitude": 12.9352,
"dropLongitude": 77.6245,
"dropAddress": "Koramangala, Bangalore"
}
GET http://localhost:8083/api/v1/rides/{rideId}
You will see driverId assigned and status = ACCEPTED
PUT http://localhost:8083/api/v1/rides/{rideId}/start
PUT http://localhost:8083/api/v1/rides/{rideId}/complete
GET http://localhost:8083/api/v1/rides/rider/rider:1
docker exec -it redis-geo redis-cli
# See all stored drivers
ZRANGE drivers:locations 0 -1
# Check specific driver position
GEOPOS drivers:locations "driver:1"
# Distance between two drivers
GEODIST drivers:locations "driver:1" "driver:2" km- Redis Geospatial (GEOADD, GEORADIUS)
- Kafka event-driven architecture (Producer/Consumer)
- Ride state machine (REQUESTED → MATCHING → ACCEPTED → STARTED → COMPLETED)
- Driver scoring algorithm (distance + rating weighted score)
- Service-to-service REST communication (Matching → Location Service)
- Docker Compose for infrastructure setup
Made with Love