Messaging: SQS, SNS and EventBridge
Big systems are built from small parts that talk through messages, so one slow or broken part doesn't stop the others. This is called decoupling.
If an order page had to wait while the email is sent, the invoice is generated and the warehouse is notified, a slow email server would slow down every customer. Messaging services let one part say "an order was placed" and move on, while other parts handle the work in the background at their own pace. If one part fails, messages wait safely instead of being lost.
SQS - a queue
Simple Queue Service holds messages until a worker takes them. The website puts "send order email" in the queue and replies to the customer at once; a worker sends the email when it can.
- Standard queue - nearly unlimited speed; a message may arrive more than once or out of order.
- FIFO queue - exact order, no duplicates (great for payments per customer), lower speed.
- Dead-letter queue - messages that keep failing move here so you can look at them later.
- Lambda can read from a queue automatically, in batches.
import json, boto3
sqs = boto3.client("sqs")
QUEUE_URL = "https://sqs.ap-south-1.amazonaws.com/123456789012/order-emails"
sqs.send_message(QueueUrl=QUEUE_URL, MessageBody=json.dumps({"order_id": 101, "email": "asha@example.in"}))SNS - publish once, deliver to many
Simple Notification Service is a topic that many subscribers listen to: email, SMS, Lambda functions, SQS queues. Publish "order placed" once, and billing, warehouse and email services each get a copy ("fan-out").
EventBridge - an event bus with rules
EventBridge routes events by their content: "when an order over ₹10,000 is placed, call the fraud-check Lambda". It also receives events from AWS services and other SaaS apps, and its Scheduler runs jobs on a timetable (like cron).
{
"source": ["shop.orders"],
"detail-type": ["OrderPlaced"],
"detail": { "total": [{ "numeric": [">", 10000] }] }
}- SQS queues jobs for workers.
- SNS sends one message to many subscribers.
- EventBridge routes events by their content.
- Decoupling keeps slow or failing parts from blocking others.
