Prompt
How do I set up an inference API for rolling model updates without downtime?
Latest observation
To set up an inference API with rolling model updates and no downtime, the main idea is:
- Keep at least one old serving instance alive while bringing up the new one
- Only switch traffic after the new version is healthy
- Drain old instances gradually
- Use versioned models and traffic routing
Recommended architecture
- API Gateway / Load Balancer
- Inference service replicas running behind it
- Model registry / artifact store for versioned models
- Deployment controller for rollout logic
- Health checks + readiness probes
- Optional: canary routing for safer rollouts
Simple zero-downtime rollout pattern
1. Version your models
Store every trained model as an immutable version, for example:
model-v12model-v13
Use a model registry or object storage path like:
s3://models/recommendation/13/model.onnxgs://.../14/
This lets the service run version N while version N+1 is being prepared.
2. Run multiple replicas behind a load balancer
Your API should not depend on a single process. Run at least 2 replicas:
- Replica A: serving
v12 - Replica B: serving
v12
When updating:
- start new replicas with
v13 - keep old replicas serving until new ones are ready
3. Use readiness checks
A new instance should not receive traffic until it has:
- loaded the model successfully
- warmed up caches
- passed a sample inference check
Example readiness flow:
- container starts
- downloads model
- loads into memory / GPU
- performs test inference
- returns
ready
Only then should the load balancer route traffic to it.
4. Rolling deployment strategy
Typical rolling update sequence:
- Start one new replica with the new model
- Wait for readiness
- Route a small amount of traffic or none at first
- Stop one old replica
- Repeat until all replicas are updated
If using Kubernetes, this is often done with:
RollingUpdatemaxUnavailable: 0maxSurge: 1
This ensures there’s always capacity available.
Safer option: blue-green deployment
This is often the easiest way to get zero downtime.
- Blue = current production version
- Green = new version
Process:
- Deploy green environment alongside blue
- Run health checks and smoke tests
- Switch traffic from blue to green
- Keep blue alive briefly for rollback
- Decommission blue after confidence is high
This is especially good when model loading is expensive or stateful.
Best option for production: canary deployment
Instead of switching all traffic at once:
- Send 1% of requests to the new model
- Monitor latency, error rate, and model quality signals
- Increase to 10%, 25%, 50%, then 100%
- Roll back automatically if metrics degrade
Useful metrics:
- request latency
- 5xx error rate
- timeout rate
- business KPIs
- prediction distribution drift
- model confidence distribution
Handling model loading without downtime
Common issue
If the process reloads the model in-place, requests may fail or latency may spike.
Better patterns
- Start a new process with the new model
- Or double-buffer the model in memory
- load new model into a second slot
- switch pointer atomically
- free old model after in-flight requests complete
This avoids blocking live traffic.
Graceful shutdown
When removing an old instance:
- Stop sending it new requests
- Let in-flight requests finish
- Close connections after a timeout
- Then terminate the process
In Kubernetes:
- use
preStophooks - set a sufficient
terminationGracePeriodSeconds
Suggested API behavior
Your inference API should expose:
GET /healthz→ process is aliveGET /readyz→ model loaded and readyPOST /infer→ inference request- Optional:
GET /version→ current model version
Example response:
{
"prediction": 0.82,
"model_version": "v13"
}
This helps observability and rollback.
Example deployment flow
Step-by-step
- Train
v13 - Validate offline
- Upload model artifact
- Deploy new serving pods with
v13 - Wait for readiness
- Route 5% of traffic
- Monitor metrics
- Increase traffic to 100%
- Terminate
v12pods
If you use Kubernetes
A common setup:
Deploymentfor the inference serviceServicefor stable traffic routingIngressor load balancer in frontConfigMap/env var for model version- rolling update strategy configured for zero downtime
Key settings:
strategy:
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
And add:
- liveness probe
- readiness probe
- resource requests/limits
- termination grace period
Extra safeguards
- Keep old models available for rollback
- Log model version with every prediction
- Use shadow traffic to test new models without affecting responses
- Cache model artifacts locally to reduce startup time
- Make deployments immutable and reproducible
Practical recommendation
If you want the simplest robust setup:
- Use blue-green or rolling update
- Put the model behind a load balancer
- Use readiness probes
- Load the model in a new process
- Switch traffic only after health checks pass
- Keep old version around for fast rollback
If you want, I can also give you:
- a Kubernetes YAML example,
- a FastAPI inference service template, or
- a blue-green/canary deployment diagram.
Brands