โข Introduction
โข Importance of Messaging Systems
โข Fundamentals
โข Queue Types
โข Visibility Timeouts
โข Retention Periods
โข Limitations
{ 1/22 }
๐๐ป๐๐ฟ๐ผ๐ฑ๐๐ฐ๐๐ถ๐ผ๐ป
Believe it or not: SQS was the ๐ณ๐ถ๐ฟ๐๐ publicly launched service by AWS!
Quoting Jeff Bar:
"We launched the Simple Queue Service in ๐น๐ฎ๐๐ฒ ๐ฎ๐ฌ๐ฌ๐ฐ, Amazon S3 in early 2006, and Amazon EC2 later that summer."
Maybe one more detail to get you excited about SQS's capabilities:
At Amazon's Prime Days in 2021, a new traffic record was set with SQS processing ๐ฐ๐ณ.๐ณ ๐บ๐ถ๐น๐น๐ถ๐ผ๐ป ๐บ๐ฒ๐๐๐ฎ๐ด๐ฒ๐ ๐ฝ๐ฒ๐ฟ ๐๐ฒ๐ฐ๐ผ๐ป๐ฑ at the peak!
SQS is a service that allows you to store messages that then await processing by another service, like for example a Lambda function
It's a core service that drastically helps to decouple systems and increase reliability
{ 4/22 }
A simple example: you're offering customers to register at your side, but several long-running sub-processes are triggered with that, maybe one's that do high latency 3rd party calls.
Surely you can do all operations blocking, but this can cause a lot of problems.
{ 5/22 }
First, submitting the formula will result in a long waiting period until it's finally processed, as all including operations need to be finished before returning a result to the customer.
Additionally: if some operation fails, error handling is hardly possible.
{ 6/22 }
Generally, it's just delegated to the customer to retry the operation, which can result in losing the potential customer at all - which is the second downside.
With messaging systems, you can easily decouple downstream operations that don't need to be synchronous.
Messaging systems like SQS also solve more problems, like:
โข the producing system is working faster than the consuming or
โข the producer or consumer has only intermittent network connection
{ 8/22 }
Having a look at ๐๐ฎ๐บ๐ฏ๐ฑ๐ฎ, there's more to gain: messages for Lambda triggers can be aggregated together into ๐ฏ๐ฎ๐๐ฐ๐ต๐ฒ๐, so one function invocation processes several messages at a time.
This saves computation times, as there are fewer cold starts on average.
{ 9/22 }
๐๐๐ป๐ฑ๐ฎ๐บ๐ฒ๐ป๐๐ฎ๐น๐
Any service of your distributed system can ๐๐๐ผ๐ฟ๐ฒ & ๐ฟ๐ฒ๐ฐ๐ฒ๐ถ๐๐ฒ messages at SQS programmatically via Amazon's API. Messages can:
โข can contain up to 256 KBs of text and
โข can be in your favorite format like JSON or XML
{ 10/22 }
๐ค๐๐ฒ๐๐ฒ ๐ง๐๐ฝ๐ฒ๐
How messages are processed depends on the queue type you've selected.
There are two of them:
โข Standard Queues (selected by default)
โข FIFO Queues (๐irst-๐n-๐irst-๐ขut)
Most important facts:
โข guarantee that messages are delivered at least once
โข there's a best-effort ordering, meaning generally messages are delivered in the order they are sent - but there's no guarantee
{ 12/22 }
๐๐๐๐ข ๐ค๐๐ฒ๐๐ฒ
โข transaction processing limit is capped at 300 transactions per second
โข guarantees ordering
โข guarantees that there's exactly-once processing of all messages
โข support for message groups
{ 13/22 }
What are ๐ ๐ฒ๐๐๐ฎ๐ด๐ฒ ๐๐ฟ๐ผ๐๐ฝ๐?
There's the option to assign a ๐ ๐ฒ๐๐๐ฎ๐ด๐ฒ ๐๐ฟ๐ผ๐๐ฝ ๐๐ฑ๐ฒ๐ป๐๐ถ๐ณ๐ถ๐ฒ๐ฟ. This means that messages with the same ID will be processed in the correct order.
๐๐ ๐ฎ๐บ๐ฝ๐น๐ฒ: processing messages of the same customer in order!
{ 14/22 }
This means SQS only guarantees that messages for the same customer identifier are delivered in a FIFO manner, but messages for other customers can be processed in parallel and ๐ฑ๐ผ๐ป'๐ have to be in the order they are sent to SQS.
If a consumer picks up a message from SQS, it's hidden for all other consumers for a certain period of time (=inflight). If the message is successfully processed by the consumer within that time, it will be deleted from the queue
{ 16/22 }
If not, the message will be available again for all consumers which could result in messages being delivered & processed ๐บ๐ผ๐ฟ๐ฒ ๐๐ต๐ฎ๐ป ๐ผ๐ป๐ฐ๐ฒ.
Facts:
โข default visibility timeout is 30 seconds
โข it's not possible to configure a timeout of more than 12 hours
You can define how long SQS stores each individual message while waiting for it to be processed. It can range from ๐ญ ๐บ๐ถ๐ป๐๐๐ฒ up to ๐ญ๐ฐ ๐ฑ๐ฎ๐๐.
If the retention period is over, the message will be deleted from the queue.
Besides timeouts & retentions, you can define how many times a message can be retrieved until it's considered ๐๐ป๐ฝ๐ฟ๐ผ๐ฐ๐ฒ๐๐๐ฎ๐ฏ๐น๐ฒ.
Define another queue (Dead Letter) to forward messages to after the limit is exceeded.
{ 19/22 }
Dead Letter Queues help you unblock your messaging systems, without actual losing messages. If a message is unprocessable, you can either define an automated exception handling process or just step in for taking manual action.
{ 20/22 }
SQS has some ๐๐ถ๐บ๐ถ๐๐ฎ๐๐ถ๐ผ๐ป๐
โข 120k messages can be inflight at a time - for FIFO Queues it's 20k
โข 256 KB message size limit (there are library extensions for SQS to store messages in S3 & only send references)
โข FIFO only allows 300 operations/second
{ 21/22 }
The last limitation can be tackled by using ๐บ๐ฒ๐๐๐ฎ๐ด๐ฒ ๐ฏ๐ฎ๐๐ฐ๐ต๐ถ๐ป๐ด to receive up to 10 messages at once, which will therefore result in being able to process up to 3,000 messages per second per queue.
{ 22/22 }
That's already the end - thank you for reading! ๐
I hope you learned something new & made you excited to put SQS into use.
If you've enjoyed this thread, I'd be happy if you โป๏ธ or โฅ๏ธ the initial post!
... and be sure to follow me for more regular cloud content! ๐ค
โข โข โข
Missing some Tweet in this thread? You can try to
force a refresh
There's a lot that comes out of the box to gain insights into how well your serverless app is performing
A quick overview to get you started โ
1๏ธโฃ Amazon CloudWatch
CloudWatch automatically monitors your functions on your behalf. It reports a lot of useful metrics:
โข number of invocations
โข execution durations
โข occurred errors
โข function throttles
Everything is exposed on a function level!
2๏ธโฃ Amazon CloudTrail
CloudTrail offers you governance, compliance & auditing features for several services, including Lambda.
It enables you to log all (encryption supported!) actions taken regarding your infrastructure, regardless if it's via the console UI or AWS SDK!
Thanks for all your interest in my AWS 1x1 threads! ๐ ๐
The good news: ๐๐ต๐ฒ๐ฟ๐ฒ'๐ ๐ฎ ๐น๐ผ๐ ๐บ๐ผ๐ฟ๐ฒ ๐ถ๐ป ๐๐ต๐ฒ ๐ฝ๐ถ๐ฝ๐ฒ๐น๐ถ๐ป๐ฒ!
... also for Azure ๐
Didn't see the previous ones yet?
๐๐ถ๐ป๐ธ๐ ๐๐ผ ๐ฎ๐น๐น ๐บ๐ ๐ฟ๐ฒ๐ฐ๐ฒ๐ป๐ ๐ฝ๐ผ๐๐๐ ๐ฎ๐ฟ๐ฒ ๐ฏ๐ฒ๐น๐ผ๐ โ
โข Fan-in & Fan-out
โข Simple Web Service
โข Publish/Subscribe
โข Strangler
โข Aggregator
{ 1/7 }
๐๐ฎ๐ป-๐ถ๐ป & ๐๐ฎ๐ป-๐ผ๐๐
Common problem: large tasks that are exceeding Lambda's execution time limit
With Fan-out, you're splitting those large tasks into small ones and delegating those to Lambda workers.
Afterward, results are aggregated (= Fan-in).
๐๐ฒ๐'๐ ๐ฏ๐ฒ ๐ต๐ผ๐ป๐ฒ๐๐: generally, debugging is not a fun task ๐คข
Especially for serverless, event-driven & distributed systems.
From Lambda's logging basics to ๐๐ฎ๐๐ถ๐ป๐ด ๐๐ถ๐บ๐ฒ & ๐ป๐ฒ๐ฟ๐๐ฒ๐ โ
Lambda's a serverless technology provided by AWS.
But that ๐ฑ๐ผ๐ฒ๐๐ป'๐ ๐บ๐ฒ๐ฎ๐ป that there are no servers.
In the background, there are countless micro-containers running on top of the traditional servers.
Where do all the logs of those containers go to?
By default, they will end up in CloudWatch.
Every Lambda will receive its own ๐น๐ผ๐ด ๐ด๐ฟ๐ผ๐๐ฝ.
Like a repository for logs.
Not only that, every micro-container will create a new so-called ๐น๐ผ๐ด ๐๐๐ฟ๐ฒ๐ฎ๐บ.
Think of it as a text file where logs are written to.