SERVERLESS & CONTAINERS

SERVERLESS & CONTAINERS

When building scalable architecture, containers and serverless are approaches that often come to mind.

This section provides a decision framework that helps you decide when to use which tool. The following schema is a synthesis.

Decision flow for scalable architecture

The stated information below should work as general guidance for making decisions between different approaches. We know that every startup has their own proclivity towards technologies as well as constraints. Feel free to adapt the framework to your needs and share it with us by contributing.

AWS Lambda

When to leverage AWS Lambda
When you need …When you want …
– To trigger action on an event– Focus on business logic and not IT operations
– Support for varying utilization– Enable simplified IT automation
– Ability to handle unknown demand– Enable real-time data processing or serverless backend
– Lighter-weight, application-focused computing– Hand operational complexity (patching, scaling, fault tolerance) to AWS
– hostingreal-time ML inference

NEW: You can now deploy your Lambda functions as container images (up to 10 GB in size). This makes it easier for you to build Lambda functions that rely on sizable dependencies, such as machine learning or data intensive workloads. Get started with Lambda Container Image Support

NEW: Lambda now supports up to 10 GB of RAM, which gives your functions access to up to 6 vCPUs. Multithreaded and multiprocess applications run faster, offsetting the additional costs for using more memory through lower duration. Check out an example here and the Lambda Power Tuning tool.

Common Lambda application types and use cases
  • File processing – Suppose you have a photo sharing application. People use your application to upload photos, and the application stores these user photos in an Amazon S3 bucket. Then, your application creates a thumbnail version of each user’s photos and displays them on the user’s profile page. In this scenario, you may choose to create a Lambda function that creates a thumbnail automatically. Amazon S3 is one of the supported AWS event sources that can publish object-created events and invoke your Lambda function. Your Lambda function code can read the photo object from the S3 bucket, create a thumbnail version, and then save it in another S3 bucket. See a Serverless Reference Architecture for Real-Time File Processing
  • Data and analytics – Suppose you are building an analytics application and storing raw data in a DynamoDB table. When you write, update, or delete items in a table, DynamoDB streams can publish item update events to a stream associated with the table. In this case, the event data provides the item key, event name (such as insert, update, and delete), and other relevant details. You can write a Lambda function to generate custom metrics by aggregating raw data. See a tutorial here.
  • Websites – Suppose you are creating a website and you want to host the backend logic on Lambda. You can invoke your Lambda function over HTTP using Amazon API Gateway as the HTTP endpoint. Now, your web client can invoke the API, and then API Gateway can route the request to Lambda. See Build a Serverless Web Application.
  • Mobile applications – Suppose you have a custom mobile application that produces events. You can create a Lambda function to process events published by your custom application. For example, in this scenario you can configure a Lambda function to process the clicks within your custom mobile application.
  • Scheduled, Cron, Periodical Jobs – In order to achieve scheduled jobs, we can leverage on CloudWatch events, which support cron-like expressions that can be used to trigger a Lambda function periodically. You can also schedule lambda functions using Amazon Eventbridge.
  • Batch Processing – When you want to reduce spikes in a monolith, AWS Lambda is often a great means to help you better size your monolith. Please look at the “Breaking Monolith” section and check out this tutorial here.
  • Real-time ML inference (pay as you go model) – AWS Lambda can mount Amazon Elastic File System to access large ML models and still benefit from the pay as you go model of Lambda. For an exmple, see Pay as you go machine learning inference.

Further resources:

Containers

When to leverage EC2-backed containers
When you need …When you want …
– Support for long-running compute jobs (> 15 minutes)– complete control of compute environment (but not just for the sake of control)
– Predictable, high traffic usage– Hybrid scenarios or on-premises portability
– Lower runtime startup latency (sub-second)– Container image portability with Docker runtime
– Application with a non-HTTP/S listener– Ability to purchase through different billing models (On-Demand, RI, Spot)
– Agent/daemon/sidecar to run alongside your service
– Specialized hardware (GPUs, etc.) or kernel tuning support
– Support for Windows containers or legacy .NET
When to leverage containers with AWS Fargate
When you need …When you want …
– Support for long-running compute jobs (> 15 minutes)– Managed serverless container environment
– More compute than Lambda offers (>3 GB memory)– Container image portability with Docker runtime
– Application with a non-HTTP/S listener– Ability to purchase through different billing models (On-Demand, Spot with Fargate Capacity Providers )
– Run sidecars with your service (agents only supported as sidecars)
– Predictable scaling OR longer start times are acceptable
– Specialized hardware (GPUs, etc.) or kernel tuning support
– Support for Windows containers or legacy .NET
Deciding between ECS and EKS

AWS sees customers successfully utilizing Amazon EKS for their businesses. If you are deciding between Amazon ECS and Amazon EKS there are at least the following points to consider:

  • Does your team already have engineers with Kubernetes experience or can hire the expertise? Amazon EKS is a managed version of Kubernetes. Your team still needs to know how to operate Kubernetes properly.
  • Different to Amazon ECS, EKS charges for each Amazon EKS cluster’s control plane.

So if your goal is to just run containers and has no prior experience to the Kubernetes orchestration system, consider using Amazon EKS.

Common container application types and use cases
  • Running Microservices – Suppose you are building your backend application logic. You will find that there are different tasks for different parts of the systems. Splitting these up in different microservices will enable you to develop and scale all the different services indepently to your demands and needs. Additionally, you can choose “the right tool for the job” (programming languages, databases) for each of the different tasks. Containers are optimal for running small, decoupled services. ECS Reference Architecture on AWS Samples Github repository.
  • Batch Processing – The typically short-lived and parallel nature of batch jobs make it a great use case for containers. Packaged into a Docker image it can be deployed anywhere, especially in an Amazon ECS task. Checkout the Reference Architecture for ECS Batch Processing. You may also want to consider AWS Batch, a service that dynamically provisions the optimal quantity and type of compute resources based on the volume and specific resource requirements of the batch jobs submitted. It supports running Docker containers.
  • Machine Learning – As ECS and EKS running in EC2-backed version can make use of specialized hardware such as GPUs, containers can be utilized for Machine Learning and Deep Learning tasks that only run for the amount of time needed to complete training or inference tasks. See: Tutorial for Deep Learning with Amazon ECS

Further resources:

Helping you get started

To help you build serverless and containerized application we recommend having a look at the resources below.

AWS Solution Constructs are vetted architecture patterns, available as an open-source extension of the AWS Cloud Development Kit (CDK), that can be easily assembled declaratively to create a production-ready workload. You can find patterns such as:

  • Lambda to SQS,
  • Kinesis Streams to Lambda,
  • Lambda to S3 or DynamoDB.

The AWS CDK Examples on Github feature a variety of CDK examples for common container-based patterns and can help you get started faster. Examples:

  • Provision an ECS Cluster with custom Autoscaling Group configuration,
  • Starting a container fronted by an application load balancer on Fargate with an EFS Mount.
Techmandra Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *