Exercise - Microservices - Spring Boot Monolithic Application: E-commerce Platform #155
Replies: 32 comments 3 replies
|
Arup Mukherjee(tcs id :1524555) |
|
Hi @akash-coded |
Part-2:Here's a comprehensive exercise designed to help first-time learners understand the need and use of microservices, using Spring Boot in an E-commerce context, and aligned with the 8 principles of microservice design: Spring Boot Microservice Exercise: E-commerce PlatformObjective: Build a basic E-commerce platform using Spring Boot which implements the 8 principles of microservice design. 1. Single Responsibility PrincipleTask: Create an
2. Loose CouplingTask: Create separate services for
Ensure that when an order is placed in 3. Services as ComponentsTask: Each of these services (Order, Product Management, and User Management) should be independently deployable. Create separate projects for each service. 4. Hide Internal DetailsTask: The 5. Decentralized GovernanceTask: Each service should have its own database. Ensure that the 6. Automation of InfrastructureTask: Use Spring Cloud tools to automate the service discovery and configuration. Implement 7. Failure IsolationTask: Use 8. Continuous Delivery through CI/CDTask: Setup a basic CI/CD pipeline using a tool like Jenkins or TravisCI. Any changes made to a service should trigger a build and deploy the respective service. Technical Requirements:
Stretch Goals:
Upon completion of this exercise, learners should understand the need for microservices in handling complex, scalable systems. They'll also have hands-on experience with the principles of microservice design, including decentralization, continuous delivery, and failure isolation. |
|
Building on the monolithic e-commerce application we discussed earlier, let's outline a microservice approach. Microservices Architecture for E-commerce1. Breaking Down into Microservices
2. Service Interactions
3. Implementation & Configuration1. User Service
2. Product Service
3. Order Service
4. Authentication Service
4. Gateway Service
5. Service Discovery
6. Database per ServiceEach microservice will have its own dedicated database:
This ensures that the services are loosely coupled and can evolve independently. 7. Data ConsistencyIn a microservices architecture, maintaining data consistency across services is challenging. Consider:
8. Deployment & ScalabilityEach service can be containerized using Docker, orchestrated, and scaled independently using Kubernetes. Example Flow:
Benefits of Microservices over Monolithic
Challenges
By the end of this microservices project, you should appreciate the granularity, scalability, and independence microservices offer compared to monolithic applications. However, you should also recognize the complexities associated with managing such distributed systems. |
|
Hi @akash-coded |
|
[ Ratan Singh Dewada |
|
Hi @akash-coded |
|
E-commerce |
|
Hi Akash, Sharing my code in zip file for Microservices - Spring Boot Monolithic Application: E-commerce Platform |
|
Hi @akash-coded ,PFA for Monolithic Application for E-Commerce |
|
Hi @akash-coded |
|
Hi @akash-coded E-Commerce Application |
|
Hi Akash, Sharing my code in zip file for Microservices: E-commerce Platform |
|
Hi @akash-coded sharing my code in zip folder |
|
Hi @akash-coded Please find the github url |
|
Microservice-ecommerce app.zip Prasad (1844193 ) |
|
pfa for the session 3 assignment |
|
Mohammad Arfaz(2354634)--- Below ecommerce microservices |
|
hi akash,PFA |
|
Hi @akash-coded |
|
Hi @akash-coded |
|
Hi @akash-coded |
|
Hi @akash-coded , Name : Kiran Ramesh(1949256) |
|
Hi @akash-coded , |
Uh oh!
There was an error while loading. Please reload this page.
We can begin with a monolithic application that brings out the challenges which microservices aim to solve. This will set the stage for your Part 2, where microservices can address those problems.
Spring Boot Monolithic Application Exercise: E-commerce Platform
Objective: Build a basic E-commerce platform using Spring Boot as a monolithic application. As the platform grows, learners will realize the complexities and potential issues that arise, making the need for microservices evident.
Features:
User Management:
Product Management:
Order Management:
Technical Requirements:
Exercise Steps:
Setup: Initialize a new Spring Boot project using Spring Initializer. Add Web, JPA, the chosen database, and Spring Security as dependencies.
Database Setup: Design a relational database schema that supports all the features. This might involve tables for Users, Products, and Orders, with relationships between them.
API Creation: Start by creating endpoints for each feature listed above. Use Controllers, Services, and Repositories in a layered architecture.
Security: Implement basic authentication using Spring Security. Users should be able to register and log in.
Testing: Create basic unit and integration tests for your endpoints using
JUnitandSpring Boot Test.Challenges to Highlight:
Scalability Issues: As the application grows, deploying even minor changes can require the entire application to be redeployed. This can be a problem in real-world scenarios where uptime is crucial.
Tight Coupling: All the modules are closely interlinked. Any change in one module can have unintended side effects in another module.
Database Monolith: As all modules use a single database, any change in the database schema for one module can affect others.
Lack of Flexibility: Different modules might have different scaling or technological needs. In a monolithic application, it's challenging to scale or update one module independently.
Development Speed: As the application grows, the development process can slow down due to the complexities of the monolithic structure.
Failure Propagation: If one feature/module fails, it can bring down the entire application.
After completing this exercise, reflect on the above challenges and introspect on questions like:
Product Managementmodule independently?Order Managementmodule, how would you deploy a fix without affecting the other modules?By understanding these challenges, you will be well-prepared to see the benefits of microservices in Part 2.
Detailed Implementation Guide: E-commerce Monolithic Application
1. Setting up the Monolithic Application:
1.1. Initial Setup:
Spring Web,Spring Data JPA,Spring Security, and your choice of database (H2orMySQL).1.2. Database Schema:
User,Product, andOrder.Orderentity should have a many-to-one relationship with bothUserandProduct.2. Building the Application:
2.1. User Management:
Endpoints:
/users- Register a new user./users/{userId}- Update user details./users/{userId}- Delete a user./users/{userId}- View user details.Link to Microservices:
In microservices, each service typically has a single responsibility. This entire User Management could be a separate service in a microservices architecture.
2.2. Product Management:
Endpoints:
/products- Add a new product./products/{productId}- Update product details./products/{productId}- Delete a product./products- View product listings.Link to Microservices:
The Product Management can be modularized as its own service, independently scalable based on load.
2.3. Order Management:
Endpoints:
/orders- Place a new order./orders/{orderId}- Update order status./orders/{orderId}- View order details./users/{userId}/orders- List orders for a user.Link to Microservices:
Order Management is another candidate for a separate service in a microservices setup. It depends on both User Management and Product Management, demonstrating service-to-service communication in microservices.
2.4. Security:
Spring Security.bcryptor a similar hashing method.Link to Microservices:
Security would be implemented at the API Gateway level in microservices, ensuring centralized and consistent security policies.
3. Challenges with the Monolithic Approach:
3.1. Scalability:
If the product listing receives a massive amount of traffic, the entire application must be scaled, even if the other parts don't face heavy loads.
3.2. Deployment Complexity:
Any small change requires the entire application to be redeployed.
3.3. Tight Coupling:
Making changes in one section can lead to unintended consequences in another due to interdependencies.
3.4. Single Point of Failure:
If one module fails, the entire application can become inaccessible.
Reflecting on the Microservices Principles:
By the end of this monolithic application project, you should understand the challenges of the monolithic architecture and be ready to explore the advantages of microservices in the subsequent exercise.
Code Snippets and Configurations: E-commerce Monolithic Application
Let's dive deeper into the monolithic application creation with code snippets, configurations, and thought processes.
1. Setup & Configuration
1.1. Initial Setup
Use Spring Initializer or start manually:
1.2. Database Configuration
In
application.properties:2. Entities Creation
2.1. User Entity
2.2. Product Entity
2.3. Order Entity
3. Repositories
For each entity, create a respective repository:
4. Services
For each entity, create a service. For instance, for
User:5. Controllers
Controllers are the REST endpoints. E.g., for
User:6. Security
For security, we can implement a simple authentication. Extend Spring's
WebSecurityConfigurerAdapter:Note: For brevity, user registration & password encryption are not included but should be.
Thought Process & Future Microservices Refactoring:
Single Database Challenge: The monolithic app uses a single database, which becomes a bottleneck as traffic grows. In a microservice architecture, each service would ideally have its own database.
Scalability: As traffic grows, you'd have to scale the entire application rather than individual components. With microservices, you could scale only the frequently accessed services, like Product Listing.
Complexity: As more features are added, the application becomes more complex and harder to maintain. In microservices, each service is isolated, making it easier to understand and maintain.
Decoupling: The tight coupling between different functionalities (like User, Product, and Orders) can be seen. In microservices, these would be completely separated, only communicating through API calls, hence reducing the chances of unintended side-effects.
All reactions