thelovemsg / ticketing_site

ticketing_site
0 stars 0 forks source link

Query 1) How to extract proper microservice? #3

Open thelovemsg opened 1 week ago

thelovemsg commented 1 week ago

How to extract proper mircoservice?

1. Identify Business Capability

Start by identifying key business capabilities. These are distinct functions that the business performs to deliver its products or services


2. Define Bounded Contexts

It defines the boundaries within a particular domain model is defined and applicable. Each bounded context correlates closely with a business cabaility and often maps directly to a microservcice.


3. Model Around Business Domain

identify subdomains that could potentially become microservices. These subdomains should represent parts of the domain that can function relatively independently and have their data storage.


4. decompose by subdomains

Within each bounded context, identify subdomains that could potentially become microservices. These subdomains should represent parts of the domain that can function relatively independently and have their data storage.


5. Analyze data flow and dependencies

Understand how data flows between different parts of the application and the dependencies involded. Services should be designed to minimize dependencies. Often, synchronous calls can be replaces with asynchronous messaging to reduce direct dependencies between services. (please look at the another added comment below this comment)

6. Define service APIs

Once you have identified potential services, define the APIs for these services. APIs act as contracts between microservices and should be stable and well-documented. They should allow services to communicate without sharing their internal implementations.


7. Isolate the service

Start isolating the service by defining its own separate data storage and independent deployment pipeline. This isolation helps in scaling, maintaining, and evolving each microservice independently.


8. Consider Fault Tolerance and Scaling

Evaluate how the system will handle failures. Microservices should be designed to be resilient, with strategies like retries, fallbacks, and circuit breakers. Also consider how each microservices will scale. Not all parts of an application will face the same load, so design your services to scale independently based on their specific needs.


9. Continuous Intregration and Deployment

Each microservice should have its CI/CD pipeline allowing for independent testing, building, and deployment. This setup enhances the agility and speed of developemtn.


10. Monitor and Refine

After deployment, continuously monitor the services and their interactions. Use metrics and logs to understand their behavior in production and refine them as necessary. This continuous feedback loop is crucial for maintaining and improving microservices.


Final Thoughts

Microservices architecture is not a silver bullet and comes with its own set of challenges, such as increased complexity in managing multiple services and data consistency issues. It’s essential to evaluate if microservices are suitable for your specific context and if the benefits outweigh the challenges.

good to read : https://martinfowler.com/microservices/

thelovemsg commented 5 days ago

E-Commerce Order Processing: Synchronous vs. Asynchronous Approaches

Overview

This repository explores different architectural approaches to handling e-commerce order processing using microservices. We compare the traditional synchronous approach with a more modern asynchronous messaging approach to highlight the benefits and potential drawbacks of each.

Example Scenario

In an e-commerce platform, the process of placing an order involves several steps and interactions between different microservices, such as the Order Service, Inventory Service, Payment Service, and Notification Service.

Synchronous Approach

Workflow:

  1. User places an order: The front-end sends a request to the Order Service.
  2. Check inventory: The Order Service makes a synchronous call to the Inventory Service to reserve the items.
  3. Process payment: If the items are reserved successfully, the Order Service makes another synchronous call to the Payment Service.
  4. Send confirmation: Upon successful payment, the Order Service sends a confirmation response back to the user and makes yet another synchronous call to the Notification Service to send an order confirmation email.

Problems:

Asynchronous Approach Using Messaging

Workflow:

  1. User places an order: The front-end sends a request to the Order Service.
  2. Post to message queue: The Order Service posts a message to a queue (OrderCreated) and immediately returns a response to the user indicating that the order is being processed.
  3. Inventory Service listens on the queue: When the Inventory Service receives the OrderCreated message, it attempts to reserve the inventory and, if successful, posts an InventoryReserved message to another queue.
  4. Payment Service listens on the queue: On receiving the InventoryReserved message, the Payment Service processes the payment and posts a PaymentProcessed message.
  5. Notification Service listens for the payment message: Once the PaymentProcessed message is received, the Notification Service sends out the order confirmation email.

Benefits:

Implementation Technologies

Conclusion

By implementing asynchronous messaging, the e-commerce system becomes more robust, flexible, and scalable. Each service in this architecture works independently, enhancing the system's ability to handle failures and fluctuations in load.