navigation

Building an Event-Driven Architecture with Amazon SNS and SQS

In modern software systems, the transition to Event-Driven Architectures (EDA) has become increasingly prevalent. In this paradigm, services automatically react to events emitted by event publishers. This completely decouples system components, allowing engineering teams to scale, upgrade, and deploy new capabilities independently without risking bottlenecks or cascading system failures.

This workshop will guide you through building and mastering a complete serverless coffee shop ordering system named “The Cozy Brew” on AWS, combining Amazon SNS, Amazon SQS, AWS Lambda, and Amazon S3.

Core system flow: Customers place beverage orders via a static web interface hosted on Amazon S3, the request is received by an AWS Lambda Function URL, which publishes an order event to an Amazon SNS Topic, and automatically fans out in parallel to customer email notifications and specialized Amazon SQS queues (BaristaQueue, VIPExpressQueue, and BaristaDLQ).

Please follow each chapter sequentially in the navigation sidebar, and always observe and verify your results directly on the AWS Management Console before proceeding to the next step.

The Cozy Brew Architecture


Core Concepts in this Workshop

1. Decoupling Producers & Consumers: The storefront web app does not call the coffee preparation queue directly. Instead, it sends requests to an AWS Lambda Function URL, which publishes an order event to an Amazon SNS Topic (CoffeeOrders).

2. Fan-Out Pattern: A single order event published to SNS is immediately duplicated and distributed in parallel to multiple destinations:

  • Customer Email Notification: Sends an immediate order confirmation receipt to the user’s inbox.
  • Barista Preparation Queue (BaristaQueue): An Amazon SQS queue receiving all beverage orders for baristas to prepare sequentially.

3. Infrastructure-Level Message Filtering: Instead of requiring downstream applications to fetch all messages and manually discard unnecessary orders, Amazon SNS Subscription Filter Policies automatically evaluate message attributes and route intelligently:

  • High-volume orders (quantity >= 5) are automatically filtered and routed to a dedicated VIPExpressQueue for expedited handling.

4. Fault Tolerance with Dead-Letter Queues (DLQ): When a malformed order message causes continuous processing crashes (a “Poison Pill” message), the Dead-Letter Queue (BaristaDLQ) automatically isolates the failed message after 3 failed retries (maxReceiveCount = 3). As a result, the system avoids bottlenecks and does not need to pause or reprocess all normal in-flight messages.