Decoupling Applications on AWS: SQS, SNS, EventBridge, Step Functions and Event-Driven Design

AWS Solutions Architect 50 min min read Updated: Nov 17, 2026 Intermediate
Decoupling Applications on AWS: SQS, SNS, EventBridge, Step Functions and Event-Driven Design
Intermediate Topic 1 of 3

Why Decouple?

In a tightly coupled system, if service B is slow or down, service A fails too. With a queue or event bus in between, A drops a message and moves on, and B processes it when it can. This gives resilience, scaling and flexibility.

text Tight: Web ──► Order service ──► Payment ──► Email (one failure breaks the chain) Decoupled: Web ──► SQS queue ──► Order workers (Auto Scaling on queue depth) └► SNS topic ──► Email queue, Analytics queue, Fraud Lambda

Amazon SQS: Simple Queue Service

SQS is a fully managed message queue. Producers send messages; consumers poll and delete them after processing. It is serverless and scales almost without limit.

Standard queueFIFO queue
ThroughputNearly unlimited300 messages/s per API action (3,000 with batching) and higher with high throughput mode
OrderingBest-effort, may be out of orderStrict order within a message group ID
DeliveryAt-least-once (duplicates possible)Exactly-once processing (5-minute deduplication)
Nameanymust end with .fifo
UseMost workloads. Make consumers idempotentOrders, financial steps, commands where order matters
SettingMeaning
Visibility timeoutAfter a consumer receives a message it is hidden for this time (default 30 s, max 12 h). If not deleted in time it reappears and is processed again. Set longer than processing time
RetentionMessages stay up to 14 days (default 4 days)
Message sizeUp to 256 KB. Bigger: store the payload in S3 and send a pointer (Extended Client Library)
Long pollingReceiveMessageWaitTimeSeconds 1-20. Waits for messages: fewer empty responses and lower cost. Prefer it
Delay queueDelay delivery up to 15 minutes
Dead-letter queue (DLQ)Messages that fail maxReceiveCount times move to a DLQ for inspection. DLQ of a FIFO queue must be FIFO
EncryptionSSE-SQS or SSE-KMS, HTTPS in transit
bash DLQ_ARN=$(aws sqs create-queue --queue-name orders-dlq --query QueueUrl --output text | xargs -I{} aws sqs get-queue-attributes --queue-url {} --attribute-names QueueArn --query Attributes.QueueArn --output text) aws sqs create-queue --queue-name orders --attributes '{"VisibilityTimeout":"60","ReceiveMessageWaitTimeSeconds":"20","MessageRetentionPeriod":"345600","RedrivePolicy":"{\"deadLetterTargetArn\":\"'$DLQ_ARN'\",\"maxReceiveCount\":\"5\"}"}' aws sqs send-message --queue-url $Q --message-body '{"orderId":"A100"}' aws sqs receive-message --queue-url $Q --wait-time-seconds 20 --max-number-of-messages 10
python import boto3, json sqs = boto3.client("sqs") while True: resp = sqs.receive_message(QueueUrl=Q, MaxNumberOfMessages=10, WaitTimeSeconds=20) for m in resp.get("Messages", []): order = json.loads(m["Body"]) process(order) # must be idempotent sqs.delete_message(QueueUrl=Q, ReceiptHandle=m["ReceiptHandle"]) # delete only after success
Scaling pattern: Auto Scaling group of workers scaled on **ApproximateNumberOfMessagesVisible per instance** (backlog per instance). A very common exam answer for decoupling a web tier from a processing tier.

Amazon SNS: Simple Notification Service

SNS is a publish/subscribe service. A publisher sends a message to a topic and SNS pushes it to all subscribers: SQS queues, Lambda, HTTP(S) endpoints, email, SMS, mobile push, Kinesis Data Firehose.

  • Standard topics (high throughput, at-least-once) and FIFO topics (ordering and dedup, with SQS FIFO subscribers)
  • Message filtering: each subscription has a filter policy on message attributes so it gets only matching messages
  • Delivery retries and a DLQ for failed deliveries
  • Server-side encryption with KMS, access policy on the topic

The Fan-Out Pattern: SNS + SQS

text Order service ──► SNS topic "order-created" ├─► SQS queue "billing" ─► billing workers ├─► SQS queue "shipping" ─► shipping workers (filter: country = IN) ├─► SQS queue "analytics" ─► Kinesis / Lambda └─► Lambda "fraud-check"
bash TOPIC=$(aws sns create-topic --name order-created --query TopicArn --output text) aws sns subscribe --topic-arn $TOPIC --protocol sqs --notification-endpoint $BILLING_QUEUE_ARN aws sns subscribe --topic-arn $TOPIC --protocol sqs --notification-endpoint $SHIPPING_QUEUE_ARN \ --attributes '{"FilterPolicy":"{\"country\":[\"IN\"]}","RawMessageDelivery":"true"}' aws sns publish --topic-arn $TOPIC --message '{"orderId":"A100"}' --message-attributes '{"country":{"DataType":"String","StringValue":"IN"}}'
  • The SQS queue policy must allow sns.amazonaws.com to sqs:SendMessage from the topic ARN
  • Fan-out is durable: each queue stores its copy even if its consumer is down

Amazon EventBridge

EventBridge is a serverless event bus that routes events from AWS services, your apps and SaaS partners to targets using rules with pattern matching. It is the modern choice for event-driven architectures.

PieceMeaning
Event busDefault bus (AWS service events), custom buses (your apps), partner buses (SaaS like Zendesk)
RuleAn event pattern (JSON filter) or a schedule (cron/rate) with up to 5 targets
TargetsLambda, SQS, SNS, Step Functions, ECS tasks, Kinesis, API destinations (any HTTP API), another bus, and 20+ services
Schema registryDiscover and version event schemas
Archive and replayStore events and replay them later
EventBridge SchedulerOne-time and recurring schedules at scale (replaces many cron jobs)
PipesPoint-to-point integration from a source (SQS, Kinesis, DynamoDB streams) with filtering and enrichment to a target
json { "source": ["aws.ec2"], "detail-type": ["EC2 Instance State-change Notification"], "detail": {"state": ["terminated"]} }
bash aws events put-rule --name nightly-report --schedule-expression "cron(0 20 * * ? *)" aws events put-targets --rule nightly-report --targets Id=1,Arn=arn:aws:lambda:ap-south-1:123456789012:function:report aws events put-events --entries '[{"Source":"shop.orders","DetailType":"OrderCreated","Detail":"{\"orderId\":\"A100\",\"total\":499}","EventBusName":"shop-bus"}]'

AWS Step Functions

Step Functions coordinates multiple services into workflows (state machines) with branching, retries, parallel steps, waits and human approval, written in Amazon States Language (JSON) or built visually in Workflow Studio.

TypeFeaturesUse for
StandardUp to 1 year runtime, exactly-once, full execution history, priced per state transitionLong-running, auditable business processes
ExpressUp to 5 minutes, at-least-once, very high rate, priced per request and durationHigh-volume event processing, streaming data, microservice orchestration
json { "StartAt": "ValidateOrder", "States": { "ValidateOrder": {"Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Parameters": {"FunctionName": "validate-order", "Payload.$": "$"}, "Retry": [{"ErrorEquals": ["States.TaskFailed"], "IntervalSeconds": 2, "MaxAttempts": 3, "BackoffRate": 2.0}], "Catch": [{"ErrorEquals": ["States.ALL"], "Next": "OrderFailed"}], "Next": "ChargeAndReserve"}, "ChargeAndReserve": {"Type": "Parallel", "Branches": [ {"StartAt": "Charge", "States": {"Charge": {"Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Parameters": {"FunctionName": "charge-card", "Payload.$": "$"}, "End": true}}}, {"StartAt": "Reserve", "States": {"Reserve": {"Type": "Task", "Resource": "arn:aws:states:::dynamodb:updateItem", "Parameters": {"TableName": "Stock", "Key": {"sku": {"S.$": "$.sku"}}, "UpdateExpression": "SET qty = qty - :one", "ExpressionAttributeValues": {":one": {"N": "1"}}}, "End": true}}}], "Next": "Notify"}, "Notify": {"Type": "Task", "Resource": "arn:aws:states:::sns:publish", "Parameters": {"TopicArn": "arn:aws:sns:ap-south-1:123456789012:order-created", "Message.$": "States.JsonToString($)"}, "End": true}, "OrderFailed": {"Type": "Fail", "Error": "OrderFailed", "Cause": "Validation or processing failed"} } }
  • Direct SDK integrations call 200+ AWS services without Lambda glue code
  • Wait for callback (task token) pauses until a human or system responds
  • Map state runs steps for each item in an array (distributed map can handle millions of S3 objects)
  • The Saga pattern with Catch and compensating steps handles failure across services

Amazon MQ

  • Managed Apache ActiveMQ and RabbitMQ brokers
  • Use when migrating existing apps that use standard protocols (AMQP, MQTT, OpenWire, STOMP, JMS). For new cloud-native apps prefer SQS/SNS/EventBridge
  • Multi-AZ active/standby deployment for high availability

Choosing the Right Service

NeedService
Buffer work between tiers, each message processed by one consumerSQS
Strict ordering and dedup of commandsSQS FIFO
Broadcast one message to many subscribersSNS (fan-out with SQS)
React to AWS or SaaS events, content-based routing, schedulesEventBridge
Orchestrate a multi-step workflow with retries and branchesStep Functions
Stream of ordered, replayable records consumed by many readers at onceKinesis Data Streams
Existing app using JMS, AMQP, MQTTAmazon MQ

Practice Tasks

  1. Create a standard queue with a DLQ (maxReceiveCount 3), send a poison message, and watch it move to the DLQ
  2. Build SNS to two SQS queues with a filter policy on one
  3. Create an EventBridge rule that reacts to an S3 object-created event and invokes Lambda
  4. Draw a Step Functions workflow for order processing with a failure path
  5. Explain visibility timeout using a timeline for a message that takes 40 seconds to process with a 30-second timeout

Conclusion

Decouple tiers with SQS (queues, long polling, DLQ, FIFO when order matters), fan out with SNS, route events with EventBridge, orchestrate with Step Functions, and use Amazon MQ only to migrate existing brokers. Make consumers idempotent and scale workers on queue depth.

Quick Summary: SQS standard vs FIFO + visibility/DLQ/long poll; SNS fan-out + filter; EventBridge rules/pipes/scheduler; Step Functions ASL + Standard vs Express; MQ; choose table.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators