Capstone Project - Spring Microservices - Reservation System #149
Replies: 23 comments 1 reply
Hotel Reservation System: Detailed Implementation GuideProject Modules and WorkflowsLet's drill down into each module and understand its purpose, interactions, and workflows that they will implement. Customer Service
Reservation Service
Payment Service
Hotel Management Service
Notification Service
Business Workflows in Detail1. Customer Registration (Customer Service)
2. Make a Reservation (Reservation Service, Payment Service, Hotel Management Service)
Step-by-Step Implementation GuidelinesStep 1: Set Up Development Environment
Step 2: Create Spring Boot Projects
Step 3: Implement Business Logic
Step 4: Implement Microservice Patterns
Step 5-13: Dockerization, Kubernetes, and DevOps
By following this detailed guide, the development team will have a robust and comprehensive set of instructions to build a fully functional, production-grade hotel reservation system. Even a layman can follow this guide to understand the core functionalities and patterns used in building this system. Security Measures, Observability, and Further Granular DetailsStep 14: Implement Security
Step 15: Observability Measures
Step 16: Testing Strategies
Step 17: CI/CD pipeline
Step 18: Implementing A/B Testing (Optional)
Step 19: Documentation
Business Workflow ExamplesRefund Process Workflow
This is a complex operation that involves multiple services, and each service has its role clearly defined. Implement Saga patterns to maintain data consistency across these operations. Room Inventory Update Workflow
Implement Proxy patterns to abstract the complexities involved in integrating with third-party inventory management systems. By following this guide, you can ensure the architecture's robustness, security, and scalability, while adhering to best industry practices and patterns. |
Implementation Guidelines (Roadmap)Step 1: Setup Development Environment
Step 2: Create Spring Boot Projects
Step 3: Implement Business Logic for Each Service
Step 4: Containerize Your Services
Step 5: Create Kubernetes Configuration
Step 6: Implement API Gateway
Step 7: Implement Service Discovery
Step 8: Implement Circuit Breaker
Step 9: Implement Database Per Service Pattern
Step 10: Implement Asynchronous Communication
Step 11: Implement Testing
Step 12: Implement DevOps
Step 13: Implement Observability
This is a roadmap you can follow to build your hotel reservation system using Spring Boot microservices. Start small, validate your steps as you go, and gradually add complexity as you become comfortable with each technology. |
Detailed Implementation DetailsHere's a more detailed example that includes Maven dependencies, entities, Liquibase migrations and seeders, and controller endpoints for the Customer and Reservation services. Customer ServiceMaven Dependencies (pom.xml)<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
</dependencies>Entity (Model)@Entity
@Table(name = "customers")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name", nullable = false)
private String name;
@Column(name = "email", unique = true, nullable = false)
private String email;
@Column(name = "password", nullable = false)
private String password;
// Getters and setters...
}Liquibase Migrations and Seeders
databaseChangeLog:
- changeSet:
id: create-customers-table
author: yourName
changes:
- createTable:
tableName: customers
columns:
- column:
name: id
type: bigint
autoIncrement: true
constraints:
primaryKey: true
nullable: false
- column:
name: name
type: varchar(255)
constraints:
nullable: false
- column:
name: email
type: varchar(255)
constraints:
nullable: false
unique: true
- column:
name: password
type: varchar(255)
constraints:
nullable: false
databaseChangeLog:
- changeSet:
id: seed-customers-table
author: yourName
changes:
- insert:
tableName: customers
columns:
- column:
name: name
value: "John Doe"
- column:
name: email
value: "john.doe@example.com"
- column:
name: password
value: "hashedpassword"Controller Endpoints@RestController
@RequestMapping("/api/v1/customers")
public class CustomerController {
@PostMapping("/register")
public ResponseEntity<?> registerCustomer() {
// logic
}
@GetMapping("/{id}")
public ResponseEntity<?> getCustomerById(@PathVariable Long id) {
// logic
}
}Reservation ServiceMaven Dependencies (pom.xml)Same as the Customer Service, but add Eureka Client and Hystrix dependencies for service discovery and fault tolerance. Entity (Model)@Entity
@Table(name = "reservations")
public class Reservation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "customerId", nullable = false)
private Long customerId;
@Column(name = "hotelId", nullable = false)
private Long hotelId;
@Column(name = "startDate", nullable = false)
private LocalDate startDate;
@Column(name = "endDate", nullable = false)
private LocalDate endDate;
// Getters and setters...
}Liquibase Migrations and SeedersSimilar approach to Customer Service, create Controller Endpoints@RestController
@RequestMapping("/api/v1/reservations")
public class ReservationController {
@PostMapping
public ResponseEntity<?> makeReservation() {
// logic
}
@GetMapping("/{id}")
public ResponseEntity<?> getReservationById(@PathVariable Long id) {
// logic
}
}For each service, you'll also need a Absolutely, let's move on to the Payment, Hotel Management, and Notification services. Payment ServiceMaven Dependencies (pom.xml)<!-- Same as previous services, plus any payment gateway dependencies you might need -->Entity (Model)@Entity
@Table(name = "payments")
public class Payment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "customerId", nullable = false)
private Long customerId;
@Column(name = "amount", nullable = false)
private BigDecimal amount;
// Additional fields such as payment method, status etc.
// Getters and setters...
}Liquibase Migrations and SeedersFollow the same format as the Customer and Reservation services, just adapt it for the Payment entity. Controller Endpoints@RestController
@RequestMapping("/api/v1/payments")
public class PaymentController {
@PostMapping
public ResponseEntity<?> makePayment() {
// logic
}
@GetMapping("/{id}")
public ResponseEntity<?> getPaymentById(@PathVariable Long id) {
// logic
}
}liquibase.propertiesapplication.propertiesHotel Management ServiceMaven Dependencies, Entity, Migrations, Seeders, and ControllersFollow the same format as the Payment service, but adapt for managing hotels, rooms, etc. liquibase.properties and application.propertiesWould be the same as Payment service, with changes for specific needs. Notification ServiceMaven Dependencies (pom.xml)<!-- Standard Spring Boot Dependencies plus email or SMS service dependencies -->Entity (Model)Since Notification could be event-driven and stateless, you may or may not need an entity model. Controller Endpoints@RestController
@RequestMapping("/api/v1/notifications")
public class NotificationController {
@PostMapping("/send")
public ResponseEntity<?> sendNotification() {
// logic
}
}liquibase.propertiesOnly if you need database interaction. application.propertiesIn all these services, don't forget to configure your service to register with Eureka for service discovery and to implement Circuit Breaker patterns using Hystrix where necessary. Saga pattern could be used in scenarios involving multiple service calls that need to be transactional, like a multi-step reservation process. This should give a more detailed and comprehensive guide to your learners for implementing each microservice thoroughly. |
|
Hi @akash-coded Name: Jay Prakash Kumar I have implemented event-driven messaging architecture with RabbitMQ, With Service Discovery and API gateway. Also the aggregator pattern and saga pattern. https://github.com/jay4tech/discovery-service/tree/final-assignment https://github.com/jay4tech/customer-service/tree/final-assignment |
|
Hi @akash-coded I have implemented the capstone project using Kafka broker for notifications. Have created schema using liquibase that allows to readily test API with seed data once services are up. I have used Eureka Service Discovery and spring cloud api gateway. Utilised Saga Pattern along with email notifications. Also attached sonar qube reports for the project's. Email notifications can be checked at test smtp server. using sender email noreply@amhotels.com |
|
Hi I have completed capstone project. Implemented SAGA pattern, Proxy pattern and API gateway. Used Kafka for event based actions and notification service. Implemented JWT token authentication in API gateway level to authenticate customer requests. Capstone Project - Spring Microservices - Reservation System.zip Thank you. |
|
Name : Arup Mukherjee |
|
Hi Akash, Sharing my code in zip file for Capstone Project - Spring Microservices - Reservation System |
|
hi @akash-coded , Please find below github link for Capstone Project - Spring Microservices - Reservation System |
|
Hi @akash-coded I have added my postman suite in each of the microservices. Also adding a google drive link which has a zip folder having all these microservices at one place and the postman suite used for testing individual microservices as well as end to end flows like customer sign up, reserving a room and cancelling it. https://drive.google.com/file/d/1FrAZDEOFNy0YZS1tIsYwykHgTVEaCuVE/view?usp=drive_web |
|
Hi @akash-coded , |
|
Hi @akash-coded, Emp Id: 2043299 |
|
Hi @akash-coded Emp Id : 389145. Thanks, |
|
Hi @akash-coded , As per the project guidelines below modules are created. Please find below the things exhibited in the project.
Project Source code: The same has also been uploaded to LMS. Please review and let me know for any clarification. |
|
@akash-coded Hi Akash Please find below link to all services for Hotel Reservation System. Workflow and pattern details mentioned in readme. Regards |
|
Hi @akash-coded , Sharing my code in zip file for Capstone Project - Spring Microservices - Reservation System microservice-capstone-reservation-system-HarshPandya-2066481.zip |
|
Hi Akash (@akash-coded ), Please find attached the capstone project for hotel reservation system. All key concepts like rest template, feign client, circuit breaker, event driven, saga pattern, api gateway, proxy authentication filter covered. Zip file contains all the microservices, read me file, postman collection to test. capstone_hotel_reservation_system.zip Name: Arul |
|
Hi Akash - Attached is the final assignment |
|
Hi @akash-coded I've completed this capstone project and the latest code is committed in the same repository mentioned in the LMS. Please review. Thanks! |
|
Hi Akash, Please find the attached Capstone Project for Reservation system. Thanks, |
|
Hi Akash, I have uploaded the capstone project in LMS. Kindly Review and share your feedback. Please let me know if there are any changes/modifications to be made. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Project Title: Hotel Reservation System
Project Documentation Manual
Introduction
The Hotel Reservation System aims to offer a seamless hotel booking experience by leveraging microservices architecture, encapsulating specific functionalities and domains within independent services. This documentation aims to provide a detailed manual for implementing each service, with a focus on advanced developers.
Code Quality Metrics & Standards
Architecture Overview
The system consists of:
Key Microservice Patterns in the Workflows
Saga Pattern: Primarily used in the refund process to ensure that a series of local transactions are all executed or compensated. Each step is an individual local transaction and has a compensating transaction.
Example: If the refund is not processed, the reservation is not cancelled, and the user is notified.
API Gateway Pattern: All client requests go through an API Gateway (Zuul/Spring Cloud Gateway), which routes requests to appropriate services.
Example: A user makes a reservation. The API gateway routes this request to the Reservation Service, which then talks to Payment Service and Hotel Management Service.
Proxy Pattern: When you have to interact with an external service or library, wrap it within a Proxy Service. The Proxy pattern will help you control access, logging, and security features for accessing the third-party or costly resources.
Example: For sending SMS and Email notifications, instead of calling third-party services directly, they could be routed through a Notification Proxy that batches requests or caches repeated requests to the same number/email to reduce costs.
Business Workflows:
User Signup Workflow
Customer Service.Customer Servicevalidates the data and creates a new record in its database.Notification Serviceis invoked to send a welcome email.Room Reservation Workflow
Reservation Service.Reservation Servicefirst checks room availability withHotel Management Service.Reservation Servicereserves the room and sends a payment request toPayment Service.Payment Serviceprocesses the transaction and sends the status back toReservation Service.Reservation Serviceconfirms the reservation, andNotification Servicesends a confirmation message.Room Cancellation and Refund
Reservation Service.Reservation Serviceconfirms the cancellation and initiates a refund viaPayment Service.Payment Serviceprocesses the refund and notifiesReservation Service.Reservation Servicereleases the room back to inventory viaHotel Management Service.Notification Servicesends out cancellation and refund notifications.Implement Saga patterns to maintain data consistency across these operations.
This manual serves as a comprehensive guide to implementing the Hotel Reservation System as a robust, fault-tolerant, and highly scalable system. By adhering to these guidelines and workflows, the development team can facilitate a smooth development, deployment, and maintenance process.
Objective
The objective of this project is to build a hotel reservation system using Spring Boot microservices, following microservices principles, patterns, testing strategies, and DevOps practices.
Project Modules:
Steps for Implementation
Below are the detailed steps for implementing this project:
Step 1: Set Up Development Environment
Step 2: Create Spring Boot Applications
Step 3: Define Business Logic for Each Service
Step 4: Containerize Services
Step 5: Create Kubernetes Configurations
Step 6: Implement API Gateway
Step 7: Implement Service Discovery
Step 8: Implement Circuit Breaker
Step 9: Implement Database Per Service Pattern
Step 10: Implement Asynchronous Communication
Step 11: Implement Testing (Optional)
Step 12: Implement DevOps Practices (Optional)
Step 13: Implement Observability (Optional)
Remember to keep in mind the principles of microservices as you implement this project: model around business domain, culture of automation, hide implementation details, decentralize all things, deploy independently, consumer first, isolate failures, and be highly observable.
Project Implementation: Hotel Reservation System Using Spring Microservices
Introduction
This implementation manual provides detailed guidance on building a Hotel Reservation System utilizing Spring Boot microservices. The system leverages microservices architecture principles, incorporating various design patterns and best practices for robust, scalable, and fault-tolerant applications.
Code Quality Metrics & Standards
Architecture Overview
Customer Service
Functionalities & Purpose:
Key Events and Actions:
UserRegistered: When a new user signs up.SendWelcomeEmailevent.UserUpdated: When user updates profile.Reservation Service
Functionalities & Purpose:
Key Events and Actions:
RoomRequested: When a customer requests a room.RoomReservedevent.ReservationCancelled: When a booking is canceled.Payment Service
Functionalities & Purpose:
Key Events and Actions:
PaymentProcessed: When a payment is successfully processed.RefundInitiated: When a refund process starts.RefundProcessed.Hotel Management Service
Functionalities & Purpose:
Key Events and Actions:
RoomInventoryUpdated: When room availability changes.RoomPricingUpdated: When pricing for rooms is updated.Notification Service
Functionalities & Purpose:
Key Events and Actions:
SendWelcomeEmail: Triggered after a user is registered.ReservationConfirmationSent: When a reservation is confirmed.Implementing Saga Pattern for Compensating Transactions
Scenario 1: Failed Payment During Reservation
Scenario 2: Room Unavailability After Payment
Scenario 3: Customer Cancels Reservation Post Payment
Circuit Breaker Scenarios
Scenario 1: Hotel Management Service Overload
Scenario 2: External Payment Gateway Timeout
Flow of Events for CQRS
Industry Best Practices & Inter-Service Communication Strategies
API Gateway (Zuul/Spring Cloud Gateway):
Proxy Pattern:
Use-Case: Notification Service acting as a proxy for third-party communication services.
Saga Choreography and Compensating Transactions
Scenario 4: Notification Failure Post Reservation
Scenario 5: Concurrent Room Booking
Circuit Breaker Usage Scenarios
Scenario 3: Slow Customer Profile Updates
Scenario 4: Hotel Management Service Database Maintenance
Event Sourcing and Event-Driven Architecture (EDA)
Event Sourcing:
Event-Driven Architecture:
ReservationServicepublishes an event after a room booking whichCustomerServiceandHotelManagementServicelisten to.Synchronous vs. Asynchronous Communication
Synchronous Communication (RestTemplate, Feign):
ReservationServicemight synchronously callPaymentServiceto process payments immediately.Asynchronous Communication (Kafka):
Logging Implementations
Microservices Communication and Event Flow
API Gateway Routing: All user requests are first routed through the API Gateway which then directs them to the respective microservice.
Event-Driven Communication:
Proxy Pattern Usage:
Overall Functionalities and Purpose of the Hotel Reservation System
Design Patterns and Their Combined Usage
Scenarios for Hotel Reservation System Implementation
Scenario 1: Database Connection Failure in Customer Service
Scenario 2: Overloaded Payment Service
Scenario 3: Inconsistent Data Between Services
Scenario 4: Service Timeout During User Signup
Scenario 5: Failure in Saga during Room Booking
Scenario 6: Invalid Request to Reservation Service
Scenario 7: External Payment Gateway Unavailability
Scenario 8: Notification Service Rate Limiting
Scenario 9: Data Synchronization Issue Post Room Cancellation
Scenario 10: Microservice Deployment Failure
Scenario 11: Security Breach in Customer Service
Scenario 12: Simultaneous Room Booking Conflict
Scenario 13: Microservice Communication Breakdown
Scenario 14: Cascading Failures from a Single Service
Scenario 15: Incomplete Saga due to Service Downtime
Scenario 16: Data Loss in Event Store
Scenario 17: High Latency in Inter-Service Communication
Scenario 18: Misconfiguration in Production Environment
Scenario 19: Payment Service Compliance Violation
Scenario 20: Batch Processing Failure in Hotel Management Service
Development Tips
Conclusion
This detailed manual provides a roadmap for implementing a robust Hotel Reservation System using Spring Boot microservices. By following the outlined architecture, implementing suggested patterns, and adhering to best practices, the development team can build a system that's not only functionally rich but also resilient and scalable.
The implementation of CQRS, sagas, and circuit breakers, combined with an event-driven architecture, ensures that the Hotel Reservation System can handle complex workflows and unexpected failures gracefully, thereby providing a seamless user experience. The project encapsulates a wide range of microservices patterns and principles, offering a comprehensive learning experience in modern software architecture and design.
All reactions