Skip to content
ML to LLMs
Cheat sheets

Production reliability

Patterns, formulas, and monitoring for dependable, affordable AI services.

PatternUse it to
Timeoutsnever wait forever on a model, tool, or index
Bounded retries with exponential backoff + jitterrecover from transient failures without retry storms
Circuit breakerstop calling a failing dependency; use a fallback
Idempotency keysmake retried side effects happen once
Fallbackssmaller model, cached answer, degraded feature
Structured outputs + schema validationnever act on malformed model output
Rate limits and quotasprotect capacity and budget
Model / prompt / index versioningreproduce and roll back
FormulaMeaning
P(fail)=pr+1P(\text{fail}) = p^{r+1}independent failures with rr retries
A=∏iaiA = \prod_i a_iavailability of dependencies in series
L=λWL = \lambda WLittle's law: requests in flight
cost=nincin+noutcout\text{cost} = n_{\text{in}}c_{\text{in}} + n_{\text{out}}c_{\text{out}}per-request token cost
(1−h) cmiss(1 - h)\,c_{\text{miss}}cost with cache hit rate hh (hits ≈ free)
params × bits / 8weight 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