Cheat sheets
Production reliability
Patterns, formulas, and monitoring for dependable, affordable AI services.
| Pattern | Use it to |
|---|---|
| Timeouts | never wait forever on a model, tool, or index |
| Bounded retries with exponential backoff + jitter | recover from transient failures without retry storms |
| Circuit breaker | stop calling a failing dependency; use a fallback |
| Idempotency keys | make retried side effects happen once |
| Fallbacks | smaller model, cached answer, degraded feature |
| Structured outputs + schema validation | never act on malformed model output |
| Rate limits and quotas | protect capacity and budget |
| Model / prompt / index versioning | reproduce and roll back |
| Formula | Meaning |
|---|---|
| independent failures with retries | |
| availability of dependencies in series | |
| Little's law: requests in flight | |
| per-request token cost | |
| cost with cache hit rate (hits ≈ free) | |
| params × bits / 8 | weight memory (7B: 14 GB fp16, 3.5 GB int4) |
Cost and latency levers: shorter prompts, fewer chunks, caching, routing to small models, output limits, streaming, batching, KV caching, quantization, distillation.
Monitor: latency percentiles (not averages), errors, cost, cache hit rate, input/prompt drift, retrieval gaps, quality signals, version skew.
Lessons: Production architecture · Reliability, cost, and observability