A FULLY-MANAGED MESSAGE QUEUING SERVICE IN THE CLOUD
Amazon Simple Queue Service (SQS) is a fully-managed message queuing service that dramatically helps to decouple systems, increase reliability, scale microservices, and integrate applications.
Believe it or not: SQS was the first publicly launched service by AWS.
Quoting Jeff Barr: "We launched the Simple Queue Service in late 2004, Amazon S3 in early 2006, and Amazon EC2 later that summer."
One more detail to get you excited about SQS's capabilities: At Amazon's Prime Day in 2021, a new traffic record was set with SQS processing 47.7 million đ¨ messages per second at its peak.
Event-driven architectures are a very common way of realizing modern microservice applications. They are built around events which are exchanged between components and often carry a state or used as identifiers.
A message will be produced by one component (Producer) and consumed by another (Consumer). This enables easier error-handling (e.g. reprocessing of sub-routines) which will result in a less coupled and error-prone system.
Even more: it's not fatal if...
There are several types of queues for varying requirements:
After receiving a message, it's hidden for other consumers for a certain period (= message is inflight).
If the message is not deleted before the timeout, it will be available again which could result in messages being delivered & processed more than once.
âšī¸ Default timeout is 30 seconds & max timeout is 12 hours.
Besides Visibility Timeout & Retention Period, there are additional configurations for queues you can take:
As with all other services you can configure policies that define the accounts, users, and roles that can access your queues and which actions are allowed or denied.
Define how long SQS stores each individual message while waiting for it to be processed and deleted. It can range from 1 minute to 14 days.
If the retention period is over, the message will be automatically discarded from the queue.
You can process SQS messages via a Lambda function. Lambda will poll the queue to invoke new function synchronously with an event that contains the queue message.
Messages for Lambda triggers can be aggregated together into batches. By that a single function invocation processes several messages at a time. This saves compute time, as there are fewer cold starts on average.
You can configure Server-Side Encryption (SSE) either via SQS-owned encryption keys (SSE-SQS) or via keys managed within AWS Key Management Service (SSE-KMS).
Both encryption modes protect messages at rest using 256-bit AES encryption. The messages will be encrypted as soon as SQS receives them & only decrypted when sending them to authorized consumers.
âšī¸ If using SSE-KMS, make sure all of your queue's principals have sufficient permissions for the encryption key.
As with other services, everything has its limitations:
The last limitation can be backed by using message batching to receive up to 10 messages at once, which will therefore result in being able to process up to 3000 messages per second per queue.
SQS provides two different types of message polling:
Each SQS message can contain up to 10 custom metadata attributes. These attributes are delivered together with the message body.
Consumers can use message attributes to handle messages in a particular way without having to process the entire message body first.
You need to define how many times a message can be retrieved from a consumer until it's considered unprocessable and will be discarded from the queue.
Instead of discarding the message, define another queue as a Dead Letter Queue (DLQ) to forward messages to after the limit is exceeded.
Dead Letter Queues help you to unblock your messaging system - without losing messages. If a message is unprocessable, you can either define an automatic exception handling process or just step in for taking manual diagnostics to solve the underlying issue.
By default, SQS automatically send metrics to CloudWatch like the visible messages count, the number of empty receives, messages that had been sent to the queue, or the number of deleted messages.
One-click integration tools like đ Dashbird.io help to provide all those metrics with a all-in-one dashboard so you always know what's up. Additionally, you get well-architected hints for best practices.
A few points to focus on when starting with SQS: