This is a Ride Sharing System designed using microservices architecture. The project demonstrates the implementation of CQRS (Command Query Responsibility Segregation), Event-Driven Architecture, and Kafka-based communication between services.
The project consists of the following key modules:
-
Rider Service
- Handles rider-related operations such as submitting ride requests.
- Publishes
RideRequestevents.
-
Ride Command Service
- Listens to
RideRequestevents and processes the ride request commands. - Updates PostgreSQL with ride details.
- Listens to
-
Ride Query Service
- Listens to
RideRequest,RideAssignment, andRideCompletionevents. - Updates MongoDB with a read-optimized view of ride data.
- Listens to
-
Driver Service
- Handles driver-related operations such as accepting ride assignments and completing rides.
- Listens for
RideAssignmentevents and publishesRideCompletionevents.
-
Kafka
- Acts as the messaging system for event communication between services using Kafka topics.
-
CQRS is implemented to separate write operations (commands) from read operations (queries), ensuring that the services handling reads and writes are isolated for better scalability, performance, and flexibility.
- Command Side: The services that handle updates to the data (
Ride Assignment Service,Driver Service,Ride Completion Service). - Query Side: The service that handles reads of the data (
Ride Query Service).
- Command Side: The services that handle updates to the data (
-
Kafka is used to send events between microservices:
- Ride Assignment Service produces ride assignment events that are consumed by the Driver Service.
- Driver Service produces events when a ride is completed, consumed by the Ride Completion Service.
- These events are used to update the Ride Query Service, ensuring eventual consistency between services.
-
Rider Service
- Accepts ride requests.
- Publishes
RideRequestevent to Kafka.
-
Ride Command Service
- Listens to
RideRequestevent. - Updates PostgreSQL with ride details.
- Listens to
-
Ride Query Service
- Listens to
RideRequest,RideAssignment, andRideCompletionevents. - Updates MongoDB with the latest ride data (using CQRS principles).
- Listens to
-
Driver Service
- Listens for
RideAssignmentevent. - Publishes
RideCompletionevent once the ride is completed.
- Listens for
Clone the repository from GitHub and navigate to the project directory.
git clone https://github.com/burakmert/ride-sharing-simulator.git
cd ride-sharing-simulatorEnsure you have Maven or Gradle installed to build the project. You can build the project with the following command:
mvn clean installYou can use Docker Compose to bring up the necessary services (Kafka, MongoDB, etc.) for local development. Ensure that your docker-compose.yml is correctly set up for Kafka and MongoDB.
docker-compose up -dOnce the Docker containers are set up, run each microservice using Spring Boot’s embedded server. Navigate to each service’s folder and run:
mvn spring-boot:runAlternatively, you can run the entire application using Docker if the services are Dockerized.
Once all services are running, you can interact with the API endpoints:
- Rider Service:
http://localhost:8092/ - Ride Command Service:
http://localhost:8102/ - Ride Query Service:
http://localhost:8112/ - Driver Service:
http://localhost:8122/
- Spring Boot: For building the microservices.
- Spring Kafka: For handling event-driven communication between microservices.
- Apache Kafka: For message brokering.
- CQRS: For separating command and query responsibilities for better scalability and performance.
- Docker: For containerizing the services.
- MongoDB: For storing and querying ride data in the
RideViewcollection. - PostgreSQL: For storing ride data in the command side of the system.
- Rider Service sends a
RideRequestevent. - Ride Command Service listens to the
RideRequestevent, processes it, and updates PostgreSQL. - Ride Query Service listens for
RideRequest,RideAssignment, andRideCompletionevents and updates MongoDB RideView. - Driver Service listens for
RideAssignmentevents and publishesRideCompletionevents after the ride is completed. - The
RideCompletionevent updates PostgreSQL and MongoDB as needed.