Sub topic 14
Beyond the three: serverless and containers as a service
This chapter assumes you know the IaaS, PaaS, and SaaS split and the stack from hardware to application. Two newer models, containers as a service (CaaS) and serverless, sit between IaaS and PaaS and do not fit cleanly into the three classic boxes.
Containers as a service
A container is a package that holds your application and its dependencies, and it runs as an isolated process on a shared operating system kernel. CaaS is a managed service that runs and orchestrates those containers for you.
You supply a container image and a description of how many copies to run. The provider handles scheduling, restarts, and networking. Depending on the option, you may also manage the machines the containers run on.
- You manage: the image, its contents, and the scaling settings.
- The provider manages: the orchestration layer and, in the fully managed form, the hosts.
Examples on AWS are Amazon ECS and Amazon EKS. Both can run on EC2 instances that you manage, or on AWS Fargate, where AWS manages the hosts.
Serverless (functions as a service)
Serverless means you do not provision or manage servers. Servers still exist, but the provider runs them. In functions as a service (FaaS), you upload a small function and the provider runs it when an event arrives, such as an HTTP request or a file upload.
Three traits set it apart from a typical PaaS:
- It scales to zero. With no requests, nothing runs.
- It scales per event, and the platform adds capacity automatically.
- It bills per invocation and run time, not for idle servers.
Here is a complete AWS Lambda function in Python:
import json
def lambda_handler(event, context):
name = event.get("name", "world")
return {
"statusCode": 200,
"body": json.dumps({"message": f"Hello, {name}"}),
}Compare it with the Flask app from the PaaS chapter. The Flask app is a long-running process that the platform keeps alive. This function exists only while it handles an event.
Where they sit on the stack
The order is a rough guide, not a strict ladder. Serverless and PaaS overlap, and CaaS on Fargate is close to PaaS in effort.
Trade-offs
| Aspect | CaaS | Serverless (FaaS) |
|---|---|---|
| Unit you deploy | Container image | Function |
| Runtime control | High: any language or library in the image | Limited to supported runtimes or custom images |
| Idle cost | Pay for running containers | None when idle |
| Run time limits | None for long-running services | Execution time caps per invocation |
| Portability | Container images move between providers | Function code and event wiring are provider-specific |
Common errors to watch for:
- Cold starts. The first request after idle time can be slower because the platform must start a new execution environment.
- Assuming state persists. A function instance can disappear at any time, so store data in a database or object store.
- Using serverless for steady, heavy load. Per-invocation pricing can cost more than a continuously running container.
Exercise
A team runs a service that needs a custom native library, runs for several hours per job, and receives steady traffic all day. Would you pick CaaS or serverless functions, and why?
Show answer
CaaS. The custom library fits in a container image, long-running jobs avoid function time limits, and steady traffic removes the idle-cost benefit of serverless.