AJ Stuyvenberg Profile picture
Mar 3 β€’ 6 tweets β€’ 2 min read
Which would you expect would be faster, SNS directly invoking a Lambda function? Or SNS to SQS to a Lambda function?

Here's a fun thread documenting what I've learned!
πŸ§΅πŸ‘‡
#Serverless
In a totally unscientific test (N=3), I’ve observed SNS messages delivered directly to Lambda functions are slower than an SNS message sent to SQS, then delivered to Lambda.

Check out the following trace:
Here, the SNS message is published from the initial lambda function (purple spans). You then see the fan-out, with the yellow span indicating the time for SNS to invoke my function, and the two blue spans representing the time for SNS to SQS and then invoking my function.
The consuming functions are identical clones, and the init duration was within ~10ms for both functions, but the start times of both functions are separated by 75ms (average over 3 tests).
In this case, it’s about a 40ms difference.
@dougmoscrop helpfully pointed out that this could be explained by the fact that SNS triggers Lambda functions using an (asynchronous) Event invocation method, whereas SQS utilizes the Request/Response (synchronous) method.

This seems plausible!
Either way, it was a fun tidbit to learn, and it didn't quite fit the format of a blog post - so I hope you enjoyed this instead!

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with AJ Stuyvenberg

AJ Stuyvenberg 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 @astuyve

Sep 14, 2021
@fitzsimons_dev @dynamodb Oh! You're one of today's lucky 10,000!

DynamoDB streams are GREAT! I use them in almost every place I use a DDB table with #Serverless. I suggest doing non-essential work via stream vs in one long function call, so the end user gets the fastest experience possible.

Here's a 🧡
@fitzsimons_dev @dynamodb 1. Sending a confirmation email after a user registers.

This is an important function, but users shouldn't have to wait for my API to call an email provider before getting a response from the backend. Stream it to another function!
@fitzsimons_dev @dynamodb 2. Stateful/synchronizing needs! Lambda functions are a distributed system, no way around that (unless you set function concurrency to 1, but I digress). So you need to build idempotency into your app.

Example πŸ‘‡
Read 15 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

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(