What are serverless containers?
- Posted
- Tags
- serverless, architecture, kubernetes
A serverless container is your own container image, run by the cloud with no servers or cluster to manage. It lifts most of a function's limits (any language, longer runs, many requests per instance) while keeping some of the pay-for-use model. Serverless here means no servers to manage, not always scale to zero.
In my serverless functions post, I gave serverless containers one paragraph and called them the middle ground: what you reach for when the work doesn't fit a function's limits. I wrote that and moved on, but I couldn't actually say what sits in the middle, or how it's different from just running my own cluster.
The question I had
What is a serverless container, and when would I pick one over a function or my own Kubernetes?
What I found
The contract
With a function, you hand over a handler and the platform calls it. With a serverless container, you hand over a container image. The platform runs it, scales it, and sends traffic to it. You never see a server or a node.
The deal is simple: your container listens on a port for requests, or it runs a task and exits. Inside, it can be any language, any library, any binary. And it runs the same way on my laptop as it does in the cloud, which a function never quite does.
Two flavors that both get called serverless
This was the part that confused me. "Serverless containers" covers two different things.
- Request-driven, scales to zero: Google Cloud Run and Azure Container Apps. A request arrives, an instance starts if none is running, and when traffic stops, instances go away. This is the one that feels like functions.
- Serverless compute for an orchestrator: AWS Fargate, used under ECS or EKS. You stop managing the machines your containers run on, but you still tell it how many tasks to run. It doesn't start a task from zero when a request comes in.
So "serverless" here means no servers to manage. It doesn't always mean scale to zero or pay per request. Fargate is serverless in the sense that which machine a task lands on is not your problem.
Many requests per instance
The biggest difference from functions, for me. One Lambda environment handles one request at a time, so 100 requests at once means 100 environments. One Cloud Run instance can handle many requests at once (80 by default, up to 1000 at the time of writing).
That means:
- fewer instances for the same traffic
- fewer cold starts, since a running instance absorbs the next request
- fewer database connections, which was the big headache in the functions post. Each instance can keep a small connection pool instead of every request opening its own.
The catch is the same as any server: if your app isn't safe to run requests in parallel, or one request hogs the CPU, the others wait. Concurrency is a setting, and you can drop it to 1 if you need to.
How you pay
You pay for the CPU and memory your instances use, for as long as they run.
- Cloud Run can bill only while an instance is handling a request, or for the instance's whole lifetime if you want background work to keep running between requests.
- Fargate bills per second while the task is running, busy or idle.
Cold starts still exist
Starting from zero means pulling the image and starting the app. A big image or a slow framework makes that worse, and it shows up in the p99, not the average. The fixes are familiar:
- keep the image small
- make the app start fast
- set a minimum number of instances, which stay warm but bill while idle
That last one is the same tradeoff as provisioned concurrency for functions: you buy back latency by giving up some of the pay-for-use savings.
Services vs jobs
Most of these platforms run two kinds of work:
- Services: long-running, answer requests, scale with traffic. An API or a web app.
- Jobs: start, do a task, exit. A batch import, a database migration, a nightly report.
Jobs are where containers beat functions on time limits. A function is cut off at 15 minutes on Lambda. A job can run much longer.
Not the same as a Lambda container image
Lambda can also take a container image, which confused me at first. But there the image is just packaging. It's still a function: same 15 minute limit, one request per environment, same event model. A serverless container is a different runtime, not a different way to upload code.
Plugging it into the network I already have
Most of what I'd run this way isn't on its own. It has to talk to things I already have. So I pictured a common setup: a private network (a VPC) with a database that has no public IP, a load balancer in front of my other apps, and a VPN back to an office. Getting a serverless container into that comes down to a few questions.
Inbound: who can reach it? Cloud Run and Container Apps give you a public HTTPS URL out of the box. You can lock that down to internal traffic only, or put the service behind the load balancer you already have, so it gets your custom domain, firewall rules, and CDN like everything else. Fargate has no URL of its own. Its tasks sit in your subnets, and you put a load balancer in front of them like you would for any server.
Scaling to zero doesn't change any of this. The URL belongs to the platform's front door, not to an instance, so it keeps answering while nothing is running and the first request starts one. On Cloud Run, the IPs behind that URL are shared and can change, so never allowlist them. If someone needs a fixed IP to reach you, give them one from a load balancer in front.
Outbound: can it reach my private database? This was the key difference for me. A Fargate task lives inside your VPC. Each task gets its own private IP and its own security group, so it reaches the database the same way a server in that subnet would. Cloud Run runs outside your VPC, so it can't see private IPs until you turn on VPC egress, which sends its outbound traffic into your network. Container Apps sits in between: you deploy its environment into your own network when you create it.
A fixed outbound IP. Some partners and firewalls only let in IPs on a list. Serverless instances come and go, so they have no stable address. The fix is to send all outbound traffic through your VPC and out a NAT gateway with a reserved IP. That one IP is what goes on the list.
Reaching on-prem. No special serverless feature here. Once the outbound traffic goes through the VPC, it follows the same VPN or dedicated link the VPC already has, with the same routes and firewall rules.
One gotcha: if Fargate tasks sit in private subnets with no route to the internet, they can't pull their image or send logs. They need a NAT gateway or private endpoints for the image registry and the logging service.
| Need | Cloud Run | Fargate | Container Apps |
|---|---|---|---|
| Where it runs | Outside your VPC | Inside your VPC, one IP per task | In a network you can choose |
| Inbound | Public URL, can be internal only or behind your load balancer | Behind your load balancer | Public or internal ingress |
| Private resources | Turn on VPC egress | Direct, with security groups | Through its network |
| Fixed outbound IP | VPC egress plus NAT | NAT gateway | NAT through its network |
| Identity | Service account | Task role | Managed identity |
This is what the "fine control over networking" row in the table further down means. With your own cluster, you build all of this yourself. Here you mostly pick settings and identities, but you do have to know which ones.
Identity does more of the work than the network
The networking above decides what can reach the service. It doesn't decide who's allowed in. The older habit was to trust anything inside the private network. The direction now, often called zero trust, is to check identity on every call and treat the network as a second layer.
Serverless containers make this the easy path. Each one runs as its own identity: a service account on Cloud Run, a task role on ECS, a managed identity on Container Apps. The platform hands it short-lived credentials, so there are no keys sitting in environment variables.
- Calling another service: the caller sends a signed token, and the receiver checks that this caller is allowed. On Cloud Run, that check is built in. Finding the other service is the platform's job too: Container Apps in the same environment call each other by name, and on ECS, Service Connect does the same.
- Calling cloud services like storage or queues: the platform's access rules check the workload's identity, not its IP.
- Calling the database: Cloud SQL and RDS can accept the workload's identity instead of a password, and Azure databases can do the same through Microsoft Entra. Passwords are still common, though.
I'd still keep the database on a private IP. The network keeps it off the internet, and identity decides who gets in.
Under the hood, it's often Kubernetes
A lot of this is Kubernetes with the cluster hidden.
- Azure Container Apps runs on Kubernetes and uses KEDA to scale on events like queue length.
- Cloud Run follows the Knative API.
- Knative is the open source piece that gives you the same scale-to-zero services on your own cluster.
This connects to my Kubernetes post: you can get most of what Kubernetes offers for a web service without running a cluster yourself.
Side by side
| Functions | Serverless containers | Your own Kubernetes | |
|---|---|---|---|
| What you ship | A handler | A container image | Container images plus manifests |
| Time limits | Short (15 minutes on Lambda) | Long for services, longer for jobs | None |
| Requests per instance | One (on Lambda) | Many | Many |
| Scale to zero | Yes | Cloud Run, Container Apps: yes. Fargate: no | Only with add-ons like Knative or KEDA |
| Networking | Platform's by default, can attach to a VPC | Public URL or inside your VPC, depending on platform | You build it all |
| What you manage | Code | Image and a few settings | The cluster, nodes, upgrades, networking |
| Examples | Lambda, Cloud Functions | Cloud Run, Container Apps, Fargate | EKS, GKE, AKS, self-managed |
When it fits, when it doesn't
| Fits | Fits less |
|---|---|
| Web apps and APIs that already run in a container | Tiny event glue, where a function is simpler |
| Work that outgrows function limits | Many services that need fine control over networking and scheduling |
| Spiky traffic with a database behind it | Steady, heavy load, where reserved machines are cheaper |
| Teams that want containers without running a cluster | Workloads that need GPUs or special hardware the platform doesn't offer |
Takeaway
A serverless container is "bring your own container, skip the cluster." It's the middle ground I named without understanding: the flexibility of a container, with most of the hands-off feel of a function. The word serverless still hides two things, though. Check whether a platform actually scales to zero and bills per request, or just means you don't manage the machines.