AWS SQS Summary

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 by providing reliable messaging between components. SQS is a web service that gives you access to a message queue that can be used to store messages while waiting for a computer to process them. It is a distributed queue system that enables web service applications to quickly and reliably queue messages that one component in the application generates to be consumed by another component.

The sources use an example of a user searching for holiday packages to illustrate how SQS works. The user enters a query in their browser, which is sent to an EC2 instance. The EC2 instance puts the message in an SQS queue. Another EC2 instance pulls the message from the queue and processes it by obtaining flight information from an airline service. The result is then sent back to the user.

One of the benefits of using SQS in this example is that if the application server crashes, the message in the queue is marked as invisible for a timeout interval. When the timeout runs out, the message reappears in the queue for another EC2 instance to process. This ensures that messages are not lost and highlights how SQS decouples the components of a distributed application and improves fault tolerance.

Key Features

  • Two Types of Queues: Standard Queues (default) and FIFO Queues (First-In-First-Out).
  • Standard Queues: Allow an unlimited number of transactions per second. They guarantee that a message will be delivered at least once, although sometimes more than one copy of a message might be delivered out of order. They provide best-effort ordering, which means messages are generally delivered in the same order they are sent, but it is not guaranteed.
  • FIFO Queues: Guarantee that messages are delivered in the order they are sent and processed once.
  • Visibility Timeout: The amount of time that a message is invisible in the SQS queue after a reader picks it up. The default visibility timeout is 30 seconds but can be increased to a maximum of 12 hours.

Key Concepts

  • Messages: The information that you send to and receive from SQS queues. They can contain up to 256 KB of text in any format, such as JSON, XML, or plain text.
  • Long Polling: Allows the consumer to wait for a message to arrive in the queue rather than continuously polling the queue.
  • Dead-Letter Queues: A dead-letter queue (DLQ) captures messages that cannot be processed successfully after a certain number of retries.

Benefits

  • Fully managed. AWS manages all aspects of infrastructure maintenance, including scaling, patching, and fault tolerance.
  • Scalability. SQS scales seamlessly with the number of messages in the queue.
  • Reliability. Messages in SQS are stored redundantly across multiple Availability Zones (AZs) within a region.
  • Decoupling. SQS helps decouple the components of an application, allowing them to operate independently and asynchronously.
  • Cost-effective. You only pay for what you use.