Chapter 5. FinOps & Resilience: cost, rate limits, and high availability | Grigoriy Dobryakov

Grigoriy Dobryakov

Course · Enterprise AI Governance Architecture

Chapter 5AI Governance course

Chapter 5. FinOps & Resilience: cost, rate limits, and high availability

A real production case from a B2B SaaS company (2026): a team turned on semantic caching with a similarity threshold of 0.88 and a global namespace to save on tokens. At one point the cache returned a Tier-1 customer's cancellation summary during a Tier-3 customer's session. Two different requests turned out to be "similar enough" by embedding — and a cost optimization became a cross-tenant leak. The team rolled back to exact-match caching.

This story is why the cost/resilience plane can't be built in isolation from chapters 1–2: an optimization that saves money at the cost of a leak isn't savings. This chapter is about eliminating uncontrolled token spend growth, protecting against exhausting API rate limits, and delivering 99.9%+ SLA — without sacrificing privacy or creating new points of failure.

The customer's business goal

For Kovcheg: a provider outage during business hours means idle operations staff; an uncontrolled agent means a six-figure overnight bill; an exhausted rate limit means "the assistant is down" at peak hour. Promises to the business:

  1. Spend is predictable and capped by department/user.
  2. A provider outage or throttle doesn't bring the system down.
  3. Optimizations (caching) never cross access or quality boundaries.

Driver: threat or regulator

Architectural pattern

Multi-Provider AI Gateway & Semantic Caching — a single gateway in front of all providers with semantic caching, budgets, fallback, and circuit breaking. The same layer that carries ch. 1 (PII), 3 (guardrails), 4 (tracing) — the planes don't spawn separate proxies, they live in one.

Engineering stack & providers

Engineering implementation

### Step 1. A single gateway

All model calls go through one layer. This is the same requirement as ch. 1 (bypassing it is a privacy hole).

### Step 2. Semantic caching with tenant isolation

Embed the prompt → search by cosine similarity in Redis; above the threshold, return the cached answer without calling the LLM. Lessons from the introduction's incident, baked into config:

semantic_cache:
  similarity_threshold: 0.97          # above the typical 0.88 — fewer false hits
  namespace: "{tenant_id}:{model}"    # model-level + tenant isolation, never global
  skip_if: ["contains_pii", "personalized"]  # never cache private content (ch. 1–2)
  per_request_threshold_override: true

Only cache non-personal, non-privileged content. In production, semantic caching realistically covers 20–45% of traffic — a material saving, as long as it doesn't break isolation.

### Step 3. Multi-tenant budgeting

Hard limits on tokens and cost by department and user; soft-alert → hard-stop. For agents (ch. 9), an additional per-task limit on steps/cost.

### Step 4. Fallback & circuit breaker

Auto-switch on rising latency or 5xx/429 errors; degrade to a backup provider or a local model; retries with backoff. A circuit breaker opens the circuit to a failing provider instead of hammering it into further failure.

### Step 5. Cost observability

Cost per request/tenant/feature in Grafana; a spending anomaly triggers an alert (this is where a nighttime agent burning through budget gets caught).

Where it breaks

Standards and mapping

Lab and artifact

Deploy LiteLLM/Portkey in front of Kovcheg: semantic cache with a tenant-scoped namespace and a 0.97 threshold, skip for PII, per-department budgets, fallback to a backup provider. Reproduce the intro's incident (global namespace + 0.88) to show the leak, then fix it via config. Simulate 429s and 5xxs — verify degradation and circuit breaking. Artifact: gateway config + a Grafana cost/latency dashboard + budget policies + a "cache hit-rate vs. cross-tenant safety" report.

Maturity checklist

Sources

Read next

Putting AI into production under regulatory risk?

Designing the control plane for your system: privacy, access, guardrails, audit, EU AI Act / ISO 42001 compliance — as working architecture, not a policy PDF.

Email me

The transition engine

Next Move Engine — the system that takes a team to an autonomous delivery loop.

Next Move Engine →