๐Ÿ“š ๐—”๐—ช๐—ฆ ๐Ÿญ๐˜…๐Ÿญ - ๐—ฆ๐—ค๐—ฆ

Your fully managed message queue service & a serverless fan's best friend.

From queue types, over visibility timeouts to message groups โ†“
๐—ง๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ ๐—ข๐˜ƒ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐Ÿงต

โ€ข 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."

jeff-barr.com/2014/08/19/my-โ€ฆ

{ 2/22 }
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!

aws.amazon.com/blogs/aws/primโ€ฆ

{ 3/22 }
So what is AWS' Simple Message Service about?

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.

{ 7/22 }
๐—œ๐—บ๐—ฝ๐—ผ๐—ฟ๐˜๐—ฎ๐—ป๐—ฐ๐—ฒ ๐—ผ๐—ณ ๐— ๐—ฒ๐˜€๐˜€๐—ฎ๐—ด๐—ถ๐—ป๐—ด ๐—ฆ๐˜†๐˜€๐˜๐—ฒ๐—บ๐˜€

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)

{ 11/22 }
๐—ฆ๐˜๐—ฎ๐—ป๐—ฑ๐—ฎ๐—ฟ๐—ฑ ๐—ค๐˜‚๐—ฒ๐˜‚๐—ฒ

The default queue type of SQS.

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.

{ 15/22 }
๐—ฉ๐—ถ๐˜€๐—ถ๐—ฏ๐—ถ๐—น๐—ถ๐˜๐˜† ๐—ง๐—ถ๐—บ๐—ฒ๐—ผ๐˜‚๐˜๐˜€

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

{ 17/22 }
๐—ฅ๐—ฒ๐˜๐—ฒ๐—ป๐˜๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฒ๐—ฟ๐—ถ๐—ผ๐—ฑ๐˜€

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.

{ 18/22 }
๐——๐—ฒ๐—ฎ๐—ฑ ๐—Ÿ๐—ฒ๐˜๐˜๐—ฒ๐—ฟ ๐—ค๐˜‚๐—ฒ๐˜‚๐—ฒ๐˜€ (DLQ)

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
ใ€€

Keep Current with Tobias Schmidt

Tobias Schmidt Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @tpschmidt_

5 Nov
๐Ÿ“š AWS 1x1 - ๐—ฉ๐—ฃ๐—– & ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ๐—ถ๐—ป๐—ด

Your logically isolated virtual network in the cloud.

From Security Groups, over Route Tables to VPC Peering โ†“
๐—ง๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ ๐—ข๐˜ƒ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐Ÿงต

โ€ข VPCs & Subnets
โ€ข Route Tables
โ€ข Internet Gateway
โ€ข NAT Gateways & Instances
โ€ข Security Groups
โ€ข Network Access Control Lists
โ€ข VPC Peering

{ 1/14 }
Maybe you didn't know, but Amazon ๐—ฉirtual ๐—ฃrivate ๐—กetwork is the networking layer for EC2.

This virtual network imitates your local data center, but with all the benefits of the cloud's scalable infrastructure.

Knowing about VPC & networking is crucial.

{ 2/14 }
Read 16 tweets
4 Nov
๐Ÿ“š AWS 1x1 - ๐— ๐—ผ๐—ป๐—ถ๐˜๐—ผ๐—ฟ๐—ถ๐—ป๐—ด & ๐—”๐˜‚๐—ฑ๐—ถ๐˜๐—ถ๐—ป๐—ด ๐—Ÿ๐—ฎ๐—บ๐—ฏ๐—ฑ๐—ฎ

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!
Read 6 tweets
2 Nov
Thanks for all your interest in my AWS 1x1 threads! ๐Ÿ“š ๐Ÿ‘‹

The good news: ๐˜๐—ต๐—ฒ๐—ฟ๐—ฒ'๐˜€ ๐—ฎ ๐—น๐—ผ๐˜ ๐—บ๐—ผ๐—ฟ๐—ฒ ๐—ถ๐—ป ๐˜๐—ต๐—ฒ ๐—ฝ๐—ถ๐—ฝ๐—ฒ๐—น๐—ถ๐—ป๐—ฒ!
... also for Azure ๐Ÿ’™

Didn't see the previous ones yet?
๐—Ÿ๐—ถ๐—ป๐—ธ๐˜€ ๐˜๐—ผ ๐—ฎ๐—น๐—น ๐—บ๐˜† ๐—ฟ๐—ฒ๐—ฐ๐—ฒ๐—ป๐˜ ๐—ฝ๐—ผ๐˜€๐˜๐˜€ ๐—ฎ๐—ฟ๐—ฒ ๐—ฏ๐—ฒ๐—น๐—ผ๐˜„ โ†“
1๏ธโƒฃ ๐—›๐—ผ๐˜„ ๐˜๐—ผ ๐—ด๐—ฒ๐˜ ๐˜€๐˜๐—ฎ๐—ฟ๐˜๐—ฒ๐—ฑ ๐˜„๐—ถ๐˜๐—ต ๐—”๐—ช๐—ฆ

2๏ธโƒฃ ๐—ก๐—ผ๐˜ ๐—ณ๐—ฒ๐—ฎ๐—ฟ๐—ถ๐—ป๐—ด ๐—–๐—ผ๐˜€๐˜๐˜€ ๐—ผ๐—ณ ๐˜๐—ต๐—ฒ ๐—–๐—น๐—ผ๐˜‚๐—ฑ

Read 7 tweets
27 Oct
๐Ÿ“š AWS 1x1: ๐—ช๐—ต๐—ฎ๐˜ ๐—ฎ๐—ฟ๐—ฒ ๐—Ÿ๐—ฎ๐—บ๐—ฏ๐—ฑ๐—ฎ ๐˜๐—ฟ๐—ถ๐—ด๐—ด๐—ฒ๐—ฟ๐˜€?

For a function to execute, an event must occur.
Most know about API Gateway for REST services as an event source.

But a lot more AWS resources can trigger your Lambda โ†“
Almost anything that happens within your AWS account is an event.

โ€ข writing a record to DynamoDB
โ€ข uploading a file to S3
โ€ข queuing a message in SQS
โ€ข a viewer request to your CloudFront distribution

All of those events can be used to trigger a Lambda function.

{ 1/12 }
There are two different kinds of invocation types: ๐˜€๐˜†๐—ป๐—ฐ๐—ต๐—ฟ๐—ผ๐—ป๐—ผ๐˜‚๐˜€ & ๐—ฎ๐˜€๐˜†๐—ป๐—ฐ๐—ต๐—ฟ๐—ผ๐—ป๐—ผ๐˜‚๐˜€

Synchronous event sources need to wait for your Lambda function to return a response.
Asynchronous don't.

If invoking functions via the SDK, this can be specified!

{ 2/12 }
Read 14 tweets
26 Oct
๐Ÿ“š Cloud 1x1 - ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ๐—น๐—ฒ๐˜€๐˜€ ๐—”๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฎ๐—น ๐—ฃ๐—ฎ๐˜๐˜๐—ฒ๐—ฟ๐—ป๐˜€

You don't need to re-invent the wheel.
You can rely on field-tested patterns.

Let's explore some common ones โ†“
๐—ฃ๐—ฎ๐˜๐˜๐—ฒ๐—ฟ๐—ป ๐—ข๐˜ƒ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„

โ€ข 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).

{ 2/7 }
Read 11 tweets
25 Oct
๐—Ÿ๐—ฒ๐˜'๐˜€ ๐—ฏ๐—ฒ ๐—ต๐—ผ๐—ป๐—ฒ๐˜€๐˜: 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.
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(