Event-Driven Architecture in Microservices: Use Case for Online Shopping System

Event-Driven Architecture in Microservices: Use Case for Online Shopping System

In the world of microservices, events are the silent orchestrators, conducting a symphony of independent processes.

Introduction:

Microservices architecture has gained immense popularity for its ability to create scalable and independent components within a software system. One crucial aspect of this architecture is the implementation of event-driven patterns, which enhances decoupling and scalability.?

Let's explore a real-world scenario of a retail product (Book in our case) order entry system to illustrate the use case of event-driven architecture in microservices.


Illustration of events in ordering a book from online shopping portal

The system services are spread across according to their functionality. Some of the common events triggered right from the beginning are as follows along with the operations that happened within them:

1. PlaceOrder Event:

  • Initiating the event triggers the OrderPlacement event processor.
  • Inserts the order into a database and returns an order ID to the customer.
  • Advertises the creation of the order through an order-created processing event.

Parallel Event Processing:

2. Notification Event Processor:

???- Listens for the order-created event.

???- Sends an email to the customer.

???- Generates an email-sent processing event.

3. Inventory Event Processor:

  • ??Listens for the order-created event.
  • ??Decrements inventory for the ordered book.
  • ???Advertise the action through an inventory-updated processing event.

4. Payment Event Processor:

  • Listens for the order-created event.
  • Charges the customer’s credit card for the created order.
  • Generates two events:?
  • ?payment-applied to notify successful payment.
  • ?payment-denied to notify a denied payment.

Handling Payment Denial:

5. Notification Event Processor (Payment-Denied):

  • Listens for the payment-denied processing event.
  • Sends an email to the customer, prompting them to update their credit card information or choose another payment method.

Order Fulfillment:

6. OrderFulfillment Event Processor:

  • Listens for the payment-applied processing event.
  • Performs order picking and packing.
  • Advertises fulfilment through an order-fulfilled processing event.

Concurrent Processing:

7. Notification Event Processor (Order-Fulfilled):

???- Notifies the customer that the order is fulfilled and ready for shipment.

8. Shipping Event Processor:

  • Listens for the order-fulfilled processing event.
  • Select a shipping method.
  • Ships the order and sends an order-shipped processing event.

9. Notification Event Processor (Order-Shipped):

  • Listens for the order-shipped processing event.
  • Notifies the customer of the order status change.

Decoupled and Independent:

All event processors operate independently and are highly decoupled.

Analogy: Think of it as a relay race where each event processor handles a specific task and passes the "baton" (event) to the next processor.

Scalability and Back Pressure:

Each event processor can scale independently to handle varying load conditions. Topics provide a back pressure point if an event processor faces issues.

Challenges:

  • Lack of control over the overall workflow associated with the initiating event.
  • Error handling challenges due to the absence of a mediator monitoring business transactions.
  • Potential business process interruptions in case of failures, emphasizing the need for automated or manual interventions.

Conclusion:

The event-driven architecture in microservices facilitates a flexible and scalable system but comes with its challenges. Understanding these dynamics is crucial for software engineers to design resilient and efficient microservices systems.

Reference:

This article draws insights and inspiration from the book "Fundamentals of Software Architecture: An Engineering Approach." Authored by Neal Ford and Mark Richards, this book serves as a comprehensive guide for software architects, engineers, and developers seeking a deep understanding of the principles and practices governing software architecture.


If you’re looking for someone to talk to about software development, agile methodologies, or the cloud or software industry in general then feel free to revert me back.

Also if you have any suggestions regarding my blog, drop a comment so I can do better next time.

till then...

Happy Reading..! ??

Thank you.


Brilliant insight! As Steve Jobs once said, ""Innovation distinguishes between a leader and a follower."" And indeed, applying decoupling in microservices is a strong step towards innovative systems architecture. ?????? #ManyMangoes #StayInnovative #JobsWisdom Follow us!

回复

要查看或添加评论,请登录

Aniket Kulkarni的更多文章

社区洞察

其他会员也浏览了