Comprehensive guide to llm blue green deployment covering architecture, implementation, testing, and operational patterns for production engineering teams.
LLM Blue Green Deployment is a strategy for updating large language models in production with zero downtime and minimal risk. It involves maintaining two identical, parallel environments—blue and green—where one serves live traffic while the other is updated and validated. When the new version is ready, traffic is switched from the blue to the green environment, making the update instantaneous and reversible. This approach is essential when model updates are expensive, inference latency is critical, or the cost of a failed rollout exceeds the benefits of new features.
To begin a blue green deployment, first prepare the green environment. This starts with a new model version, typically a retrained or fine-tuned version of the current model. The process begins with model packaging and versioning using standard tools.
docker build -t ghcr.io/myorg/llm-green:2024.06.01 -f Dockerfile.green .
docker push ghcr.io/myorg/llm-green:2024.06.01
The Dockerfile.green includes all dependencies, model weights, and a server entrypoint:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY model/ /app/model/
COPY server.py /app/server.py
EXPOSE 8000
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "server:app"]
The server is a minimal FastAPI app serving the model:
# server.py
from fastapi import FastAPI
from pydantic import BaseModel
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
app = FastAPI()
# Load model and tokenizer
model_name = "/app/model"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
class PromptRequest(BaseModel):
prompt: str
max_tokens: int = 128
@app.post("/generate")
def generate(request: PromptRequest):
inputs = tokenizer(request.prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=request.max_tokens)
return {"text": tokenizer.decode(outputs[0], skip_special_tokens=True)}
This green environment is then deployed via a standard orchestration tool such as Kubernetes.
# deploy-green.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: llm-green
labels:
app: llm
version: "2024.06.01"
spec:
replicas: 4
selector:
matchLabels:
app: llm
environment: green
template:
metadata:
labels:
app: llm
environment: green
version: "2024.06.01"
spec:
containers:
- name: llm
image: ghcr.io/myorg/llm-green:2024.06.01
ports:
- containerPort: 8000
resources:
requests:
memory: "4Gi"
cpu: "2"
limits:
memory: "8Gi"
cpu: "4"
Apply the deployment:
kubectl apply -f deploy-green.yaml
The green environment is now running and ready to serve traffic, but it is not yet active.
Before switching traffic, validate the green environment with a set of real-world prompts and expected outputs.
# Run validation tests via a script
curl -X POST http://llm-green.mycompany.com:8000/generate \
-H "Content-Type: application/json" \
-d '{
"prompt": "Explain quantum computing in simple terms.",
"max_tokens": 256
}'
The response must be JSON with a text field. A validation script checks against a known golden output:
import requests
import json
GOLDEN_OUTPUTS = {
"quantum_computing": "Quantum computing uses qubits...",
"code_generation": "A quantum computer can process...",
}
def validate_green():
for test, expected in GOLDEN_OUTPUTS.items():
response = requests.post(
"http://llm-green.mycompany.com:8000/generate",
json={"prompt": test, "max_tokens": 256}
)
result = response.json()
if result["text"] != expected:
print(f"Validation failed for {test}")
return False
return True
if validate_green():
print("Green environment validated")
else:
print("Green environment validation failed")
The validation must succeed before proceeding. If any test fails, the deployment pipeline pauses. A common silent failure is model loading with incorrect tokenizer or missing weights—this is caught by validating a prompt with known output.
Once validated, switch traffic from the blue to the green environment using a load balancer or reverse proxy.
# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: llm-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: llm.mycompany.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: llm-blue
port:
number: 8000
Update the ingress to route to the green service:
# ingress.yaml (updated)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: llm-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: llm.mycompany.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: llm-green
port:
number: 8000
Apply the updated ingress:
kubectl apply -f ingress.yaml
The switch is instantaneous: clients hitting llm.mycompany.com now use the green environment. Traffic is now served by the new model version.
During the transition, both blue and green services are running. The blue service continues to serve traffic while the green service is being validated and warmed.
A common issue is cold start latency in the green deployment. The new model is not yet loaded into GPU memory. To warm it, send a batch of pre-defined prompts:
# Warm the green model
for prompt in $(cat warmup_prompts.txt); do
curl -X POST http://llm-green.mycompany.com:8000/generate \
-H "Content-Type: application/json" \
-d "{\"prompt\": \"$prompt\", \"max_tokens\": 128}" \
-s -o /dev/null -w "%{http_code}\n"
done
The warmup script runs at startup and before deployment. It reduces the chance of first-request latency spikes.
If the green deployment fails—either in validation or in production—roll back to the blue environment.
# ingress.yaml (rollback)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: llm-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: llm.mycompany.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: llm-blue
port:
number: 8000
Apply the rollback ingress and monitor logs:
# Monitor the blue service
kubectl logs -f deployment/llm-blue
A frequent failure is inconsistent response schema between blue and green. The green service returns a text field, but the blue service returns a output field. The load balancer routes traffic, but clients fail to parse the JSON. This is silently detected only when monitoring logs.
// Blue service response
{
"output": "Quantum computing uses qubits..."
}
// Green service response
{
"text": "Quantum computing uses qubits..."
}
The client code must handle both schemas, or the schema mismatch must be enforced at the ingress layer.
After switching, the blue environment becomes the new green, and the old green becomes the blue for the next release cycle.
# Update blue to the current green version
kubectl rollout restart deployment/llm-blue
The blue deployment is now running the latest version. The old green deployment can be scaled down or deleted.
# Scale down green after successful rollout
kubectl scale deployment llm-green --replicas=1
# Delete green after 24 hours
kubectl delete deployment llm-green
If the new green is stable, promote it to production and prepare the next update.
RuntimeError: Unable to load model from /app/model
The cause is often a missing config.json or pytorch_model.bin in the model directory.
2024.06.01, but the blue environment is on 2024.05.15. Clients may see inconsistent behavior when switching.503 Service Unavailable, but the script assumes 200 OK.MODEL_PATH=/data/model, but the blue service uses MODEL_DIR. The Dockerfile must include both, or the environment must be standardized.| Action | Command |
|---|---|
| Build green model image | docker build -t ghcr.io/myorg/llm-green:2024.06.01 -f Dockerfile.green . |
| Deploy green service | kubectl apply -f deploy-green.yaml |
| Validate green | curl -X POST http://llm-green.mycompany.com/generate ... |
| Switch traffic | Update ingress YAML and apply |
| Warm green model | for prompt in $(cat warmup_prompts.txt); do curl ...; done |
| Rollback to blue | Update ingress to route to llm-blue |
| Monitor blue after rollback | kubectl logs -f deployment/llm-blue |
| Scale down green | kubectl scale deployment llm-green --replicas=1 |
| Delete green | kubectl delete deployment llm-green |
LLM Blue Green Deployment is not a one-time process. It is a repeatable, reliable pattern for updating language models in production. Every step is executable, every failure is visible, and every choice is grounded in real tooling and real data flow.
This page was rewritten on 14 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy