Skip to content

divyamtayal/mini-uber-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚖 Mini-Uber Backend (Microservices Architecture)

A production-grade event-driven microservices project inspired by Uber, built with Spring Boot, Kafka, Eureka, Gateway, Zipkin, Prometheus/Grafana, Redis, and Postgres.


🏗️ Architecture

Architecture Diagram

🏗️ Kafka topics map

Kafka Diagram

Services

  • API Gateway (Spring Cloud Gateway + JWT Security + Resilience4j)
  • Discovery Server (Eureka Service Registry)
  • User Service (Postgres + JPA)
  • Driver Service (Postgres + JPA)
  • Ride Service (Postgres + Kafka producer/consumer)
  • Matching Service (Kafka consumer/producer for driver assignment)
  • Payment Service (Postgres + Kafka consumer/producer)
  • Tracking Service (Redis for live driver tracking)
  • Notification Service (Kafka consumer, logs notifications)

Event Pipeline (Kafka)

  1. Ride requested → published by ride-service
  2. Consumed by matching-service → driver assigned
  3. Driver assignment consumed by ride-service → ride started
  4. Ride completed → published by ride-service
  5. Consumed by payment-service → payment created
  6. Consumed by notification-service → notification sent

🏗️ Component Diagram

Component Diagram


🚀 Features

✅ Microservices with service discovery & load balancing
✅ Secure Gateway with JWT Authentication
Kafka event-driven communication between services
Distributed tracing with Zipkin (traceId across HTTP + Kafka)
Metrics & monitoring with Prometheus + Grafana
Resilience4j Circuit Breakers & fallback in API Gateway
Redis caching for driver tracking
✅ PostgreSQL persistence with JPA + Flyway migrations
✅ Centralized logging & observability


🛠️ Tech Stack

  • Spring Boot 3, Spring Cloud
  • Postgres, Redis
  • Apache Kafka
  • Zipkin, Micrometer, Prometheus, Grafana
  • Resilience4j
  • Docker (optional, can run locally)
  • JUnit/Testcontainers for integration tests

🏗️ Deployment and ports

Deployment Diagram


🏗️ Sequence Diagram — Ride lifecycle

Sequence Diagram


⚡ Run Locally

1. Start Infrastructure

Make sure you have:

  • Postgres running on:
    • user-service → 5432
    • driver-service → 5433
    • ride-service → 5434
    • payment-service → 5435
  • Redis on localhost:6379
  • Kafka broker on localhost:29092
  • Zipkin on http://localhost:9411
  • Prometheus on http://localhost:9090
  • Grafana on http://localhost:3000

These can be started with docker-compose -f infra/docker-compose.yml up.


2. Run All Services

One command 🚀:

./run-all.sh

---

3. 🧪 Testing the Workflow

Create User

curl -X POST http://localhost:8080/api/users \
     -H "Content-Type: application/json" \
     -d '{"name":"Alice","email":"alice@mail.com"}'

Request Ride

curl -X POST http://localhost:8080/api/rides \
     -H "Authorization: Bearer <JWT>" \
     -H "Content-Type: application/json" \
     -d '{"userId":1,"startLocation":"A","endLocation":"B"}'

Kafka Event Flow

ride-service → matching-service → ride-service → payment-service → notification-service

Complete Ride

curl -X PATCH http://localhost:8080/api/rides/{id}/complete \
     -H "Authorization: Bearer <JWT>"

🛠️ Troubleshooting

  • Kafka UnknownHost → use localhost:29092 (host) vs kafka:9092 (Docker)
  • JWT Weak Key → use Keys.secretKeyFor(SignatureAlgorithm.HS256)
  • DB Connection Refused → check Postgres container ports + spring.datasource.url
  • Prometheus scrape errors → verify /actuator/prometheus endpoint

📸 Screenshots

🟦 Eureka — Service Registry

Shows all services (user, driver, ride, payment, matching, tracking, notification) registered with discovery.

Eureka

📊 Grafana — Observability Dashboard

Custom dashboards for API latency, Kafka throughput, and JVM metrics.

Grafana

📈 Prometheus — Metrics Source

Scraping from all microservices via /actuator/prometheus.

Prometheus

🔎 Zipkin — Distributed Tracing

End-to-end trace of a ride request across Gateway → Ride → Matching → Payment → Notification.

Zipkin

About

Mini Uber Backend – Event-Driven Microservices Architecture

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors