DEV Community

Dipali Kulshrestha
Dipali Kulshrestha

Posted on

Messaging & Event Driven design

Event-driven architecture (EDA) is a modern architecture pattern built from small, decoupled services that publish, consume, or route events.

An event represents a change in state, or an update. For example: an item placed in a shopping cart, a file uploaded to a storage system, or an order becoming ready to ship. Events can either carry the state (such as the item name, price, or quantity in an order) or simply contain identifiers (for example, “order #8942 was shipped”) needed to look up related information.

Unlike traditional request-driven models, EDA promotes loose coupling between producer and consumer services. This makes it easier to scale, update, and independently deploy separate components of a system.

AWS Messaging Services

Amazon SQS (Simple Queue Service)

  • Fully managed message queue
  • Used for decoupling application components

Two types:

  • Standard Queue: At-least-once delivery, best-effort ordering
  • FIFO Queue: Exactly-once processing, strict ordering

Amazon SNS (Simple Notification Service)

  • Pub/Sub messaging service
  • One message → multiple subscribers

Common subscribers:

  • SQS
  • Lambda
  • Email / HTTP endpoints

SNS vs SQS

  • SNS pushes messages
  • SQS polls messages
  • SNS fan-out pattern uses SNS → multiple SQS queues

Amazon EventBridge

Amazon EventBridge is a serverless event bus that facilitates event-driven architectures. It simplifies the process of connecting different services and applications by enabling them to communicate through events. EventBridge routes events from sources such as AWS services, custom applications, and third-party software, delivering them to targets like AWS Lambda, Amazon SNS, Amazon SQS, and more.

EventBridge plays a crucial role in building de-coupled systems, where different components communicate through events. This approach enhances scalability, flexibility, and resilience, as each system component operates independently and reacts to events in real-time.

When to Use What

SQS: Asynchronous processing, buffering

SNS: Fan-out notifications

EventBridge: Event routing across services

LAB 7: Messaging with Amazon SQS

Task: Implement loosely coupled architectures using messaging services

Objective

  • Decouple application components using SQS
  • Process messages asynchronously using Lambda
  • Configure DLQ for failure handling

Architecture

  • Producer (Lambda / CLI)
  • Amazon SQS
  • Consumer (Lambda)
  • Dead Letter Queue

Steps
Step 1: Create SQS Queue

Navigate to SQS → Create queue

Type: Standard

Visibility timeout: 60 seconds

Create queue

Step 2: Create Dead Letter Queue

Create another SQS queue

Name: order-processing-dlq

Configure DLQ on main queue

Max receives: 3

Step 3: Create Lambda Consumer

Navigate to Lambda → Create function

Runtime: Python 3.12

Add SQS trigger

Use sample code:

def lambda_handler(event, context):
    for record in event['Records']:
        print(record['body'])
Enter fullscreen mode Exit fullscreen mode

Step 4: Send Message to Queue

aws sqs send-message \
--queue-url \
--message-body "Order123"

Validation

Message processed by Lambda

Failed messages move to DLQ

Top comments (0)