CLF-C02Chapter 108 of 130Objective 3.5

Amazon SQS — Simple Queue Service

This chapter covers Amazon Simple Queue Service (SQS), a fully managed message queuing service that decouples the components of a cloud application. SQS is a core service in the AWS messaging and integration category, and it appears frequently on the CLF-C02 exam under Domain 3: Cloud Technology Services. Understanding SQS is critical because it demonstrates key cloud design principles like loose coupling, scalability, and fault tolerance. This objective carries approximately 5-8% of the exam weight, and you will see questions about its features, use cases, and how it compares to other AWS messaging services.

25 min read
Beginner
Updated May 31, 2026

The Restaurant Order Ticket System

Imagine a busy restaurant kitchen. The chefs (your application components) need to know what orders to cook. Instead of having customers (user requests) shout orders directly at the chefs — which would cause chaos, missed orders, and bottlenecks — the restaurant uses a ticket system. Each order is written on a ticket and placed on a rotating metal spike (the queue). The chefs pull tickets from the spike one at a time, in the order they were placed (first-in, first-out). If a chef is busy with a steak, the ticket for the salad sits on the spike until a chef is free. The spike holds tickets even if no chef is looking at it — it's durable. The restaurant can also add more chefs (scale horizontally) to process tickets faster, and each ticket is processed at least once. If a chef drops a ticket, it stays on the spike for another chef to pick up. The spike has a maximum capacity — if too many tickets pile up, new orders are rejected (queue full). This is exactly how Amazon SQS works: it decouples the producers (customers) from the consumers (chefs), buffering messages (tickets) so that each component can work independently and at its own pace.

How It Actually Works

What is Amazon SQS and What Problem Does It Solve?

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. In a traditional monolithic application, components communicate directly with each other. If one component fails or becomes slow, the entire system can degrade or break. SQS introduces a buffer — a queue — between components. Producers send messages to the queue, and consumers poll (retrieve) messages from the queue. This decoupling means that if a consumer fails, messages are safely stored in the queue until the consumer recovers. If traffic spikes, the queue absorbs the load, preventing system overload.

How SQS Works — The Mechanism

SQS uses a pull-based model. Here is the step-by-step mechanism:

1.

Producer sends a message: An application component (e.g., an EC2 instance, Lambda function, or on-premises server) sends a message to an SQS queue using the AWS SDK, CLI, or API. The message can be up to 256 KB of text in any format (JSON, XML, plain text).

2.

SQS stores the message: SQS durably stores the message across multiple Availability Zones (AZs) within the AWS Region. The message is replicated to ensure high availability and durability.

3.

Consumer polls for messages: A consumer (another application component) polls the queue for messages. Polling can be short (immediate return if no messages) or long (waits up to 20 seconds for a message to arrive). Long polling reduces costs and latency.

4.

Consumer processes the message: The consumer receives the message and processes it (e.g., updates a database, calls an API, or triggers a workflow).

5.

Consumer deletes the message: After successful processing, the consumer sends a delete request to SQS to remove the message from the queue. If the consumer fails to delete (e.g., crashes), the message becomes visible again after the visibility timeout expires (default 30 seconds, max 12 hours). This ensures at-least-once delivery.

Key Concepts and Configuration

- Queue Types: SQS offers two types of queues: - Standard Queue: High throughput (nearly unlimited transactions per second), at-least-once delivery, and best-effort ordering. Messages may be delivered more than once and may arrive out of order. Use when throughput is critical and ordering is not strict. - FIFO Queue: First-In-First-Out delivery, exactly-once processing (no duplicates), and limited throughput (3,000 messages per second with batching, 300 without). The queue name must end with .fifo. Use when order and deduplication are critical (e.g., financial transactions).

Visibility Timeout: The period during which a message is hidden from other consumers after being polled. If the consumer does not delete the message within this timeout, it becomes visible again. Set this based on expected processing time.

Dead-Letter Queue (DLQ): A separate queue that receives messages that failed processing after a specified number of attempts (max receives). This helps isolate problematic messages for analysis.

Message Retention: Messages can be retained in the queue from 1 minute to 14 days (default 4 days). After retention expires, messages are automatically deleted.

Delivery Delay: You can delay the delivery of messages to consumers by up to 15 minutes (delay queue). This is useful for scheduling.

Message Size: 256 KB maximum per message. For larger payloads, use S3 to store the payload and send a reference in the SQS message.

Pricing Model

SQS pricing is based on usage: - Requests: Each API action (SendMessage, ReceiveMessage, DeleteMessage, etc.) counts as a request. Standard queues: $0.40 per million requests (first 1 million free per month). FIFO queues: $0.50 per million requests. - Data Transfer: Data transfer out to the internet is charged at standard AWS data transfer rates. Data transfer between SQS and other AWS services in the same region is free. - No upfront costs or minimum fees.

Comparison to On-Premises or Competing Approaches

On-premises message queuing systems (e.g., RabbitMQ, ActiveMQ) require you to provision, manage, and scale servers. You must handle failover, patching, and capacity planning. SQS is fully managed — no servers to manage, automatic scaling, and high availability by default. AWS also offers Amazon MQ, a managed message broker for ActiveMQ and RabbitMQ, for those who need compatibility with existing protocols. SQS is simpler and more cloud-native, while Amazon MQ provides migration paths for legacy systems.

When to Use SQS vs. Alternatives

SQS: Use when you need a simple, fully managed queue for decoupling application components. Ideal for asynchronous processing, task queues, and buffering requests.

Amazon SNS (Simple Notification Service): Use for pub/sub messaging where multiple subscribers need to receive the same message. SNS pushes messages to subscribers (e.g., Lambda, SQS, HTTP endpoints), while SQS uses pull-based polling.

Amazon Kinesis: Use for real-time streaming of large data (e.g., log data, clickstreams) where you need to process data in order and replay records. Kinesis is designed for data streams, not task queues.

Amazon MQ: Use if you are migrating an existing application that uses standard messaging protocols (AMQP, MQTT, STOMP) and you want to avoid rewriting code.

Walk-Through

1

Create an SQS Queue

Navigate to the SQS console in AWS Management Console. Click 'Create queue'. Choose queue type: Standard or FIFO. For FIFO, you must enable content-based deduplication or provide a deduplication ID. Set configuration options: visibility timeout (default 30 seconds), message retention period (default 4 days), maximum message size (1 KB to 256 KB), delivery delay (0 to 900 seconds), and receive message wait time (0 to 20 seconds for long polling). Optionally, configure a dead-letter queue by specifying a redrive policy (max receives, e.g., 3). Click 'Create queue'. AWS creates the queue and provides a URL and ARN. The queue is now ready to send and receive messages.

2

Send a Message to the Queue

Use the AWS CLI, SDK, or console to send a message. In the console, select the queue, click 'Send and receive messages'. Enter message body (up to 256 KB). For FIFO queues, you must provide a message group ID (required) and can optionally provide a deduplication ID. Click 'Send message'. AWS stores the message durably across multiple AZs. The message will persist until a consumer retrieves and deletes it, or until the retention period expires. You can also send messages programmatically using the SendMessage API. Example CLI command: `aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue --message-body "Hello World"`

3

Receive and Process Messages

A consumer (e.g., an EC2 instance running a worker process) polls the queue for messages. Use the ReceiveMessage API. For efficiency, enable long polling by setting ReceiveMessageWaitTimeSeconds to 20 (max). The consumer receives up to 10 messages per request. After receiving, the consumer processes each message (e.g., transform data, call a downstream service). The message becomes invisible to other consumers during the visibility timeout. If processing succeeds, the consumer calls DeleteMessage with the receipt handle to remove the message. If processing fails, the consumer may leave the message (it will reappear after timeout) or send it to a dead-letter queue after exceeding max receives.

4

Configure Monitoring and Alarms

SQS integrates with Amazon CloudWatch to provide metrics like NumberOfMessagesSent, NumberOfMessagesReceived, ApproximateNumberOfMessagesVisible, ApproximateAgeOfOldestMessage, and SentMessageSize. Create CloudWatch alarms to alert on queue depth (e.g., if ApproximateNumberOfMessagesVisible exceeds a threshold) to detect backlogs. You can also enable SQS queue logging with AWS CloudTrail to audit API calls. For FIFO queues, monitor for high message age that may indicate processing bottlenecks. Use these metrics to auto-scale consumers (e.g., using EC2 Auto Scaling based on queue depth).

5

Handle Failures with Dead-Letter Queue

Configure a dead-letter queue (DLQ) to capture messages that cannot be processed after a specified number of attempts. In the queue configuration, set 'Redrive allow policy' to 'By queue' and specify the DLQ ARN. Set 'Maximum receives' to e.g., 3. When a message is received but not deleted after 3 attempts, SQS automatically moves it to the DLQ. The DLQ is a standard or FIFO queue that stores failed messages for analysis. You can then examine the DLQ messages, fix the issue, and re-drive (move) them back to the source queue using the 'DLQ redrive' feature. This prevents poison-pill messages from blocking the main queue.

What This Looks Like on the Job

Scenario 1: Order Processing in an E-Commerce Platform

An online retailer uses a microservices architecture. When a customer places an order, the order service sends a message to an SQS queue. The inventory service polls the queue to reserve items, the payment service polls to process payment, and the shipping service polls to initiate delivery. This decoupling ensures that if the payment service is slow, orders are still accepted and queued. During a flash sale, thousands of orders pour in simultaneously. SQS scales automatically, buffering the spike. The inventory service auto-scales based on queue depth (using CloudWatch alarms) to process orders faster. Cost is low — only pennies for millions of messages. A common misconfiguration is setting the visibility timeout too short, causing duplicate processing when a consumer takes longer than expected. The team sets the timeout based on the 99th percentile processing time and uses a dead-letter queue to capture failed orders for manual review.

Scenario 2: Asynchronous Job Processing for a Video Transcoding Service

A video platform allows users to upload videos. When a video is uploaded, the upload service sends a message to an SQS queue with the video ID and S3 location. A fleet of EC2 Spot Instances polls the queue, downloads the video, transcodes it to multiple formats, and uploads the results back to S3. After successful transcoding, the worker deletes the message. If a worker crashes mid-transcoding, the message becomes visible again after the visibility timeout, and another worker picks it up. The team uses a FIFO queue to ensure that if a user uploads multiple videos in a specific order, they are processed in that order. They also use long polling to reduce costs (fewer empty responses). A pitfall is not setting a maximum receive count — a malformed video could cause infinite retries. They configure a dead-letter queue with max receives of 3 to isolate problematic videos.

Scenario 3: Decoupling Web Tier from Backend in a Serverless Application

A news website uses AWS Lambda for the backend. When a user submits a comment, API Gateway invokes a Lambda function that validates the comment and sends it to an SQS queue. Another Lambda function (polling the queue via an event source mapping) processes the comment (e.g., stores it in DynamoDB, sends notifications). This decouples the frontend from the backend write path. If the database is under heavy load, the queue buffers incoming comments. The Lambda consumer can scale up to 1,000 concurrent executions (default limit) to process comments faster. The team uses a DLQ to capture comments that fail processing due to validation errors. A common mistake is not enabling the Lambda event source mapping correctly — the Lambda function must have permissions to poll and delete messages from SQS. The team uses AWS SAM to define the infrastructure and set the batch size to 10 to process multiple comments per invocation.

How CLF-C02 Actually Tests This

What CLF-C02 Tests on SQS

The CLF-C02 exam tests your understanding of SQS as a decoupling mechanism, its two queue types (Standard vs. FIFO), and its role in building scalable, fault-tolerant architectures. You should know:

The difference between Standard and FIFO queues: Standard offers high throughput and at-least-once delivery; FIFO offers exactly-once processing and first-in-first-out ordering.

The concept of visibility timeout and its purpose (to prevent multiple consumers from processing the same message).

The use of dead-letter queues to handle failed messages.

How SQS differs from SNS (push vs. pull).

That SQS is a regional service (messages are stored across multiple AZs).

Common Wrong Answers and Why Candidates Choose Them

1.

'SQS guarantees exactly-once delivery for standard queues' — Candidates confuse Standard with FIFO. Standard queues provide at-least-once delivery, meaning duplicates are possible. FIFO queues provide exactly-once processing.

2.

'SQS pushes messages to consumers' — This is a common mistake because SNS pushes messages. SQS uses a pull model; consumers must poll the queue.

3.

'SQS can be used for real-time streaming of large data' — Candidates may confuse SQS with Amazon Kinesis. SQS is for message queuing, not streaming. Message size is limited to 256 KB.

4.

'SQS messages are stored indefinitely' — The default retention period is 4 days, with a maximum of 14 days. Messages are automatically deleted after retention expires.

5.

'You need to provision servers for SQS' — SQS is fully managed; no server provisioning is required.

Specific Terms and Values That Appear on the Exam

Queue types: Standard, FIFO (name ends with .fifo)

Visibility timeout: default 30 seconds, range 0 seconds to 12 hours

Message retention: default 4 days, min 1 minute, max 14 days

Message size: up to 256 KB

Long polling: receive message wait time up to 20 seconds

Dead-letter queue: max receives setting (e.g., 3)

Throughput: Standard — nearly unlimited; FIFO — 300 messages per second (without batching), 3,000 with batching

Tricky Distinctions Between Similar Services

The exam often asks you to choose between SQS, SNS, and Kinesis. Use this decision rule:

If the scenario requires decoupling and asynchronous processing of tasks (e.g., order processing), choose SQS.

If the scenario requires publishing messages to multiple subscribers (e.g., sending email and SMS for the same event), choose SNS.

If the scenario requires real-time processing of streaming data (e.g., clickstreams, log data) with ordering and replay capability, choose Kinesis.

Elimination Strategy

When you see a question about message queuing, eliminate options that mention push delivery (unless it's SNS). Eliminate options that claim exactly-once for standard queues. Eliminate options that require server management. Look for keywords like 'decouple', 'buffer', 'asynchronous', 'polling' to confirm SQS.

Key Takeaways

SQS is a fully managed message queuing service for decoupling application components.

Two queue types: Standard (high throughput, at-least-once) and FIFO (exactly-once, ordered).

Visibility timeout prevents multiple consumers from processing the same message; default 30 seconds.

Messages are stored durably across multiple AZs and retained for 1 minute to 14 days (default 4 days).

Maximum message size is 256 KB; use S3 for larger payloads.

Long polling (up to 20 seconds) reduces cost and latency.

Dead-letter queues isolate messages that fail processing after a set number of attempts.

SQS is pull-based; SNS is push-based.

FIFO queue names must end with .fifo.

SQS integrates with Lambda via event source mappings for serverless processing.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Amazon SQS

Pull-based: consumers poll the queue.

At-least-once delivery (Standard) or exactly-once (FIFO).

Used for decoupling application components.

Messages can be delayed up to 15 minutes.

No fan-out capability; each message is consumed by one consumer.

Amazon SNS

Push-based: SNS pushes messages to subscribers.

At-least-once delivery.

Used for pub/sub messaging to multiple subscribers.

No message delay feature.

Supports fan-out to multiple endpoints (Lambda, SQS, HTTP, email, SMS).

Watch Out for These

Mistake

SQS is a push-based service like SNS.

Correct

SQS is pull-based; consumers must poll the queue to receive messages. SNS pushes messages to subscribers.

Mistake

Standard queues guarantee exactly-once delivery.

Correct

Standard queues provide at-least-once delivery; duplicates are possible. FIFO queues provide exactly-once processing.

Mistake

Messages in SQS are stored forever.

Correct

Messages have a configurable retention period from 1 minute to 14 days (default 4 days). After that, they are automatically deleted.

Mistake

SQS can handle messages larger than 256 KB.

Correct

The maximum message size is 256 KB. For larger payloads, store the payload in S3 and send a reference in the SQS message.

Mistake

You must provision and manage servers to use SQS.

Correct

SQS is a fully managed service. AWS handles the underlying infrastructure, scaling, and availability.

Frequently Asked Questions

What is the difference between Standard and FIFO SQS queues?

Standard queues offer high throughput (nearly unlimited transactions per second) and at-least-once delivery, meaning messages may be delivered more than once and may arrive out of order. FIFO queues guarantee first-in-first-out delivery and exactly-once processing, but throughput is limited to 300 messages per second (3,000 with batching). Use Standard when throughput is critical and ordering is not strict; use FIFO when order and deduplication are required, such as in financial transactions. On the exam, look for keywords like 'ordering' or 'duplicates' to identify FIFO scenarios.

How does SQS ensure messages are not lost?

SQS stores messages durably across multiple Availability Zones within a Region. When a producer sends a message, SQS replicates it synchronously to multiple AZs before acknowledging receipt. This ensures that even if one AZ fails, the message is still available. Additionally, messages are retained for a configurable period (default 4 days, max 14 days). Consumers must delete messages after processing; if they fail, the message becomes visible again after the visibility timeout. This combination of replication and retry ensures no message is lost.

Can SQS trigger a Lambda function automatically?

Yes, you can configure an event source mapping in Lambda to poll an SQS queue and invoke a Lambda function with messages. Lambda automatically scales the number of concurrent executions based on the queue depth. This is a common pattern for serverless applications. However, note that Lambda is not directly triggered by SQS in the same way SNS triggers Lambda; Lambda actively polls the queue. You must grant the Lambda function permissions to receive and delete messages from the queue.

What is the visibility timeout and how should I set it?

The visibility timeout is the period during which a message is hidden from other consumers after being received. It prevents multiple consumers from processing the same message. You should set it to a value slightly higher than the expected processing time for a typical message. If you set it too low, other consumers may see the message before processing is complete, causing duplicate processing. If you set it too high, a consumer failure delays message reprocessing. The default is 30 seconds, with a maximum of 12 hours.

How does SQS pricing work?

SQS charges based on the number of requests (API calls). Each SendMessage, ReceiveMessage, DeleteMessage, etc., counts as a request. Standard queues cost $0.40 per million requests after the first 1 million free per month. FIFO queues cost $0.50 per million requests. Data transfer out to the internet is charged at standard AWS data transfer rates, but data transfer between SQS and other AWS services in the same region is free. There are no upfront costs or minimum fees.

What is a dead-letter queue (DLQ) and when should I use one?

A dead-letter queue is a separate SQS queue that receives messages that have failed processing after a specified number of attempts (max receives). You configure a redrive policy on the source queue to move messages to the DLQ after the max receives threshold is exceeded. Use a DLQ to isolate problematic messages (e.g., malformed data) so they don't block the main queue. You can then analyze the DLQ messages, fix the issue, and re-drive them back to the source queue for reprocessing. On the exam, remember that DLQs help with debugging and preventing poison-pill messages.

Can I send large messages (e.g., 10 MB) with SQS?

No, the maximum message size is 256 KB. For larger payloads, you should store the payload in Amazon S3 and send a reference (e.g., S3 object key) in the SQS message. The consumer can then retrieve the payload from S3. This pattern is known as the 'SQS extended client library' or 'large message handling'. AWS provides an SQS Extended Client Library for Java that handles this automatically.

Terms Worth Knowing

Ready to put this to the test?

You've just covered Amazon SQS — Simple Queue Service — now see how well it sticks with free CLF-C02 practice questions. Full explanations included, no account needed.

Done with this chapter?