Alex Xu Profile picture
Co-Founder of ByteByteGo | Author of the bestselling book series: โ€˜System Design Interviewโ€™ | YouTube: https://t.co/9gPSJSrtPU

Mar 31, 2022, 8 tweets

๐’๐ž๐ซ๐ฏ๐ž๐ซ๐ฅ๐ž๐ฌ๐ฌ is one of the hottest topics in cloud services. How does AWS ๐‹๐š๐ฆ๐›๐๐š work behind the scenes?

Lambda is a ๐ฌ๐ž๐ซ๐ฏ๐ž๐ซ๐ฅ๐ž๐ฌ๐ฌ computing service provided by Amazon Web Services (AWS), which runs functions in response to events.

๐…๐ข๐ซ๐ž๐œ๐ซ๐š๐œ๐ค๐ž๐ซ ๐Œ๐ข๐œ๐ซ๐จ๐•๐Œ
Firecracker is the engine powering all of the Lambda functions [1]. It is a virtualization technology developed at Amazon and written in Rust.

The diagram below illustrates the isolation model for AWS Lambda Workers.

Lambda functions run within a sandbox, which provides a minimal Linux userland, some common libraries and utilities. It creates the Execution environment (worker) on EC2 instances.

How are lambdas initiated and invoked? There are two ways.

๐’๐ฒ๐ง๐œ๐ก๐ซ๐จ๐ง๐จ๐ฎ๐ฌ ๐ž๐ฑ๐ž๐œ๐ฎ๐ญ๐ข๐จ๐ง
Step1: "The Worker Manager communicates with a Placement Service which is responsible to place a workload on a location for the given host (itโ€™s provisioning the sandbox) and returns that to the Worker Manager" [2].

Step 2: "The Worker Manager can then call ๐˜๐˜ฏ๐˜ช๐˜ต to initialize the function for execution by downloading the Lambda package from S3 and setting up the Lambda runtime" [2]

Step 3: The Frontend Worker is now able to call ๐˜๐˜ฏ๐˜ท๐˜ฐ๐˜ฌ๐˜ฆ [2].

๐€๐ฌ๐ฒ๐ง๐œ๐ก๐ซ๐จ๐ง๐จ๐ฎ๐ฌ ๐ž๐ฑ๐ž๐œ๐ฎ๐ญ๐ข๐จ๐ง
Step 1: The Application Load Balancer forwards the invocation to an available Frontend which places the event onto an internal queue(SQS).

Step 2: There is "a set of pollers assigned to this internal queue which are responsible for polling it and moving the event onto a Frontend synchronously. After itโ€™s been placed onto the Frontend it follows the synchronous invocation call pattern which we covered earlier" [2].

Question: Can you think of any use cases for AWS Lambda?

Sources:
[1] AWS Lambda whitepaper: docs.aws.amazon.com/whitepapers/laโ€ฆ
[2] Behind the scenes, Lambda: bschaatsbergen.com/behind-the-sceโ€ฆ
Image source: [1] [2]

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling