Startup Ground to Cloud: Launching Fanout Pattern to AWS Cloud

Nic Lasdoce
14 Feb 20245 minutes read

Let's lift the Fanout Pattern into the AWS Cloud! Dive into our exploration of a simple e-commerce payment completion transaction to understand how the fanout pattern operates and discover which AWS cloud services enhance this design pattern.

Introduction

The fanout pattern is a fundamental architectural design pattern utilized in distributed systems to enable efficient message distribution to multiple processes or services simultaneously. This pattern plays a pivotal role in scenarios where an action or event triggers a cascade of reactions from various parts of a system. Below, we delve into the fanout pattern's core concepts, benefits, and practical considerations, followed by an illustrative example using an e-commerce payment service.

Core Concepts

The essence of the fanout pattern lies in its ability to broadcast a single message or event to multiple recipients without the sender having to be aware of the individual consumers. This mechanism is achieved through a publish-subscribe model, where:

Publisher: The entity that generates and sends the message or event.

Message Broker or Exchange: An intermediary that receives messages from the publisher and distributes them to all subscribed consumers.

Subscribers: The services or processes that listen for and act upon the messages broadcasted by the publisher.

Illustrative Example: E-Commerce Payment Service

To contextualize the fanout pattern, consider its application in an e-commerce platform during the checkout process:

Process Flow

  1. Event Publication: Once the payment is successfully processed, the payment processing system (publisher) emits a "Payment Successful" event.

  2. Fanout Mechanism: A message broker receives this event and, using the fanout pattern, distributes it to all subscribed services without requiring knowledge of these subscribers' details.

  3. Event Processing: All services that are subscribed to this specific event will be notified so they can process the event. In this example, these two services will handle receive and process the event simultaneously:

    • Shipping Service will initiate the shipping process for the relevant items to the customer's address.
    • Inventory Service will update the inventory levels to account for the sold items.

Solving Scalability Issue

The initial setup works well, but as the e-commerce site gains popularity, the Inventory and Shipping Services could become overwhelmed, failing to process all events and resulting in significant customer complaints. To prevent such outcomes, we introduce an intermediary service between the event processing and the message broker, known as the Queue Service.

The Queue Service now becomes the new subscriber to the message broker, while the Shipping and Inventory Services no longer subscribe directly to the message broker. Instead, they monitor the queue for any events. With this arrangement, regardless of the volume of payment events incoming, we ensure that they are all queued, waiting for the Event Processors (Inventory and Shipping Services) to retrieve them and update the queue once they have been successfully processed.

Ground to Cloud

Now it's time to make this system available for actual usage by deploying it to the cloud. To accomplish this, we will utilize AWS Services to implement this architectural pattern.

  • Publisher: The Purchase service continues as the publisher of the payment completion event. The cloud implementation heavily depends on the backend framework used, but common deployments include Kubernetes, ECS Fargate (for a simple and serverless implementation of Kubernetes), EC2, and Lambda.
  • Message Broker: AWS SNS will serve as the message broker. We prefer to go serverless to minimize maintenance (instead of using RabbitMQ or Kafka, which of course have their own applications, but we favor simplicity in this article for easier understanding). Specifically, we will create an SNS Topic for the Payment Complete Event.
  • Queue (As Subscribers): Here, we will use AWS SQS, another serverless system, to manage the queuing. To further enhance the system, we could add a dead-letter queue for handling failed event processing, but that is a topic for another time.
  • Event Processor:: The inventory and shipping services remain as the event processors. For cloud deployment, the suggestions for the Publisher apply here as well.

Benefits of the Fanout Pattern

  • Decoupling of Components: Producers and consumers operate independently, enhancing system modularity and flexibility.
  • Scalability: Systems can scale more easily, as adding more consumers does not impact the publisher or existing consumers.
  • Fault Tolerance: The failure of one consumer does not affect the publisher or other consumers, improving the overall resilience of the system.
  • Efficiency: Enables simultaneous processing of messages, reducing latency and improving response times for distributed tasks.

Practical Considerations

  • Idempotency: It's crucial to design consumer services to handle the same message multiple times without adverse effects, preventing issues related to message redelivery or duplication.
  • Error Handling: Implementing comprehensive error handling and retry mechanisms in consumer services ensures system robustness and reliability.
  • Monitoring and Logging: Vital for tracking the system's health, identifying bottlenecks, and debugging issues across distributed components.

Conclusion

In conclusion, transitioning an e-commerce system's architecture to leverage the fanout pattern, especially when scaling to the cloud, offers significant benefits in terms of scalability, reliability, and efficiency. By utilizing AWS Services such as SNS for message brokering and SQS for queue management, we can create a resilient architecture that ensures smooth communication between microservices, even under high load. This setup not only manages the increased traffic as the e-commerce platform grows but also maintains high customer satisfaction by reliably processing payments, updating inventory, and managing shipments.

The adoption of serverless components like AWS SNS and SQS further simplifies operations, reducing the need for maintenance and allowing developers to focus on improving the application rather than managing infrastructure. The flexibility of cloud services, including the choice between containers and serverless functions for deploying microservices, provides a robust foundation for building scalable and fault-tolerant systems.

Bonus

If you are a founder needing help in your Software Architecture or Cloud Infrastructure, we do free assessment and we will tell you if we can do it or not! Feel free to contact us at any of the following:
Social
Contact

Email: nic@triglon.tech

Drop a Message

Tags:
Software Development
TechStack
AWS
NodeJS

Nic Lasdoce

Software Architect

Unmasking Challenges, Architecting Solutions, Deploying Results

Member since Mar 15, 2021

Tech Hub

Unleash Your Tech Potential: Explore Our Cutting-Edge Guides!

Stay ahead of the curve with our cutting-edge tech guides, providing expert insights and knowledge to empower your tech journey.

View All
Struggling with Database Performance? Discover These 5 Aurora Patterns for Better Operations
30 Jun 20242 minutes read
Monolith: From Zero to Millions
14 May 20244 minutes read
View All

Get The Right Job For You

Subscribe to get updated on latest and relevant career opportunities