·7 min read

Why We Switched to 1 Worker Per Pod in Kubernetes

How multi-worker pods were hiding failures from our monitoring, and why single-worker pods made debugging 10x easier

Monitoring was green. Customers were reporting intermittent timeouts. We were sure it was the network. It took weeks to find the real culprit: multiple workers per pod, hiding failures from Kubernetes' health checks.

This isn't a universal truth. Plenty of teams run multi-worker pods just fine. But if you have mysterious failures you can't reproduce, or an app with worker-level bugs, read on.

The Visibility Problem

Users said "the API is slow sometimes". We checked the dashboards: all green, normal metrics.

This went on for months.

We had the classic FastAPI setup that everyone uses:

uvicorn main:app --workers 4

Makes sense, right? One pod, four workers. More workers = more throughput. It's what the docs show, what Stack Overflow recommends, what we've all been doing since forever.

Except it was randomly eating requests, and we had no idea.

The Debugging Journey

It started with sporadic customer complaints. Not many, but enough to investigate. The weird part? We could never reproduce it. Our logs showed the requests coming in, then... nothing. No error, no timeout logged, just silence.

After adding way too much instrumentation, we finally caught it:

Pod Status: ✅ Running
Health Check: ✅ 200 OK
Reality: Worker 2 had been deadlocked for 47 minutes

The pod was "healthy" because the health checks kept landing on the three live workers. Worker 2 was stuck, and every request that landed on it just hung.

┌─────────────────┐
│ Pod (Running)   │
│                 │
│ Worker 1: ✅    │ ← Health checks answered here
│ Worker 2: 💀    │ ← Stuck for 47 minutes
│ Worker 3: ✅    │
│ Worker 4: ✅    │
└─────────────────┘

Why This Is Hard to Detect

Standard monitoring usually won't catch this.

Kubernetes checks if the pod is healthy, not individual workers. Your health endpoint returns 200 OK because a worker responds. CPU and memory look normal because three workers are fine. Your logs are a mess because all four workers write to the same stdout.

And even if a probe does hit the stuck worker once in a while, it doesn't matter. A liveness probe only restarts the container after failureThreshold consecutive failures (default 3). One failed probe followed by a pass resets the count. A pod where 1 in 4 probes fails will never get restarted.

It's like having a 4-person customer service team where one person went home, but nobody noticed because the phone still gets answered... eventually.

The Core Issue

Obvious in hindsight: Kubernetes manages pods, not processes inside pods. When you run multiple workers, Kubernetes can't see if one of them fails.

The Solution That Felt Wrong (But Worked)

We switched to 1 worker per pod.

Yes, really.

# Before: 1 pod with 4 workers
apiVersion: apps/v1
kind: Deployment
spec:
  replicas: 1
  template:
    spec:
      containers:
      - name: app
        command: ["uvicorn", "main:app", "--workers", "4"]
 
# After: 4 pods with 1 worker each
apiVersion: apps/v1
kind: Deployment
spec:
  replicas: 4
  template:
    spec:
      containers:
      - name: app
        command: ["uvicorn", "main:app"]  # No --workers flag
        resources:
          requests:
            memory: "128Mi"
            cpu: "100m"
          limits:
            memory: "256Mi"
            cpu: "200m"

At first this felt like going backwards. More pods? Isn't that wasteful?

We also added an HPA:

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: my-app
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-app
  minReplicas: 4
  maxReplicas: 20
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70

(If you copy an older example with targetCPUUtilizationPercentage, that field is autoscaling/v1 only. In v2 it's the metrics block above.)

One thing the YAML above doesn't show: you still need a liveness probe. With one worker, a crash means the process exits and the kubelet restarts the container on its own. But a hung worker is still running, so only a liveness probe catches it. The difference is that now the probe always hits the one worker that matters, so a hang fails every probe and the restart actually happens.

What Actually Improved

Failures became visible. Worker crash = container restart. Worker hang = failed liveness probe = container restart. No more silent failures.

Debugging became possible.

# Before: Which worker logged this error??
kubectl logs my-app-pod-abc123
[ERROR] Database connection failed
[INFO] Request processed
[ERROR] Database connection failed
[INFO] Request processed
# All workers mixed together 😭
 
# After: Clear logs per pod
kubectl logs my-app-pod-abc123
[ERROR] Database connection failed
# Ah, THIS specific instance has DB issues

Scaling became granular. Instead of jumping from 4 workers to 8 (doubling capacity), we could go from 4 to 5 pods. Much smoother.

Resource limits actually worked. Before, one worker could hog CPU and starve the others, and the limit only applied to the pod as a whole. Now Kubernetes enforces limits per worker, because a worker is a pod.

But What About...

"Isn't this more overhead?"

Yes. 4 pods use more total memory than 1 pod with 4 workers, since there's no copy-on-write sharing between pods. I still think it's worth it: each pod gets its own resources, no workers fight over CPU, and when something breaks you know exactly which instance it is.

"What about startup time?"

Fair point. If your app takes 30 seconds to start, deploys get slower. But with rolling deployments and proper readiness probes, users never notice.

"What about shared resources?"

This is the one real trade-off. If you're loading a 2GB ML model, you probably don't want 10 pods each loading their own copy. More on this below.

The ML Exception

There's one case where we kept multi-worker pods: our ML inference service.

The model takes 2 minutes to load and uses 4GB of RAM. Running 10 pods would mean 40GB of RAM just for model copies. Not worth it.

So for that service we kept the workers and added a health check that tries to cover all of them. The idea, as pseudo-code:

# ML service keeps multiple workers
uvicorn ml_service:app --workers 3
 
# But we added aggressive health checking
@app.get("/health/workers")
async def check_all_workers():
    """Actually verify all workers can process requests"""
    results = []
    for worker_id in range(3):
        try:
            # Each worker must prove it's alive
            test_inference = await run_inference_test(worker_id)
            results.append({"worker": worker_id, "status": "ok"})
        except:
            results.append({"worker": worker_id, "status": "dead"})
 
    if any(r["status"] == "dead" for r in results):
        raise HTTPException(503, detail=results)
 
    return results

A caveat if you build this yourself: an HTTP request lands on one worker, and that worker can't call into its siblings directly. Uvicorn gives you no way to route a request to a specific worker. A pattern that does work is a heartbeat file: each worker writes a timestamp to its own file (for example /tmp/hb-<pid>) from a background task, and an exec liveness probe fails if any file is older than N seconds. The probe then runs outside the workers, so a stuck worker can't hide behind the healthy ones.

The point stays the same: if you must run multiple workers, monitor each one, not the pod.

How To Know If You Have This Problem

Try it on a multi-worker pod (not in prod):

  1. Find the worker PIDs: kubectl exec <pod> -- ps -ef (if the image has no ps, look at /proc/*/cmdline)
  2. Freeze one worker: kubectl exec <pod> -- kill -STOP <worker-pid>
  3. Watch the health checks keep passing
  4. Send a bunch of requests and watch some of them hang
  5. kill -CONT <worker-pid> when you're done

If you're using --workers in your deployments, you probably have this gap. The question is whether you can live with it.

Migration Strategy (The Realistic Version)

Don't big-bang this. Here's what worked for us:

Week 1: Pick your least important service

  • That internal admin tool with 5 users? Perfect.
  • Remove --workers, increase replicas
  • Watch it for a week

Week 2-3: Move to a real service

  • Pick something customer-facing but not critical
  • Add good resource limits
  • Set up an HPA
  • Monitor error rates obsessively

Week 4+: Gradual rollout

  • Service by service
  • Keep a list of "exceptions" (ML services, etc.)
  • Document why each exception exists

What Changed

The biggest difference was in visibility and in how we debug. Failed workers now trigger restarts, logs trace back to a specific instance, debugging got noticeably faster, and the mysterious timeouts mostly disappeared.

Latency and overall performance stayed the same. Total resource usage stayed about the same once the per-pod limits were tuned.

What we had to redo: resource limits per pod, the deployment config of every service, and the team's mental model of how pods scale.

What This Taught Us

The bigger lesson isn't about workers or pods. It's that sometimes the "best practice" from the VM era doesn't translate to Kubernetes.

We've been trained to think "fewer processes = better" because managing processes used to be hard. But Kubernetes is really good at managing lots of pods. That's literally its job.

Let it do its job.

The TL;DR

  • Multiple workers per pod can hide a stuck worker from your probes and make debugging painful
  • 1 worker per pod + liveness probe + HPA makes failures visible and logs traceable
  • Exception: services with high startup cost (ML models). Monitor each worker there
  • Migration: start with one non-critical service, measure, then roll out. You can always revert

Got war stories about multi-worker pods? Found a case where they actually make sense? Hit me up. I'm genuinely curious about other experiences with this pattern.


A note on how this was written: I used AI to help with phrasing and structure. The tone, the opinions, the war stories, the code, and everything else here are mine.