Architecture & Event Flow

In an Event-Driven Architecture (EDA), services are decoupled and communicate asynchronously via events. This section presents the end-to-end architecture topology and the detailed event processing flow for “The Cozy Brew” coffeehouse system.


Architecture Diagram

The Cozy Brew Architecture


Detailed Event Flow Breakdown

  • Order Placement (Client Layer): The customer selects their beverage, customizes cup size (S / M / L), sets quantity, and provides brewing notes directly on the static web application hosted on Amazon S3.

  • Serverless Ingestion (Compute Layer): The web application performs an asynchronous HTTP POST request to the AWS Lambda Function URL. The Lambda function (order-publisher):

    • Validates incoming input data.
    • Generates a unique, searchable Order ID (e.g., COZY-A1B2C3).
    • Attaches structured metadata fields (Message Attributes: drink, size, quantity, is_vip).
  • Event Publishing (Messaging Layer): Lambda calls the sns:Publish API to broadcast the order event to the central CoffeeOrders topic in Amazon SNS without waiting for downstream fulfillment to finish.

  • Fan-Out & Automated Routing (Consumer Layer):

    • Email Notification: Amazon SNS automatically formats and dispatches an immediate order confirmation receipt to the customer’s registered email inbox.
    • Standard Barista Queue (BaristaQueue): Receives all orders via an unfiltered subscription, enabling cafe baristas to pick up and brew drinks concurrently.
    • VIP Express Routing (VIPExpressQueue): Amazon SNS evaluates subscription filter policies. If quantity >= 5, the message is automatically duplicated and routed to the prioritized VIPExpressQueue.
    • Queue Protection with Dead-Letter Queue (BaristaDLQ): If an order encounters malformed syntax or causes consumer crashes more than 3 times, Amazon SQS isolates the poison message into the Dead-Letter Queue (BaristaDLQ), keeping the primary queue unblocked.