There has been a constant comparison between Lambda and Fargate, two serverless computing engines from AWS, despite their fundamental differences. In this presentation, a comparison is explained between AWS Fargate and Lambda based on a number of variables with examples and use cases to assist you in selecting the best technology for your serverless application.
2. Agenda AWS Fargate: An overview
AWS Lambda: An overview
Fargate vs. Lambda: Development
Fargate vs. Lambda: Performance
Fargate vs. Lambda: Pricing
Fargate vs. Lambda: Operational compatibility
Fargate vs. Lambda: Scalability and maintenance
Fargate vs. Lambda: Security
Key characteristics and use cases of AWS Fargate
Key characteristics and use cases of AWS Lambda
3. AWS Fargate: An overview
Fargate is a serverless compute engine that allows you
to run containers without managing the infrastructure.
It complements ECS/EKS and makes launching
container-based applications much more effortless.
Therefore, you can focus on building your applications
while AWS does the heavy lifting of provisioning,
configuring, and scaling servers or clusters.
All you need to do is define the infrastructure
parameters, and Fargate will launch the containers for
you.
4. AWS Lambda: An overview
Lambda, an event-driven compute engine, is another
serverless technology from AWS.
It reduces the operational overhead of managing the
infrastructure with a pay-per-use model and no upfront
cost.
In addition, it enables you to run code in response to
events and automatically provisions for and manages the
compute resources required.
5. AWS Fargate vs. Lambda: Development
Developers can build locally using Docker and run the
container images directly in the cloud with Fargate.
It takes care of everything in-between.
Developing with Docker is quite popular as its features
can be used for easily managing multiple containers,
network configurations, resource requirements, etc., and
it has larger community support.
Recently, AWS and its community have developed
numerous tools to develop, create, and manage Lambda
functions seamlessly.
Earlier, developing with Lambda was a complex process
as it lacked a straightforward procedure to run Lambda
functions in the cloud, along with runtime restrictions.
Fargate: Lambda:
6. AWS Fargate vs. Lambda: Performance
Typically, the startup time for Fargate containers is 60-90
seconds which is more than Lambda.
However, Fargate has dedicated resources and no
runtime limitations, so the environment remains in a warm
state.
But it may take more startup time if there is a sudden
spike of requests, and it takes longer to scale up.
The initial Lambda startup takes 5 seconds, following
which the same functions have a negligible startup time.
But a Lambda function stops running after 15 minutes
until triggered by an event, causing cold starts.
However, there are multiple ways and techniques to
reduce and prevent Lambda cold starts that you can read
in our blog post on how to avoid Lambda cold starts.
Fargate: Lambda:
7. AWS Fargate vs. Lambda: Pricing
AWS Fargate pricing is calculated per second based on
the allocated memory, vCPUs, OSs, CPU infrastructure,
and storage resources used.
AWS Lambda pricing is calculated per millisecond based
on the number of requests, the memory and runtime used
by functions, and the network traffic.
Fargate: Lambda:
8. AWS Fargate vs. Lambda: Operational compatibility
It comes with additional complexity as you still have to
register your containers with ECS.
But it offers significantly more flexibility in that you have
full access to the configuration of each container.
It entirely abstracts the whole infrastructure layer, allowing
you to focus on your critical application functionalities.
But its operational flexibility is restricted as it limits
temporary disk space to 512MB and includes a 50MB
deployment package.
Fargate: Lambda:
9. AWS Fargate vs. Lambda: Scalability and maintenance
In the case of Fargate, you need to set up autoscaling.
Also, you need to shut down Fargate tasks on a manual
or scheduled basis as it cannot scale to 0, adding to
maintenance.
Moreover, in Fargate, the developers must keep the base
container images updated.
So it again adds to the maintenance but allows for more
control.
Lambda functions are scalable by design, so they
automatically launch instances to meet the increases in
demand.
Apart from rapid auto-scaling, it can also scale to 0. So,
you don’t have to pay for idle applications, which is useful
for low traffic workloads.
This ability of Lambda to scale from 0-1000 rapidly is
essential for spiky and unpredictable traffic.
Fargate: Lambda:
10. AWS Fargate vs. Lambda: Security
With Fargate, permissions are associated with containers
or pods the tasks are run in.
All Fargate tasks run in their individual, isolated compute
environments without sharing any underlying resources
(kernel, CPU/memory, Elastic Network Interface) with
other tasks.
With Lambda, you can set up IAM roles that each function
or service will assume.
AWS Identity and Access Management (IAM) modules
ensure that only the right users can access the function or
the application.
Moreover, functions have dedicated execution
environments that are never shared with other functions.
Fargate: Lambda:
11. Key characteristics
and use cases of
AWS Fargate
Deploys and scales applications easily, from single-use utility
applications to entirely containerized microservices
architectures.
Eliminates the operational overhead of choosing server types,
patching, sizing, cluster scheduling, optimizing cluster packing,
and more.
Allows you to pay only for what you use as Fargate’s fully
managed container environment automatically allocates the
required compute power-on-demand.
Integrates with a range of sibling AWS services for networking,
CI/CD, security, monitoring, etc.
Allows developers to have workload isolation.
Improves security with isolated compute environments.
12. When to use AWS
Fargate
Long-running compute jobs that are longer than 15 minutes
Applications that require more compute than Lambda offers, i.e.,
more than 3GB of memory
Applications with predictable scaling and where longer start
times are acceptable
Latency-sensitive and storage-intensive applications
Applications that need inter-container communication
Containerized machine learning applications
13. Key characteristics
and use cases of
AWS Lambda
Reduces costs because you only pay for the resources you use.
Scales automatically to handle a few requests per day or even
thousands of requests per second.
Reduces operational overhead such as administration,
maintenance, security patching, resizing, and adding servers for
any type of application or backend services.
Allows developers to spend more time on innovation with quicker
iterations.
Supports multiple programming languages.
Allows packaging and deploying of functions as container
images, expanding its use cases.
Easily integrates with other innovative AWS services.
14. When to use AWS
Lambda
Web applications and websites that require dynamic scaling to
handle excessive traffic loads at peak hours and save money
when there is no traffic.
For applications that can be easily expressed as single functions
with predictable usage of resources on each invocation.
Event-driven workloads and apps.
Custom mobile and IoT backends.
Asynchronous, small jobs to be managed in tandem.
File processing and automated file synchronization.
Real-time log analysis and data processing.
IT automation.