You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. SQS was the very first service AWS ever launched (in 2004) and remains one of the most heavily used services in the entire platform.
A message queue is a form of asynchronous communication. A producer places a message on the queue, and a consumer retrieves it later. The queue acts as a buffer between the two, decoupling their execution.
Producer ——> [SQS Queue] ——> Consumer
The producer does not wait for the consumer to process the message. The consumer pulls messages from the queue at its own pace.
| Problem Without a Queue | How SQS Solves It |
|---|---|
| Consumer is temporarily offline | Messages are stored in the queue until the consumer is available |
| Producer is faster than consumer | Messages buffer in the queue, preventing the consumer from being overwhelmed |
| Tight coupling between services | Producer and consumer only need to know about the queue, not each other |
| Single point of failure | SQS is highly available and durable across multiple AZs |
| Difficulty scaling consumers | Multiple consumers can read from the same queue in parallel |
SQS offers two types of queues:
| Feature | Standard | FIFO |
|---|---|---|
| Throughput | Nearly unlimited | Up to 300 msg/s (3,000 with batching) |
| Ordering | Best-effort | Guaranteed |
| Delivery | At-least-once | Exactly-once |
| Queue name suffix | None | Must end in .fifo |
You create a queue in the AWS Management Console, CLI, or SDK. You choose Standard or FIFO and configure settings like message retention and visibility timeout.
A producer sends a message to the queue. The message body can be up to 256 KB of text (JSON, XML, plain text, or any format).
import boto3
sqs = boto3.client('sqs')
sqs.send_message(
QueueUrl='https://sqs.eu-west-2.amazonaws.com/123456789012/my-queue',
MessageBody='{"orderId": "ORD-12345", "action": "process"}'
)
A consumer polls the queue for messages. SQS delivers messages to the consumer, and the consumer processes them.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.