Sub topic 14
Beyond the Three: Serverless and Containers as a Service
This chapter assumes you know the IaaS, PaaS, and SaaS split from the earlier chapters. You should also know what a container image is and what an HTTP request is. It covers two models that sit between the classic three, and it shows how to place any service on the stack.
Why Three Models Are Not Enough
IaaS, PaaS, and SaaS describe who manages which layer. The model was drawn when the choice was mostly "rent a virtual machine" or "use a finished product". Two later patterns do not fit cleanly:
- Containers as a Service (CaaS) is a managed service that runs your container images. You do not manage the machines underneath.
- Serverless is a family of services where you supply code or configuration and the provider handles servers, scaling, and idle capacity. Function as a Service (FaaS) is the best-known kind.
Both sit between IaaS and PaaS. Serverless goes further toward the provider than most PaaS does. Neither is a replacement for the three models. They are extra positions on the same line of "how much do I manage".
The order is approximate. A given PaaS may hide more than a given CaaS, so treat the line as a guide.
Containers as a Service
A container packages your application with its libraries and a minimal filesystem. Running containers yourself on IaaS means you still manage virtual machines. You patch their operating systems, size the cluster, and decide where each container is placed.
CaaS removes the machine layer. You give the provider an image, a CPU and memory size, and networking settings. The provider finds capacity, starts the container, restarts it on failure, and bills for the resources the container uses. Examples are AWS Fargate (used with Amazon ECS or EKS), Google Cloud Run, and Azure Container Apps.
Here is a small image definition. The image holds the Flask app from earlier in this tutorial's examples, saved as app.py:
FROM python:3.12-slim
WORKDIR /app
RUN pip install --no-cache-dir flask gunicorn
COPY app.py .
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:application"]After you push the image to a registry and register a task definition, a single command starts it on Fargate. The cluster name, task definition, subnet, and security group below are placeholders:
aws ecs run-task \
--cluster my-cluster \
--launch-type FARGATE \
--task-definition my-app:1 \
--network-configuration "awsvpcConfiguration={subnets=[subnet-0123456789abcdef0],securityGroups=[sg-0123456789abcdef0],assignPublicIp=ENABLED}"Compare this with the earlier IaaS example. No instance type, AMI, or operating system appears. You still choose the runtime, because you built the image.
What you keep with CaaS
- The container image, including its base image and the packages in it. A vulnerable library in your image is your problem.
- Application configuration, secrets, and the identity (IAM role) the container runs with.
- Networking rules such as which ports are open and which security groups apply.
- Scaling rules, in most services. You say how many copies to run or what triggers more.
What the provider takes
- Host operating system patching and hardware replacement.
- Placing containers onto physical capacity.
- Isolating your containers from other customers' containers.
Serverless and Function as a Service
"Serverless" does not mean no servers. It means you do not provision, size, or patch them, and you do not pay while your code is idle. Serverless services share these traits:
- Event-driven. Code runs in response to an event such as an HTTP request, a file upload, a queue message, or a timer.
- Automatic scaling. The provider starts as many copies as the event load needs, including zero when nothing happens.
- Pay per use. Billing counts requests and execution time, not hours of reserved capacity.
FaaS is the compute part. You write a function, and the platform runs it per event. AWS Lambda, Google Cloud Functions, and Azure Functions are examples. The wider serverless idea includes managed backends that follow the same rules, such as object storage (Amazon S3), queues (Amazon SQS), and key-value databases (Amazon DynamoDB).
This Lambda function handles an HTTP request forwarded by an API gateway. Save it as app.py:
import json
def handler(event, context):
params = event.get("queryStringParameters") or {}
name = params.get("name", "world")
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": json.dumps({"message": f"Hello, {name}"}),
}Package and create it. The role ARN is a placeholder for an existing execution role:
zip function.zip app.py
aws lambda create-function \
--function-name hello \
--runtime python3.12 \
--handler app.handler \
--role arn:aws:iam::123456789012:role/my-lambda-role \
--zip-file fileb://function.zipYou wrote no server loop, no web framework, and no port number. The platform supplies the runtime and the entry point, and it calls handler once per event.
Where They Fit in the Shared Responsibility Model
| Layer | IaaS | CaaS | PaaS | FaaS | SaaS |
|---|---|---|---|---|---|
| Physical hardware and data center | Provider | Provider | Provider | Provider | Provider |
| Host operating system | You | Provider | Provider | Provider | Provider |
| Container image and base OS packages | You | You | Provider | Provider | Provider |
| Language runtime | You | You (in image) | Provider | Provider | Provider |
| Application code | You | You | You | You (functions) | Provider |
| Identity, access rules, and data | You | You | You | You | You (your data and users) |
The last row never moves fully to the provider. Even in SaaS you decide who has accounts and what data you put in. In the other models you also write the access policies, so a mistake there is yours.
Edge Cases and Failure Modes
These are the behaviors that surprise people who treat serverless or CaaS as "PaaS but cheaper".
Cold starts
When a function has had no recent traffic, the next event may need a new execution environment. The platform loads the code and starts the runtime first, which adds latency. The delay depends on the runtime, package size, and initialization work. Services offer mitigations such as keeping a minimum number of warm instances, usually at extra cost. Latency-sensitive paths need a test with realistic idle gaps.
Execution limits
FaaS caps run time per invocation. Lambda's maximum is 15 minutes, for example. Memory, payload size, and concurrency also have limits. Long batch jobs, large file processing, and persistent connections often belong in CaaS or IaaS.
Statelessness
A function instance can be created or discarded at any time. Do not keep needed data in memory or on local disk between invocations. Store state in a database, a cache, or object storage. The same rule applies to CaaS containers, which can be restarted on a different host.
Cost at steady load
Pay-per-use is cheap when traffic is bursty or low. When a function runs continuously at high load, per-millisecond billing can exceed the cost of a reserved container or virtual machine doing the same work. Estimate cost at your expected request volume before choosing.
Lock-in and portability
Container images run on any container platform, so CaaS has the lowest switching cost of the models in this chapter. Function code is often portable, but the trigger wiring, event shapes, permissions, and the managed services around it are provider-specific. Moving a serverless application usually means rewriting its integrations.
Debugging and observability
You cannot log in to a host. You depend on logs, metrics, and traces that the provider exposes. Plan for structured logging and request tracing from the start.
Choosing Among the Options
Use these questions in order:
- Is the work event-driven, short, and bursty? Choose FaaS. Examples are image thumbnails after upload, webhook handlers, and scheduled cleanup.
- Do you already have a container image, or need a custom runtime or system libraries? Choose CaaS.
- Is it a long-running web service with steady traffic and a standard language runtime? PaaS or CaaS fits, depending on how much runtime control you need.
- Do you need OS-level control, special drivers, or software that does not containerize? Choose IaaS.
- Does a finished product already meet the need? Choose SaaS.
Exercise
A team runs an image-resizing job that fires when a photo is uploaded. Uploads arrive in bursts, with long quiet periods overnight. Each resize takes about 2 seconds. Which model fits best, and what is one risk to test before launch?
Show answer
FaaS (serverless) fits best: the work is event-driven, short, bursty, and idle for long periods, so scaling to zero and per-use billing save money. One risk is cold-start latency after quiet periods, which may delay the first resizes after idle time. Other acceptable risks are execution time or payload limits, or cost at high volume.
Exercise
Your application needs a native system library that is not available in your PaaS runtime, but you do not want to manage virtual machines. Which model do you choose, and which layer do you now own that you did not on PaaS?
Show answer
Containers as a Service. You package the library and the application in a container image and the provider runs it without you managing hosts. You now own the container image, including the base operating system packages and the language runtime inside it.