๐๐๐ซ๐ฏ๐๐ซ๐ฅ๐๐ฌ๐ฌ 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?
๐นHTTP 1.0 was finalized and fully documented in 1996. Every request to the same server requires a separate TCP connection.
๐นHTTP 1.1 was published in 1997. A TCP connection can be left open for reuse (persistent connection), but it doesnโt solve the HOL (head-of-line) blocking issue.
HOL blocking - when the number of allowed parallel requests in the browser is used up, subsequent requests need to wait for the former ones to complete.
How to scale a website to support millions of users? We will explain this step-by-step.
The diagram below illustrates the evolution of a simplified eCommerce website. It goes from a monolithic design on one single server, to a service-oriented/microservice architecture.
Suppose we have two services: inventory service (handles product descriptions and inventory management) and user service (handles user information, registration, login, etc.).
Step 1 - With the growth of the user base, one single application server cannot handle the traffic anymore. We put the application server and the database server into two separate servers.
Some ๐๐๐ฏ๐๐ฉ๐ฌ books I find enlightening:
๐นAccelerate - presents both the findings and the science behind measuring software delivery performance.
๐นContinuous Delivery - introduces automated architecture management and data migration.
๐นSite Reliability Engineering - famous Google SRE book. It explains the whole life cycle of Googleโs development, deployment, and monitoring, and how to manage the worldโs biggest software systems.
๐นEffective DevOps - provides effective ways to improve team coordination.
๐นThe Phoenix Project - a classic novel about effectiveness and communications. IT work is like manufacturing plant work, and a system must be established to streamline the workflow. Very interesting read!
Kafka achieves low latency message delivery through Sequential I/O and Zero Copy Principle. The same techniques are commonly used in many other messaging/streaming platforms.
The diagram below illustrates how the data is transmitted between producer and consumer, and what zero-copy means.
๐นStep 1.1 - 1.3: Producer writes data to the disk
๐นStep 2: Consumer reads data without zero-copy
2.1: The data is loaded from disk to OS cache
2.2 The data is copied from OS cache to Kafka application 2.3 Kafka application copies the data into the socket buffer 2.4 The data is copied from socket buffer to network card 2.5 The network card sends data out to the consumer
One picture is worth more than a thousand words. In this post, we will take a look at what happens when Alice sends an email to Bob.1/4
1. Alice logs in to her Outlook client, composes an email, and presses โsendโ. The email is sent to the Outlook mail server. The communication protocol between the Outlook client and mail server is SMTP.2/4
2. Outlook mail server queries the DNS (not shown in the diagram) to find the address of the recipientโs SMTP server. In this case, it is Gmailโs SMTP server. Next, it transfers the email to the Gmail mail server. The communication protocol between the mail servers is SMTP.3/4
Caching is awesome but it doesnโt come without a cost, just like many things in life.
One of the issues is cache miss attack. Correct me if this is not the right term. It refers to the scenario where data to fetch doesn't exist in the database and the data isnโt cached either.
So every request hits the database eventually, defeating the purpose of using a cache. If a malicious user initiates lots of queries with such keys, the database can easily be overloaded.
The diagram below illustrates the process.
Two approaches are commonly used to solve this problem:
๐นCache keys with null value. Set a short TTL (Time to Live) for keys with null value.