Production Readiness — Observability, Deployment & Operations
Logs, metrics and traces with OpenTelemetry, RED/USE/golden signals, correlation IDs, health checks (liveness, readiness, startup), twelve-factor configuration, graceful shutdown, deployment strategies (rolling, blue-green, canary, feature flags), testing strategy, API documentation, and a production-readiness checklist.
Observability
Structured logs with correlation
{"ts":"2026-10-07T10:21:03.412Z","level":"error","service":"payments","env":"prod",
"trace_id":"4bf92f3577b34da6a3ce929d0e0e4736","span_id":"00f067aa0ba902b7",
"request_id":"req_01J9ZK7T0X","user_id":"usr_42","route":"POST /v1/payments",
"msg":"card declined","decline_code":"insufficient_funds","latency_ms":182}
Rules: JSON; consistent field names; include trace/request IDs; log events, not every line; never log secrets, tokens, full card numbers or unnecessary PII; sample noisy debug logs.
Metrics that matter
| Signal | Metric | Example alert |
|---|---|---|
| Rate | http_requests_total by route/status | sudden drop to 0 |
| Errors | 5xx ratio | > 1% for 5 min (or SLO burn rate) |
| Duration | latency histogram → p50/p95/p99 | p99 > 500 ms for 10 min |
| Saturation | CPU, memory, pool utilisation, queue depth, consumer lag | queue lag growing for 15 min |
Distributed tracing
from opentelemetry import trace
tracer = trace.get_tracer("payments")
def charge(order):
with tracer.start_as_current_span("charge_card") as span:
span.set_attribute("order.id", order.id)
span.set_attribute("payment.amount_minor", order.total)
result = psp_client.charge(order) # auto-instrumented HTTP client adds a child span
span.set_attribute("payment.status", result.status)
return result
The W3C traceparent header propagates context across HTTP/gRPC/messaging so spans from every service join one trace.
Health checks
@app.get("/livez") # liveness: am I alive? (no dependency checks)
def livez():
return {"status": "ok"}
@app.get("/readyz") # readiness: should I get traffic?
def readyz():
if shutting_down or not warmed_up or not db_pool.healthy():
return JSONResponse({"status": "not ready"}, status_code=503)
return {"status": "ready"}
# Kubernetes
livenessProbe: { httpGet: { path: /livez, port: 8080 }, periodSeconds: 10, failureThreshold: 3 }
readinessProbe: { httpGet: { path: /readyz, port: 8080 }, periodSeconds: 5 }
startupProbe: { httpGet: { path: /livez, port: 8080 }, failureThreshold: 30, periodSeconds: 2 }
Configuration (twelve-factor)
- Config in the environment (or a config service), not in code; same build artifact for every environment.
- Secrets from a secrets manager.
- Validate config at startup and fail fast.
- Feature flags for runtime toggles (LaunchDarkly, Unleash, OpenFeature).
The twelve factors in one line each: one codebase; explicit dependencies; config in env; backing services as attached resources; separate build/release/run; stateless processes; port binding; scale out via processes; disposability (fast start, graceful stop); dev/prod parity; logs as event streams; admin tasks as one-off processes.
Graceful shutdown
import asyncio, signal
shutting_down = False
async def main():
server = await start_http_server()
loop = asyncio.get_running_loop()
stop = asyncio.Event()
loop.add_signal_handler(signal.SIGTERM, stop.set)
await stop.wait()
global shutting_down
shutting_down = True # /readyz now returns 503
await asyncio.sleep(5) # let load balancers deregister us
server.close() # stop accepting new connections
await asyncio.wait_for(server.wait_closed(), timeout=20) # drain in-flight requests
await consumer.stop_and_commit() # finish/ack current messages
await db_pool.close()
Deployment strategies
| Strategy | Extra capacity | Rollback | Risk exposure | Notes |
|---|---|---|---|---|
| Recreate | none | redeploy | everyone, with downtime | dev/test only |
| Rolling | small | slow-ish | grows with rollout | Kubernetes default |
| Blue-green | 2× | instant switch | everyone at switch time | needs schema compatibility |
| Canary | small | fast (shift traffic back) | small % first | automate analysis (Argo Rollouts, Flagger) |
| Shadow / dark launch | depends | n/a | none (responses discarded) | test with real traffic |
Testing strategy
| Level | What | Notes |
|---|---|---|
| Unit | pure logic | fast, many |
| Integration | DB, cache, queues | real dependencies in containers (Testcontainers) |
| Contract | API compatibility between services | consumer-driven contracts (Pact), OpenAPI diff checks |
| End-to-end | critical user journeys | few, slow, flaky-prone |
| Load / stress / soak | capacity, limits, leaks | k6, Gatling, Locust |
| Chaos | resilience to failures | fault injection in staging/prod (with guard rails) |
| Security | SAST, DAST, dependency scanning | in CI |
API documentation
- OpenAPI spec as the source of truth (generate docs, SDKs, mocks, validation, contract tests).
- Examples for every endpoint, error catalogue, auth guide, rate-limit policy, changelog, deprecation schedule.
- Sandbox environment and test API keys for external developers.
Production-readiness checklist
- SLOs defined; dashboards + alerts on SLO burn
- Timeouts, retries (with jitter), circuit breakers on every dependency
- Rate limiting and input size limits
- AuthN/AuthZ on every endpoint (object-level)
- Liveness/readiness probes; graceful shutdown
- Autoscaling + load-tested capacity; multi-AZ
- Structured logs, metrics, traces with correlation IDs
- Secrets in a manager; least-privilege IAM
- Backups and a tested restore procedure
- Safe deployments (canary/blue-green) and backward-compatible migrations
- Runbooks, on-call ownership, dependency map
- Data classification, retention and deletion (GDPR/DPDP)
Interview questions
Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.