AI Agent Scaling: Kubernetes vs Serverless
I spent the better part of 2025 watching teams make the same mistake with AI agents. They pick a compute platform based on what's trendy, not on what their agents actually need. Then they burn six figures discovering the difference. That's expensive. Let me save you the tuition.
The question of ai agent scaling kubernetes vs serverless isn't about which platform is "better." It's about understanding what your agents do when they fail, how they hold state, and whether your traffic looks like a steady river or a flash flood.
I'm Nishaant Dixit. I run SIVARO, where we build production AI systems. We've deployed agents for logistics companies, financial services, and healthcare firms. We've hit every wall you can imagine. Here's what we learned.
What We're Actually Debating
First, let's ground this. An AI agent in production is not a single model call. It's a loop: perceive, reason, act, observe. That loop makes HTTP calls to LLMs, executes tools, reads databases, and sometimes spawns sub-agents. Each of those steps has different infrastructure needs.
The Anthropic engineering team makes a useful distinction: workflows are predictable, agents are dynamic. That's not academic. It's the crux of your scaling decision.
Workflows can be scaled like traditional web services. Agents cannot, because you don't know what they'll do next. An agent might make 3 tool calls or 30. It might finish in 2 seconds or 20 minutes.
Most people think this is a compute problem. It's not.
It's a state and lifecycle problem.
The Real Problem: Inflight State
Here's what nobody tells you before you build an agent platform: your agent's execution context lives somewhere. When that agent runs on a server, the server holds its memory, its intermediate steps, its tool call results. If that server dies, your agent loses its mind. Literally.
This is where ai agent scaling kubernetes vs serverless gets real.
Let me give you a concrete example. In late 2025, we built a claims processing agent for a mid-sized insurer. The agent retrieves policy documents, checks them against claim submissions, and occasionally asks the user for clarification. Each run takes 3-8 minutes. Each run holds about 4MB of context in memory.
We started on serverless. The cold starts were horrifying. Every time the function spun up, it had to re-initialize the document index, re-warm the model connections, and re-establish state. We saw p95 latencies of 40 seconds. Our users thought the system was broken.
So we moved to Kubernetes. Stable connections, warm pools, predictable performance. But then the agent hit a burst of 200 concurrent runs. Our three pods couldn't handle it. As we scaled up, each new pod needed two minutes to join the pool. By the time it was ready, the burst was over.
We were caught between latency and elasticity.
Here's a simplified view of the classic Kubernetes deployment pattern:
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: agent-worker
spec:
replicas: 5
selector:
matchLabels:
app: agent-worker
template:
metadata:
labels:
app: agent-worker
spec:
containers:
- name: agent
image: sivaro/agent-runner:2.4.1
resources:
requests:
memory: "2Gi"
cpu: "500m"
limits:
memory: "4Gi"
cpu: "2"
env:
- name: AGENT_STATE_STORE
value: "redis://state-store:6379"
This works for steady loads. It doesn't work for spiky ones. The Google research team's work on agentic infrastructure highlights checkpointing and state hydration as core hurdles. They're right. The moment your platform can't restore an agent to its exact prior state on a different node, you've broken the system.
Serverless: The Other Side of the Coin
Serverless platforms shine for bursty, short-lived workloads. A function that runs for 500ms and returns a result? Perfect for serverless. An agent that runs for 10 minutes and makes 25 API calls? That's torture.
The cold start problem doesn't go away. Every time your function spins down, your agent's state evaporates. You have to persist it externally. That adds latency to every single step of the agent loop.
But there's a deeper issue: cost control.
Serverless billing is per-invocation. An agent might invoke your platform 50 times per user request. Each invocation is billed separately. Multiply that by 10,000 users, and you're paying for 500,000 function executions. Most of those are memory-holding operations that do almost nothing.
Here's what we found at SIVARO when we ran a cost analysis in Q1 2026: the same agent workload cost 3.7x more on a major serverless platform than on Kubernetes, once we accounted for state storage, re-initialization, and per-invocation charges. The per-request compute was similar. The overhead ate us alive.
That said, there's a place for serverless. It's the perfect front door.
We run a hybrid architecture now. Serverless functions handle ingestion, authentication, and request validation. They're stateless, fast, and bursty. The actual agent execution runs on Kubernetes with persistent connections and warm state.
Here's the pattern:
python
# Serverless function: entry point
def handle_request(event, context):
agent_id = event['agent_id']
payload = event['payload']
# Validate and enrich
validated = validate_request(payload)
# Enqueue to agent executor
response = enqueue_to_executor(agent_id, validated)
return {
'statusCode': 202,
'body': {'accepted': True, 'agent_id': agent_id}
}
The serverless layer scales instantly. The Kubernetes layer scales intelligently. Each does what it does best.
The Orchestration Problem
Here's where most architectures fall apart. Your agent is running on a Kubernetes cluster. It needs to call a tool that lives in a serverless function. Or it's a serverless agent that needs to connect to a long-running model server.
Agent orchestration is its own infrastructure layer. It's not just about compute. It's about routing, retries, and state synchronization.
The Blaxel team's guide on deploying AI agents makes a point I agree with: your orchestration layer needs to be separate from your execution layer. Don't embed orchestration logic in your agent code. Don't embed it in your compute platform.
We've standardized on this pattern at SIVARO:
typescript
// Orchestration layer: routes agent steps
const orchestrator = new AgentOrchestrator({
stateStore: new RedisStateStore(redisClient),
executor: new KubernetesExecutor({
namespace: 'agent-ns',
image: 'sivaro/agent-runner:2.4.1'
}),
tools: {
paymentGateway: new ServerlessTool('payment-gateway-fn'),
documentStore: new GRPCTool('doc-store.internal:8080'),
searchIndex: new GRPCTool('search-idx.internal:9090')
},
retryPolicy: {
maxRetries: 3,
backoff: 'exponential',
maxDelayMs: 5000
}
});
Your orchestrator survives platform changes. Your agent doesn't care what it's running on. That abstraction is worth the engineering cost.
This aligns with the practical guide from arXiv on agentic AI systems that emphasizes separating the agent loop from the execution environment. The agent is a policy. The environment is a detail.
Cost Optimization: The Eternal Struggle
Let's talk about ai agent cost optimization at scale because this is where the rubber meets the road.
Everyone starts with token costs. They're the most visible number. But they're rarely the biggest cost. Here's what our cost breakdown looked like for a production agent platform in early 2026:
Compute: 34% of total cost
Inference (LLM calls): 28%
State storage: 15%
Data transfer and API calls: 12%
Observability and monitoring: 11%
Interesting, right? Compute and inference are nearly equal. And state storage is a line item you can't ignore.
Most teams optimize token usage. They use smaller models, cached prefixes, and smart prompting. But they ignore the compute inefficiency baked into their scaling strategy.
On Kubernetes, we saw 31% average CPU utilization across our agent fleet. That's wasted money. But when we autoscaled down, we hit latency spikes because pods took too long to warm up.
The solution wasn't a better autoscaler. It was a split-pool strategy:
yaml
# Kubernetes autoscaling config
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: agent-worker-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: agent-worker
minReplicas: 4
maxReplicas: 20
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 25
periodSeconds: 60
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Pods
value: 4
periodSeconds: 30
Three pods stay warm always. They handle the baseline. When traffic spikes, we scale up aggressively. When traffic drops, we bleed off slowly. It's not perfect. It's honest.
The Towards Data Science piece on workflows vs agents touches on this: your scaling strategy depends on whether your agent is interactive or asynchronous. Interactive agents need low latency and steady state. Async agents can tolerate cold starts and bursty handling.
Match your platform to your agent type. Don't force one pattern on everything.
Failure Modes: What Actually Breaks
We've done enough ai agent deployment failure case studies to see the patterns. Let me share the ones that matter.
Failure 1: The State Memory Leak
An agent that runs for 30 minutes accumulates context. That context lives in memory. On Kubernetes, that means the pod grows. If you don't set limits, it crashes the node. We saw this in a financial analysis agent. After 20 minutes of running, it ballooned to 8.5GB of memory. The pod OOM-killed, and the agent had to restart from checkpoint. The user watched a progress spinner for 15 minutes.
Failure 2: The Retry Storm
One agent hits an API error. It retries. The retry fails. It retries harder. Meanwhile, a hundred agents do the same thing. Your infrastructure gets overwhelmed by exponential backoff. We measured a 40x amplification at one client. One stuck agent generated 40 requests per second to a downstream service.
Failure 3: The Cold Start Chain
On serverless, each step of the agent loop can trigger a cold start. The full loop takes 10x longer than expected. The user gives up. But the agent keeps running. Now you have zombie agents consuming resources and generating cost.
The Business Plus AI analysis of agent failures points at a common root cause: agents fail invisibly. They don't crash loudly. They hang quietly. Your infrastructure needs to detect a hung agent and kill it before it becomes a cost leak.
Here's a health check pattern we use:
go
// Health checker for agent executors
func checkAgentHealth(ctx context.Context, agentID string) error {
timeout := 30 * time.Second
done := make(chan struct{})
go func() {
// Send heartbeat to agent loop
agentClient.Heartbeat(ctx, agentID)
close(done)
}()
select {
case <-done:
return nil
case <-time.After(timeout):
// Kill the agent, persist checkpoint
orchestrator.KillAgent(agentID, "health-check-timeout")
return fmt.Errorf("agent %s failed heartbeat", agentID)
}
}
This has saved us more times than I can count. A hung agent is worse than a dead one.
The Middle Ground: Event-Driven Kubernetes
After two years of running hybrid architectures, I've stopped believing in the binary choice. The answer for ai agent scaling kubernetes vs serverless is a synthesis: event-driven Kubernetes.
Here's the architecture we've standardized on for new deployments:
- Serverless front door for requests, auth, and validation
- Event bus (Kafka or similar) for agent lifecycle events
- Kubernetes workers that pull events and execute agent steps
- Redis for state storage with checkpointing
- Vector database for semantic memory
The key insight: your workers shouldn't hold state in memory. They should load it from Redis, do a step, save it back, and release the pod. This makes Kubernetes workers as disposable as serverless functions, but with warm pools and persistent connections.
This is the real ai agent scaling kubernetes vs serverless resolution. You get the elasticity of serverless and the reliability of Kubernetes. But it requires disciplined engineering. You have to design your agent to be stateless between steps.
Not every agent can do this. If your agent needs a long-lived context window that you can't serialize quickly, you're stuck with persistent pods. But if you design for checkpointing from day one, the benefits are enormous:
- Cold start time: 40 seconds → 200ms
- Horizontal scaling: minutes → seconds
- Cost: drops by 60-70% versus serverless
- Failure recovery: restart from last checkpoint, not from the beginning
What to Actually Build
Let me give you a decision framework. Not a checklist, a framework for judgment.
Choose serverless for:
- Short-lived agents (< 30 seconds per run)
- Stateless steps
- Bursty, unpredictable traffic
- Prototypes and MVPs
Choose Kubernetes for:
- Long-running agents (minutes to hours)
- Stateful execution
- Predictable background traffic
- Cost-sensitive workloads
Choose hybrid for:
- Production systems with real users
- Mixed workloads (some stateless, some stateful)
- Any architecture where you expect to scale 10x+
The Machine Learning Mastery architecture guide covers some of this territory. I disagree with their suggestion that you can standardize on one platform. You can't. Not in production.
We ran a pure Kubernetes deployment for 8 months. It worked until it didn't. A burst of traffic from a viral demo hit our cluster, and we couldn't scale fast enough. The outage lasted 47 minutes. We lost a client.
We ran a pure serverless deployment for 3 months. The cost was 3.2x budget. And the latency made the product unusable. Users complained we were slower than the old manual process.
The hybrid isn't elegant. It's necessary.
Operational Maturity: The Real Deciding Factor
Forget the technology for a second. The real question is: can your team operate this?
Kubernetes is a full-time job. You need someone who understands nodes, pods, autoscaling, networking, and security. That person costs 200K a year plus equity. Most startups don't have them.
Serverless is easier to operate. The platform handles the hard parts. But you lose control. And when things go wrong, you're debugging in a black box. That's its own tax.
We're seeing teams at major companies like Stripe and Datadog move toward a middle layer: managed Kubernetes with platform automation. The control of K8s with the simplicity of serverless. But that's still a cost center.
The Google research piece on agentic infrastructure is blunt about this: operational burden is one of the key hurdles. They suggest that most failures aren't technical. They're operational. Teams pick a platform they can't operate, then blame the platform.
Start with what your team can handle. Then evolve.
Looking Forward: What Changes in 2026 and Beyond
Agentic workloads are maturing fast. The patterns that felt cutting-edge in 2025 are now standard. Here's what I see coming:
Smaller, cheaper models. The math on inference is improving. You'll be able to run 80% of agent logic with models that cost 30x less than GPT-4-class systems. That shifts the cost balance toward compute, making Kubernetes relatively cheaper.
State as a service. Redis, Memcached, and other state stores are becoming agent-native. You'll see products that handle checkpointing, serialization, and state restore as managed services. That reduces the burden of stateful design.
Protocol stabilization. The Agent Client Protocol, MCP, and other standards are reducing framework churn. Less time rewriting infrastructure means more time optimizing.
Observability for agents. Tracing an agent's reasoning steps is still sucky. That's changing. Dedicated agent tracing tools are coming online. This will make operational diagnosis much faster.
But the fundamentals won't change. Agents need compute, memory, and orchestration. The best platform is the one that fits your agent's lifecycle.
Frequently Asked Questions
Should I start with Kubernetes or serverless for my AI agent?
Start with serverless if your agent is simple and stateless. It gets you to market faster. Move to Kubernetes when you hit latency or cost walls. You will hit them.
What's the biggest hidden cost in ai agent scaling kubernetes vs serverless?
State storage and hydration. Teams optimize compute costs, then forget that every state load and save has a price. We saw a client spend 22% of their budget on Redis operations they hadn't planned for.
How do I handle cold starts in serverless for agents?
You can't eliminate them, but you can mitigate them with provisioned concurrency. That costs more but keeps functions warm. You're trading cost for latency. It's a business decision, not a technical one.
Is Kubernetes overkill for a small agent project?
Probably. If you have one agent and 100 users, use a simple server or serverless function. Kubernetes shines at scale. It's expensive to operate at small scale.
What's the best approach for ai agent cost optimization at scale?
Design for statelessness. The more stateless your agents, the more efficiently you can scale. Cost follows compute. Compute follows state.
What's the biggest mistake you see in agent deployment?
Choosing a platform before designing the agent lifecycle. The agent determines the platform, not the other way around.
Can I migrate from serverless to Kubernetes later?
Yes, it's painful but doable. Make your agent code platform-agnostic from day one. Separate business logic from infrastructure code. Your future self will thank you.
At the end of the day, the question of ai agent scaling kubernetes vs serverless isn't a technology debate. It's an economics question, a latency question, and an operational question. The right answer depends on what your agent does, how long it runs, and how much money you have to burn.
We're moving away from the binary at SIVARO. Our infrastructure is now hybrid, event-driven, and state-aware. The results are measurable: 61% lower cost per agent run, 4x faster scaling, and 99.95% uptime across our production fleet.
That didn't happen with one platform. It happened with the right platform for each job.
I write, talk, and build this stuff. Follow along if you want to see what's next.
Nishaant Dixit — Founder of SIVARO. Building data infrastructure and production AI systems since 2018. Built systems processing 200K events/sec.