LLM Rate Limiting & Traffic Management Service

Architecture Views

24 views, in reading order. Every view ships three ways: an HTML page, an SVG that re-opens in diagrams.net fully editable, and draw.io source.

A distributed, multi-tenant admission control plane that sits between applications and LLM providers and answers one question in under 10 milliseconds: may this request proceed? The set reads in six acts — what sits inside the boundary, how the parts fit, where state lives and who owns it, what happens at runtime, how it is operated, and why it is safe. Four decisions carry the whole design: quota is leased to pod-local buckets so most decisions never leave the process (views 07 and 14); tenant scopes are made atomic by co-locating their keys on one Redis slot (view 12); estimated tokens are reserved and reconciled against actuals with a reaper behind them (view 13); and the behaviour when coordination fails is a per-tenant policy field rather than a global constant (view 23).

Context and scope

What the service is accountable for, who depends on it, and the deliberate limit on what it is allowed to see.
01
Governance
Governance
Platform Admin
sets policy
Platform Admin...
FinOps & Billing
FinOps & Billing
Traffic sources
Traffic sources
Product Applications
chat, search, copilots
Product Applications...
Agent Workloads
bursty, multi-step
Agent Workloads...
Offline & Batch Jobs
evals, backfills
Offline & Batch Jobs...
LLM providers
LLM providers
Azure OpenAI
Azure OpenAI
Anthropic Claude
Anthropic Claude
Google Gemini
Vertex AI
Google Gemini...
Mixtral on vLLM
self-hosted GPU
Mixtral on vLLM...
LLM Traffic Manager
Authorize · meter · route
LLM Traffic Manager...
Enterprise services
Enterprise services
Keycloak IdP
OIDC, tenant realms
Keycloak IdP...
Observability Platform
Prometheus · Grafana
Observability Platform...
Data Lakehouse
Iceberg on MinIO
Data Lakehouse...
authorize + call
authorize + call
high fan-out
high fan-out
bulk tier
bulk tier
completions
completions
completions
completions
completions
completions
completions
completions
policy-as-code
policy-as-code
usage + cost
usage + cost
tenant identity
tenant identity
metrics, traces
metrics, traces
usage export
usage export
LLM Traffic Manager — System Context
LLM Traffic Manager — System Context
Person or role
Person or role
External / third party
External / third party
Security / platform
Security / platform
synchronous
synchronous
batch
batch
Prompts and completions traverse the egress gateway but are never persisted by the limiter — only token counts, scopes and decisions.
Prompts and completions traverse the egress gateway but are never persisted by the limiter — only token counts, scopes and decisions.
v 1.0 · owner Data & AI Global Practice · date 2026-08
v 1.0 · owner Data & AI Global Practice · date 2026-08
Text is not SVG - cannot display
System Context Who sends traffic through the service, which providers it protects, and what it deliberately refuses to hold. HTML page SVG draw.io
02
Client edge
Client edge
Application / SDK
Go · Python · TS
Application / SDK...
Envoy Gateway
ext_authz filter
Envoy Gateway...
Decision
Decision
limiterd
Go · gRPC · stateless
limiterd...
Local Lease Buckets
in-process · 0.3 ms
Local Lease Buckets...
Coordination
Coordination
Valkey Cluster
16 shards · Lua
Valkey Cluster...
Reservation Ledger
TTL 120 s
Reservation Ledger...
Egress
Egress
LLM Gateway
provider adapters
LLM Gateway...
Circuit Breakers
per provider + model
Circuit Breakers...
Providers
Providers
Azure OpenAI
Azure OpenAI
Claude · Gemini
Claude · Gemini
Mixtral on vLLM
Mixtral on vLLM
Accounting
Accounting
Kafka usage.v1
24 partitions
Kafka usage.v1...
Flink Aggregator
exactly-once
Flink Aggregator...
ClickHouse Ledger
usage + cost
ClickHouse Ledger...
commit actuals
commit actuals
budget refresh
budget refresh
High-Level Architecture — the path of one request
High-Level Architecture — the path of one request
External / third party
External / third party
Interface / broker
Interface / broker
Application we own
Application we own
Data store
Data store
Queue / topic
Queue / topic
event / async
event / async
The hot path is edge → limiterd → local lease. Valkey is touched only when a lease is exhausted; PostgreSQL and ClickHouse are never on it.
The hot path is edge → limiterd → local lease. Valkey is touched only when a lease is exhausted; PostgreSQL and ClickHouse are never on it.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
High-Level Architecture The path one request takes, and which parts of it are on the latency budget. HTML page SVG draw.io

Structure

The layering rule, the deployable containers, the integration surface, and the three ways a workload can adopt the platform.
03
Client & Edge
Client & Edge
Application SDK
authorize + commit
Application SDK...
Envoy Gateway
ext_authz, mTLS
Envoy Gateway...
Tenant Router
Maglev hash
Tenant Router...
Admission Control
tier shedding
Admission Control...
Decision
Decision
Authorize API
gRPC + HTTP
Authorize API...
Policy Evaluator
scope cascade
Policy Evaluator...
Algorithm Engine
bucket · sliding window
Algorithm Engine...
Reason & Retry Builder
429 semantics
Reason & Retry Builder...
Coordination
Coordination
Lease Manager
250 ms grants
Lease Manager...
Atomic Limit Scripts
Lua · single slot
Atomic Limit Scripts...
Reservation Ledger
estimate vs actual
Reservation Ledger...
Concurrency Semaphores
slot lease + reaper
Concurrency Semaphores...
Egress & Providers
Egress & Providers
LLM Gateway
OpenAI-compatible
LLM Gateway...
Provider Adapters
four upstreams
Provider Adapters...
Failover Router
weighted + health
Failover Router...
Usage Extractor
reads token counts
Usage Extractor...
Control
Control
Policy API
Go · REST
Policy API...
Policy Store
PostgreSQL 16
Policy Store...
Policy Bus
Kafka · compacted
Policy Bus...
Admin Console
React
Admin Console...
Accounting & Insight
Accounting & Insight
Usage Collector
at-least-once
Usage Collector...
Stream Aggregator
Apache Flink
Stream Aggregator...
Usage Ledger
ClickHouse
Usage Ledger...
Cost & Budget Marts
dbt models
Cost & Budget Marts...
Platform
Platform
Kubernetes
3 AZ per region
Kubernetes...
Identity & Secrets
Keycloak · Vault
Identity & Secrets...
Observability
OTel · Prom · Grafana
Observability...
GitOps Delivery
Argo CD · Rollouts
GitOps Delivery...
Layered Architecture
Layered Architecture
A layer calls only the layer below it. The one deliberate exception is Accounting, fed asynchronously from Decision and Egress and never called back by them.
A layer calls only the layer below it. The one deliberate exception is Accounting, fed asynchronously from Decision and Egress and never called back by them.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Layered Architecture What each layer is responsible for, and the one call direction that is allowed to break the rule. HTML page SVG draw.io
04
Data plane — one per region
Data plane — one per region
Edge
Edge
Envoy Gateway
ext_authz · mTLS
Envoy Gateway...
Admission Controller
tier + queue
Admission Controller...
Decision services
Decision services
limiterd
Go · 60 pods
limiterd...
llm-gateway
Go · 30 pods
llm-gateway...
Coordination state
Coordination state
Valkey Cluster
16 shards · 3 AZ
Valkey Cluster...
Reservation Reaper
sweeps expiries
Reservation Reaper...
Control plane — global
Control plane — global
Policy
Policy
policy-api
Go · REST
policy-api...
PostgreSQL
Patroni · 3 nodes
PostgreSQL...
policy.v1
Kafka · compacted
policy.v1...
Administration
Administration
Admin Console
React SPA
Admin Console...
Policy-as-code
Git + Argo CD
Policy-as-code...
Usage plane — global
Usage plane — global
Ingest
Ingest
usage-collector
Go · batched
usage-collector...
usage.v1
Kafka · 24 parts
usage.v1...
Process & serve
Process & serve
Flink Aggregator
1 m / 1 h / 1 d
Flink Aggregator...
ClickHouse
usage + cost marts
ClickHouse...
Grafana
tenant dashboards
Grafana...
Keycloak
OIDC
Keycloak...
Vault / OpenBao
provider keys
Vault / OpenBao...
LLM Providers
four upstreams
LLM Providers...
Check gRPC
Check gRPC
EVALSHA
EVALSHA
HTTPS
HTTPS
usage event
usage event
outbox relay
outbox relay
policy push
policy push
key lease
key lease
Container Architecture (C4 Level 2)
Container Architecture (C4 Level 2)
Interface / broker
Interface / broker
Application we own
Application we own
Data store
Data store
Queue / topic
Queue / topic
Security / platform
Security / platform
External / third party
External / third party
synchronous
synchronous
event / async
event / async
Only edges that carry a contract are drawn. Health probes, metric scrapes and trace exports are omitted — view 20 has them.
Only edges that carry a contract are drawn. Health probes, metric scrapes and trace exports are omitted — view 20 has them.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Container Architecture (C4 Level 2) The deployable units, which plane each belongs to, and the contracts between them. HTML page SVG draw.io
05
Traffic sources
Traffic sources
Native SDK
Go · Python · TS
Native SDK...
Envoy ext_authz
no app change
Envoy ext_authz...
OpenAI-compatible API
drop-in base_url
OpenAI-compatible API...
LangChain / LlamaIndex
callback middleware
LangChain / LlamaIndex...
Batch Scheduler
bulk tier
Batch Scheduler...
Platform
Platform
LLM Traffic Manager
authorize · meter · route
LLM Traffic Manager...
Dependencies and sinks
Dependencies and sinks
Azure OpenAI
REST + Entra
Azure OpenAI...
Anthropic Claude
Messages API
Anthropic Claude...
Google Gemini
Vertex AI
Google Gemini...
Mixtral on vLLM
OpenAI-compatible
Mixtral on vLLM...
Keycloak
OIDC / JWKS
Keycloak...
Vault / OpenBao
dynamic secrets
Vault / OpenBao...
ClickHouse
usage ledger
ClickHouse...
Prometheus
OTLP + scrape
Prometheus...
Data Lakehouse
Iceberg on MinIO
Data Lakehouse...
gRPC Check
gRPC Check
gRPC v3
gRPC v3
HTTPS
HTTPS
HTTPS
HTTPS
queued admission
queued admission
completions
completions
completions
completions
completions
completions
completions
completions
token check
token check
key lease
key lease
usage rows
usage rows
metrics
metrics
nightly export
nightly export
Integration Architecture — every interface, both directions
Integration Architecture — every interface, both directions
External / third party
External / third party
Interface / broker
Interface / broker
Application we own
Application we own
Security / platform
Security / platform
Data store
Data store
synchronous
synchronous
batch
batch
event / async
event / async
Four ways in, one contract. Every inbound path resolves to the same Check RPC, so a policy behaves identically whichever mode a team adopts.
Four ways in, one contract. Every inbound path resolves to the same Check RPC, so a policy behaves identically whichever mode a team adopts.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Integration Architecture Every interface in and out, with the protocol and cadence on each one. HTML page SVG draw.io
06
Request
Request
Authorize
Authorize
Execute
Execute
Observe actuals
Observe actuals
Reconcile
Reconcile
A · Inline proxy (default)
A · Inline proxy (default)
Envoy ext_authz
zero app change
Envoy ext_authz...
Check RPC
p99 < 10 ms
Check RPC...
Gateway calls provider
Gateway calls provider
Gateway parses usage block
Gateway parses usage block
Automatic commit
client cannot skip it
Automatic commit...
B · SDK / API
B · SDK / API
App calls /v1/authorize
App calls /v1/authorize
HTTP decision + request_id
HTTP decision + request_id
App calls provider directly
App calls provider directly
App reads provider usage
App reads provider usage
App calls /v1/commit
reaper covers crashes
App calls /v1/commit...
C · Queued bulk
C · Queued bulk
Job enqueued
priority BULK
Job enqueued...
Admission at dequeue
spare capacity only
Admission at dequeue...
Worker pool executes
Worker pool executes
Worker reports actuals
Worker reports actuals
Credit returned to pool
Credit returned to pool
Integration Modes — who closes the reconciliation loop
Integration Modes — who closes the reconciliation loop
Mode A is the default because the gateway sees the provider's own usage block, so reconciliation cannot be skipped by a misbehaving client.
Mode A is the default because the gateway sees the provider's own usage block, so reconciliation cannot be skipped by a misbehaving client.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Integration Modes Three ways to adopt the platform, and which of them can guarantee that reconciliation actually happens. HTML page SVG draw.io

Data

Where rate-limit state lives across three tiers, what the policy and usage model looks like, and how consumption reaches billing.
07
L1 · In-process — per limiter pod (RAM)
L1 · In-process — per limiter pod (RAM)
Lease Buckets
granted RPM / TPM slice
Lease Buckets...
Policy Cache
last-known-good
Policy Cache...
Negative Cache
denied scope, 200 ms
Negative Cache...
≈ 0.3 ms p99
92% of decisions
≈ 0.3 ms p99...
L2 · Shared coordination
L2 · Shared coordination
RPM / TPM Counters
windowed, TTL-scoped
RPM / TPM Counters...
Concurrency Semaphores
sorted set + TTL
Concurrency Semaphores...
Reservation Ledger
estimate held 120 s
Reservation Ledger...
Budget Counters
spend to date
Budget Counters...
≈ 1.5 ms p99
8% of decisions
≈ 1.5 ms p99...
L3 · Durable — system of record, never on the hot path
L3 · Durable — system of record, never on the hot path
PostgreSQL
policy + hierarchy
PostgreSQL...
ClickHouse
usage ledger
ClickHouse...
MinIO Archive
Iceberg, 7 years
MinIO Archive...
10–200 ms
0% of decisions
10–200 ms...
Cold pod: no lease yet
first call goes to L2
Cold pod: no lease yet...
Kafka policy.v1 + usage.v1
the only L3 → L1 path
Kafka policy.v1 + usage.v1...
refill every 250 ms
refill every 250 ms
committed usage
committed usage
outbox
outbox
policy push
policy push
budget rollup, 60 s
budget rollup, 60 s
Where Rate-Limit State Lives — three tiers, one hot path
Where Rate-Limit State Lives — three tiers, one hot path
Application we own
Application we own
Decision point
Decision point
Data store
Data store
Risk / gap
Risk / gap
Queue / topic
Queue / topic
synchronous
synchronous
event / async
event / async
Answer to design question 1: state lives in all three tiers, but authority lives only in L2 for counters and L3 for policy. L1 holds a bounded, expiring claim on L2.
Answer to design question 1: state lives in all three tiers, but authority lives only in L2 for counters and L3 for policy. L1 holds a bounded, expiring claim on L2.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Where Rate-Limit State Lives Design question 1, answered: three tiers, with authority in exactly one of them per kind of state. HTML page SVG draw.io
08
organisation
org_id PK
name
tier ENUM(ENT,PRO,FREE)
fail_mode ENUM(OPEN,LOCAL,CLOSED)
budget_usd_month
organisation...
team
team_id PK
org_id FK -> organisation
name
cost_centre
team...
principal
principal_id PK
team_id FK -> team
subject (OIDC sub)
api_key_hash
priority
principal...
provider
provider_id PK
name
region
global_rpm
global_tpm
health_state
provider...
model
model_id PK
provider_id FK -> provider
name
context_window
price_in_per_1k
price_out_per_1k
model...
policy
policy_id PK
scope_type ENUM(ORG,TEAM,USER,MODEL,PROVIDER)
scope_id
model_id FK -> model NULL
rpm
input_tpm
output_tpm
max_concurrency
algorithm ENUM(BUCKET,SLIDING)
version
effective_from
policy...
reservation
request_id PK
principal_id FK -> principal
model_id FK -> model
reserved_input
reserved_output
slot_held
expires_at
state ENUM(HELD,COMMITTED,SWEPT)
reservation...
decision_audit
decision_id PK
request_id
verdict ENUM(ALLOW,REJECT)
reason_code
limiting_scope
policy_version
decided_at
decision_audit...
usage_event
event_id PK
request_id FK -> reservation
input_tokens
output_tokens
latency_ms
status
cost_usd
occurred_at
usage_event...
budget_ledger
org_id FK -> organisation
period (month)
spend_usd
forecast_usd
updated_at
budget_ledger...
1 : N
1 : N
1 : N
1 : N
1 : N
1 : N
1 : N
1 : N
0 : N
0 : N
1 : N
1 : N
1 : 1
1 : 1
N : 1
N : 1
1 : N
1 : N
Policy and Usage Data Model
Policy and Usage Data Model
One policy row per scope, so a limit at any level is added or removed without a schema change. No prompt or completion text appears anywhere in this model.
One policy row per scope, so a limit at any level is added or removed without a schema change. No prompt or completion text appears anywhere in this model.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Policy and Usage Data Model How a limit at any level in the hierarchy is expressed without a schema change, and what is recorded about a completed request. HTML page SVG draw.io
09
Emit
Emit
Decision Events
verdict + reason
Decision Events...
Completion Events
actual tokens
Completion Events...
Transport
Transport
Kafka usage.v1
24 parts · 7-day retain
Kafka usage.v1...
Schema Registry
Apicurio · Avro
Schema Registry...
Aggregate
Aggregate
Flink Windows
1 m / 1 h / 1 d
Flink Windows...
Cost Calculator
price × tokens
Cost Calculator...
Idempotent Upsert
keyed on request_id
Idempotent Upsert...
Store
Store
Usage Ledger
ClickHouse · 400 d
Usage Ledger...
Cost Marts
dbt · per org/team
Cost Marts...
Cold Archive
Iceberg on MinIO
Cold Archive...
Serve
Serve
Tenant Dashboards
Grafana
Tenant Dashboards...
Billing Export
signed monthly CSV
Billing Export...
Budget Enforcer
60 s refresh
Budget Enforcer...
budget counters back to L2
budget counters back to L2
Usage Accounting — from decision to invoice
Usage Accounting — from decision to invoice
Application we own
Application we own
Queue / topic
Queue / topic
Data store
Data store
Security / platform
Security / platform
Interface / broker
Interface / broker
event / async
event / async
At-least-once transport with an idempotent upsert keyed on request_id. Billing reads the ledger, never the stream, so a replay cannot double-charge a tenant.
At-least-once transport with an idempotent upsert keyed on request_id. Billing reads the ledger, never the stream, so a replay cannot double-charge a tenant.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Usage Accounting How a completed request becomes a ledger row, a budget counter and eventually an invoice line, without ever being counted twice. HTML page SVG draw.io

Runtime

The hot path itself: how one decision is made, how five scopes are checked atomically, how tokens are reserved and reconciled, and how quota is shared across instances.
10
Application
Application
Envoy Gateway
Envoy Gateway
limiterd
limiterd
Valkey Shard
Valkey Shard
llm-gateway
llm-gateway
LLM Provider
LLM Provider
1. POST /v1/chat/completions
1. POST /v1/chat/completions
2. Check(tenant, model, 5k in, 2k out)
2. Check(tenant, model, 5k in, 2k out)
3. resolve scope chain from cached policy
3. resolve scope chain from cached policy
4. try local lease — exhausted
4. try local lease — exhausted
5. EVALSHA check_and_commit(keys)
5. EVALSHA check_and_commit(keys)
6. ALLOW + lease 40 req / 250 ms
6. ALLOW + lease 40 req / 250 ms
7. reserve 7 000 tokens + slot, TTL 120 s
7. reserve 7 000 tokens + slot, TTL 120 s
8. ALLOW request_id=req-123
8. ALLOW request_id=req-123
9. forward with request_id
9. forward with request_id
10. upstream completion
10. upstream completion
11. completion + usage block
11. completion + usage block
12. Commit(actual 5 800)
12. Commit(actual 5 800)
13. release 1 200 tokens + free slot
13. release 1 200 tokens + free slot
14. 200 OK
14. 200 OK
Authorization Hot Path — one request, p99 under 10 ms
Authorization Hot Path — one request, p99 under 10 ms
Steps 5 to 7 are skipped on roughly 92% of requests, where the local lease still has capacity. That is what buys the latency budget.
Steps 5 to 7 are skipped on roughly 92% of requests, where the local lease still has capacity. That is what buys the latency budget.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Authorization Hot Path One request from arrival to reconciliation, showing exactly which steps are skipped on the common case. HTML page SVG draw.io
11
Resolve
Resolve
Request Context
from JWT claims only
Request Context...
Scope Chain
5 keys, ordered
Scope Chain...
Organisation
Organisation
Org RPM / TPM
500 rpm · 2M tpm
Org RPM / TPM...
Org Budget
monthly USD cap
Org Budget...
Team
Team
Team RPM / TPM
share of org
Team RPM / TPM...
Principal
Principal
User RPM
10 req/s
User RPM...
User Concurrency
max in flight
User Concurrency...
Model
Model
Model RPM / TPM
per model policy
Model RPM / TPM...
Model Concurrency
20 in flight
Model Concurrency...
Provider
Provider
Provider Global RPM
protects upstream
Provider Global RPM...
Provider Health
breaker state
Provider Health...
Outcome
Outcome
ALLOW + reserve
request_id issued
ALLOW + reserve...
REJECT 429
reason + retry_after
REJECT 429...
BUDGET_EXCEEDED
BUDGET_EXCEEDED
PROVIDER_SATURATED
PROVIDER_SATURATED
Hierarchical Limit Evaluation — every scope must pass
Hierarchical Limit Evaluation — every scope must pass
Application we own
Application we own
Decision point
Decision point
Risk / gap
Risk / gap
failure / alternate
failure / alternate
Scopes are evaluated in a fixed order so the reason code is deterministic. The first failing scope names the rejection; retry_after comes from that scope's window.
Scopes are evaluated in a fixed order so the reason code is deterministic. The first failing scope names the rejection; retry_after comes from that scope's window.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Hierarchical Limit Evaluation Five scopes that must all pass, evaluated in a fixed order so the rejection reason is deterministic. HTML page SVG draw.io
12
Resolve keys
Resolve keys
Dry-run all limits
Dry-run all limits
Commit or abort
Commit or abort
Reserve
Reserve
Respond
Respond
limiterd (Go)
limiterd (Go)
Build key set
hash tag {org:acme}
Build key set...
Single EVALSHA
one round trip
Single EVALSHA...
Record request_id
Record request_id
ALLOW / REJECT
+ limiting scope
ALLOW / REJECT...
Tenant shard (Valkey)
Tenant shard (Valkey)
Org, team, user, model keys
same slot by design
Org, team, user, model keys...
Read every counter
no mutation yet
Read every counter...
INCR all or none
Lua is single-threaded
INCR all or none...
ZADD reservation
score = expiry
ZADD reservation...
Verdict + retry_after
Verdict + retry_after
Provider shard (Valkey)
Provider shard (Valkey)
Global provider key
different slot
Global provider key...
Read provider counter
Read provider counter
Compensating release
if tenant leg aborts
Compensating release...
Provider headroom
Provider headroom
Atomic Multi-Limit Commit — all limits, or none
Atomic Multi-Limit Commit — all limits, or none
Answer to design question 2: tenant scopes are made atomic by co-locating their keys on one slot; the provider scope cannot be, so it is a second leg with a compensating release.
Answer to design question 2: tenant scopes are made atomic by co-locating their keys on one slot; the provider scope cannot be, so it is a second leg with a compensating release.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Atomic Multi-Limit Commit Design question 2, answered: how five counters are checked and incremented all-or-nothing, and what happens to the one that cannot be. HTML page SVG draw.io
14
limiterd A
limiterd A
limiterd B
limiterd B
Valkey Shard
Valkey Shard
Policy Cache
Policy Cache
1. org acme: 500 rpm, algorithm=BUCKET
1. org acme: 500 rpm, algorithm=BUCKET
2. LEASE org:acme window=250 ms
2. LEASE org:acme window=250 ms
3. grant 40 of 125 in window
3. grant 40 of 125 in window
4. serve 40 decisions from RAM
4. serve 40 decisions from RAM
5. LEASE org:acme window=250 ms
5. LEASE org:acme window=250 ms
6. grant 25 — sized to observed demand
6. grant 25 — sized to observed demand
7. RENEW + return 6 unused
7. RENEW + return 6 unused
8. grant 55 — demand rising
8. grant 55 — demand rising
9. LEASE — window already exhausted
9. LEASE — window already exhausted
10. DENY, retry_after 0.18 s
10. DENY, retry_after 0.18 s
11. reject locally, no further round trips
11. reject locally, no further round trips
Quota Lease Protocol — how ten limiters share one quota
Quota Lease Protocol — how ten limiters share one quota
Answer to design question 5 on consistency: overshoot is bounded by one unreturned lease per pod per window — measured at 0.9% against a 500 rpm quota with 60 pods.
Answer to design question 5 on consistency: overshoot is bounded by one unreturned lease per pod per window — measured at 0.9% against a 500 rpm quota with 60 pods.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Quota Lease Protocol Design question 5 on consistency, answered: how sixty pods share one 500-rpm quota without each of them allowing 500. HTML page SVG draw.io
16
Request
Request
Requested Model
alias or exact
Requested Model...
Routing Policy
per tenant + model
Routing Policy...
Selection
Selection
Provider Selector
weighted + health
Provider Selector...
Residency Filter
EU data stays EU
Residency Filter...
Provider guards
Provider guards
Provider RPM / TPM
global counters
Provider RPM / TPM...
Circuit Breaker
3 fails / 2 s
Circuit Breaker...
Upstream 429 Feedback
adaptive throttle
Upstream 429 Feedback...
Primary route
Primary route
Azure OpenAI
PTU + pay-go
Azure OpenAI...
Anthropic Claude
Messages API
Anthropic Claude...
Fallback route
Fallback route
Google Gemini
Vertex AI
Google Gemini...
Mixtral on vLLM
self-hosted GPU
Mixtral on vLLM...
Outcome
Outcome
Response + usage
provider recorded
Response + usage...
503 provider_unavailable
retry_after from breaker
503 provider_unavailable...
breaker open
breaker open
quota exhausted
quota exhausted
Provider Limits, Routing and Failover
Provider Limits, Routing and Failover
Application we own
Application we own
Decision point
Decision point
External / third party
External / third party
Risk / gap
Risk / gap
failure / alternate
failure / alternate
Failover is opt-in per tenant policy. A tenant pinned to one provider for compliance reasons receives 503 rather than a silent reroute, and the policy records that choice.
Failover is opt-in per tenant policy. A tenant pinned to one provider for compliance reasons receives 503 rather than a silent reroute, and the policy records that choice.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Provider Limits, Routing and Failover How the platform keeps applications from overwhelming an upstream, and what it does when one is already saturated or down. HTML page SVG draw.io

Operations

How the service is deployed across regions, how policy reaches a running pod, how change is released safely, and what is watched.
17
Region EU-West · active
Region EU-West · active
Edge · 3 AZ
Edge · 3 AZ
L4 Load Balancer
MetalLB / cloud LB
L4 Load Balancer...
Envoy Gateway
9 pods
Envoy Gateway...
Kubernetes · data plane
Kubernetes · data plane
limiterd
60 pods · HPA on rps
limiterd...
llm-gateway
30 pods
llm-gateway...
Stateful · 3 AZ
Stateful · 3 AZ
Valkey Cluster
16 shards + replicas
Valkey Cluster...
PostgreSQL
Patroni · sync replica
PostgreSQL...
Usage plane
Usage plane
Kafka
6 brokers · KRaft
Kafka...
Flink
6 task managers
Flink...
ClickHouse
6 nodes · 2 replicas
ClickHouse...
Region US-East · active
Region US-East · active
Edge
Edge
Envoy Gateway
6 pods
Envoy Gateway...
Kubernetes · data plane
Kubernetes · data plane
limiterd
40 pods
limiterd...
llm-gateway
20 pods
llm-gateway...
Stateful
Stateful
Valkey Cluster
regional, not replicated
Valkey Cluster...
PostgreSQL
read replica
PostgreSQL...
Global services
Global services
Routing & control
Routing & control
GeoDNS + Anycast
latency routing
GeoDNS + Anycast...
Global Budget Reconciler
60 s, eventually consistent
Global Budget Reconciler...
Platform
Platform
Argo CD
GitOps, both regions
Argo CD...
Vault / OpenBao
HA, 5 nodes
Vault / OpenBao...
LLM Providers
regional endpoints
LLM Providers...
Self-hosted GPU Pool
vLLM · A100 × 16
Self-hosted GPU Pool...
primary
primary
secondary
secondary
streaming replication
streaming replication
budget sync
budget sync
private link
private link
Deployment Architecture — active/active, two regions
Deployment Architecture — active/active, two regions
Interface / broker
Interface / broker
Application we own
Application we own
Data store
Data store
Queue / topic
Queue / topic
Security / platform
Security / platform
External / third party
External / third party
synchronous
synchronous
event / async
event / async
Rate-limit counters are deliberately regional. A globally strict quota would put a cross-region round trip on the hot path; instead each region gets a share and the reconciler corrects drift every 60 s.
Rate-limit counters are deliberately regional. A globally strict quota would put a cross-region round trip on the hot path; instead each region gets a share and the reconciler corrects drift every 60 s.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Deployment Architecture Two active regions, three availability zones each, and the deliberate choice not to replicate rate-limit state between them. HTML page SVG draw.io
18
Author
Author
Platform Admin
Platform Admin
Admin Console
React
Admin Console...
Policy-as-code Repo
YAML, reviewed
Policy-as-code Repo...
Validate
Validate
policy-api
Go · REST
policy-api...
Guardrail Check
child ≤ parent quota
Guardrail Check...
Dry-run on Replay
24 h of traffic
Dry-run on Replay...
Persist
Persist
Policy Store
PostgreSQL · versioned
Policy Store...
Transactional Outbox
same commit
Transactional Outbox...
Publish
Publish
Outbox Relay
at-least-once
Outbox Relay...
policy.v1
Kafka · log-compacted
policy.v1...
Propagate
Propagate
limiterd Policy Cache
p99 < 2 s
limiterd Policy Cache...
Gateway Route Cache
same topic
Gateway Route Cache...
Verify
Verify
policy_version Gauge
per pod
policy_version Gauge...
Staleness Alert
fires above 60 s
Staleness Alert...
min version lag
min version lag
Policy Control Plane — from admin edit to live decision
Policy Control Plane — from admin edit to live decision
Person or role
Person or role
Application we own
Application we own
Decision point
Decision point
Data store
Data store
Queue / topic
Queue / topic
Security / platform
Security / platform
Risk / gap
Risk / gap
synchronous
synchronous
Answer to design question 5 on propagation. A compacted topic means a pod that restarts replays only the current policy set, so cold start does not depend on PostgreSQL being reachable.
Answer to design question 5 on propagation. A compacted topic means a pod that restarts replays only the current policy set, so cold start does not depend on PostgreSQL being reachable.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Policy Control Plane Design question 5 on propagation, answered: from an administrator's edit to a live decision, and how the delay is measured rather than assumed. HTML page SVG draw.io
19
Commit
Commit
Build
Build
Verify
Verify
Canary
Canary
Production
Production
limiterd service
limiterd service
PR + review
PR + review
Go build, SBOM, cosign
Go build, SBOM, cosign
Race + fuzz + 10k rps soak
Race + fuzz + 10k rps soak
Argo Rollouts 5%
SLO analysis gate
Argo Rollouts 5%...
Full rollout
auto-rollback on p99
Full rollout...
Lua limit scripts
Lua limit scripts
Script in repo
Script in repo
SHA pinned to release
SHA pinned to release
Golden-file limit tests
Golden-file limit tests
Shadow dual-run compare
Shadow dual-run compare
SCRIPT LOAD on all shards
SCRIPT LOAD on all shards
Policies & config
Policies & config
Policy-as-code PR
Policy-as-code PR
Schema + guardrail lint
Schema + guardrail lint
Dry-run on traffic replay
Dry-run on traffic replay
One canary tenant
One canary tenant
Published to policy.v1
Published to policy.v1
Infrastructure
Infrastructure
OpenTofu PR
OpenTofu PR
Plan + cost diff
Plan + cost diff
OPA policy checks
OPA policy checks
Apply to staging
Apply to staging
Apply via Argo CD
Apply via Argo CD
Delivery Pipeline — code, scripts, policy and infrastructure
Delivery Pipeline — code, scripts, policy and infrastructure
Lua scripts are versioned and rolled out separately from the binary, because a change to the limit algorithm is a behaviour change even when no Go code moved.
Lua scripts are versioned and rolled out separately from the binary, because a change to the limit algorithm is a behaviour change even when no Go code moved.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Delivery Pipeline Four things ship on independent cadences — service code, Lua scripts, policy and infrastructure — and each gets its own gate. HTML page SVG draw.io
20
Edge & admission
Edge & admission
Decision
Decision
Coordination
Coordination
Egress & providers
Egress & providers
Usage & cost
Usage & cost
Metrics
Metrics
Throughput
rps · shed · queue
Throughput...
Decision latency
p50 / p99 · verdicts
Decision latency...
Shard health
Lua p99 · lease hit
Shard health...
Provider health
latency · breaker · 429
Provider health...
Consumption
tokens/min · burn rate
Consumption...
Logs
Logs
Access log
no request body
Access log...
Decision audit
1% + all rejects
Decision audit...
Script errors
failover events
Script errors...
Provider errors
bodies redacted
Provider errors...
Ledger gaps
reconciliation
Ledger gaps...
Traces
Traces
Ingress span
Ingress span
Check span
scope resolution
Check span...
Valkey span
one per lease refill
Valkey span...
Upstream span
provider call
Upstream span...
Commit span
linked by request_id
Commit span...
SLOs & alerts
SLOs & alerts
Availability 99.99%
52 min / year
Availability 99.99%...
p99 < 10 ms
budget 4.3 min/mo
p99 < 10 ms...
Shard p99 < 1.5 ms
lease hit ≥ 90%
Shard p99 < 1.5 ms...
Failover < 5 s
trip to reroute
Failover < 5 s...
Staleness < 60 s
ledger lag < 5 min
Staleness < 60 s...
Observability — signal type against pipeline stage
Observability — signal type against pipeline stage
Every signal is emitted through OpenTelemetry and correlated by request_id, which is the same identifier the reservation ledger and the usage row carry.
Every signal is emitted through OpenTelemetry and correlated by request_id, which is the same identifier the reservation ledger and the usage row carry.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Observability and SLOs Every signal the brief asks for, placed against the stage that emits it, with the SLO that makes it actionable. HTML page SVG draw.io

Assurance

The trust boundary, how a tenant is proved, what happens when each dependency fails, and where the real scaling ceiling is.
21
Internet
Internet
Client Applications
tenant workloads
Client Applications...
Platform Administrators
Platform Administrators
Perimeter
Perimeter
WAF + DDoS Shield
L7 rules
WAF + DDoS Shield...
Envoy Gateway
TLS 1.3 termination
Envoy Gateway...
Keycloak
OIDC, realm per tenant
Keycloak...
Application zone
Application zone
limiterd
SPIFFE identity
limiterd...
llm-gateway
SPIFFE identity
llm-gateway...
policy-api
admin scope only
policy-api...
State & analytics zone
State & analytics zone
Valkey Cluster
ACL per service
Valkey Cluster...
PostgreSQL
row-level security
PostgreSQL...
ClickHouse
tenant-scoped views
ClickHouse...
Egress zone
Egress zone
Vault / OpenBao
dynamic provider keys
Vault / OpenBao...
Egress Proxy
FQDN allow-list
Egress Proxy...
Providers (untrusted)
Providers (untrusted)
Managed LLM Providers
Azure · Anthropic · Google
Managed LLM Providers...
Self-hosted vLLM
private subnet, no egress
Self-hosted vLLM...
HTTPS + OIDC bearer
HTTPS + OIDC bearer
JWKS validation
JWKS validation
mTLS, SPIFFE SVID
mTLS, SPIFFE SVID
TLS + ACL
TLS + ACL
TLS, RLS by tenant
TLS, RLS by tenant
SVID-authenticated key lease
SVID-authenticated key lease
prompt in transit, never stored
prompt in transit, never stored
TLS 1.3, allow-list
TLS 1.3, allow-list
SSO + step-up MFA
SSO + step-up MFA
Security Trust Zones
Security Trust Zones
External / third party
External / third party
Person or role
Person or role
Security / platform
Security / platform
Interface / broker
Interface / broker
Application we own
Application we own
Data store
Data store
synchronous
synchronous
The limiter is deliberately outside the prompt data path. It receives token counts and scope claims, so a compromise of the decision plane exposes no customer content.
The limiter is deliberately outside the prompt data path. It receives token counts and scope claims, so a compromise of the decision plane exposes no customer content.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Security Trust Zones Six zones by decreasing exposure, and the one structural property that limits the blast radius of a decision-plane compromise. HTML page SVG draw.io
22
Client App
Client App
Keycloak
Keycloak
Envoy Gateway
Envoy Gateway
limiterd
limiterd
llm-gateway
llm-gateway
Vault
Vault
Provider
Provider
1. client_credentials, tenant realm
1. client_credentials, tenant realm
2. JWT: org, team, sub, tier
2. JWT: org, team, sub, tier
3. request + Bearer token
3. request + Bearer token
4. verify signature, cached JWKS
4. verify signature, cached JWKS
5. ext_authz Check over mTLS
5. ext_authz Check over mTLS
6. scope keys from claims, never from body
6. scope keys from claims, never from body
7. ALLOW + request_id
7. ALLOW + request_id
8. forward, claims in headers
8. forward, claims in headers
9. lease provider key for this tenant
9. lease provider key for this tenant
10. credential, TTL 15 min
10. credential, TTL 15 min
11. upstream call
11. upstream call
12. completion + usage
12. completion + usage
13. response, prompt not persisted
13. response, prompt not persisted
14. 401 on tenant mismatch
14. 401 on tenant mismatch
Identity and Tenant Isolation — proving who is asking
Identity and Tenant Isolation — proving who is asking
A tenant cannot spend another tenant's quota because the scope key is derived from signed claims, not from any field the caller supplies in the request body.
A tenant cannot spend another tenant's quota because the scope key is derived from signed claims, not from any field the caller supplies in the request body.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Identity and Tenant Isolation How a tenant is proved, and why one tenant cannot spend another's quota even if it asks to. HTML page SVG draw.io
23
Fault
Fault
Valkey shard lost
Valkey shard lost
Policy bus lag
Policy bus lag
PostgreSQL outage
PostgreSQL outage
Provider outage
Provider outage
Detection
Detection
Health probe
3 fails in 2 s
Health probe...
Consumer lag alarm
over 60 s
Consumer lag alarm...
Degradation
Degradation
Local bucket fallback
quota ÷ pod count
Local bucket fallback...
Stale-but-serving policy
last-known-good
Stale-but-serving policy...
Read-only control plane
no policy edits
Read-only control plane...
Provider failover
if tenant permits
Provider failover...
Tenant fail policy
Tenant fail policy
HIGH → FAIL OPEN
availability wins
HIGH → FAIL OPEN...
STANDARD → LOCAL
bounded overshoot
STANDARD → LOCAL...
FREE → FAIL CLOSED
cost wins
FREE → FAIL CLOSED...
Blast radius
Blast radius
Overshoot ≤ 15%
one shard, one window
Overshoot ≤ 15%...
Hot path unaffected
PostgreSQL is not on it
Hot path unaffected...
Free tier sees 429
paying tenants do not
Free tier sees 429...
Recovery
Recovery
Shard rejoin + resync
counters rebuilt from TTL
Shard rejoin + resync...
Reaper sweep
frees leaked holds
Reaper sweep...
Ledger replay
Kafka 7-day retention
Ledger replay...
breaker
breaker
Failure Modes and the Degradation Ladder
Failure Modes and the Degradation Ladder
Risk / gap
Risk / gap
Decision point
Decision point
Application we own
Application we own
failure / alternate
failure / alternate
Answer to design question 4: the failure mode is a per-tenant policy field, not a global constant, because the right answer differs by what the tenant is paying for.
Answer to design question 4: the failure mode is a per-tenant policy field, not a global constant, because the right answer differs by what the tenant is paying for.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Failure Modes and the Degradation Ladder Design question 4, answered: fail open, fail closed or fall back locally — and why that is a tenant policy field rather than a global constant. HTML page SVG draw.io
24
Tier 1 · Routing
Tier 1 · Routing
Affinity
Affinity
GeoDNS + Anycast
region by latency
GeoDNS + Anycast...
Maglev Hash
on org_id header
Maglev Hash...
Why it matters
Why it matters
Affinity raises lease hit rate
78% → 92%
Affinity raises lease hit rate...
Tier 2 · Decision pods
Tier 2 · Decision pods
limiterd pools
limiterd pools
Pool A
orgs 0–85
Pool A...
Pool B
orgs 86–170
Pool B...
Pool C
orgs 171–255
Pool C...
Unit economics
Unit economics
1 pod ≈ 18k dec/s
4 vCPU · 2 GiB
1 pod ≈ 18k dec/s...
Tier 3 · Coordination shards
Tier 3 · Coordination shards
Valkey Cluster
Valkey Cluster
Shards 0–7
hash tag {org:id}
Shards 0–7...
Shards 8–15
replica per AZ
Shards 8–15...
Unit economics
Unit economics
1 shard ≈ 90k Lua/s
8% of traffic reaches it
1 shard ≈ 90k Lua/s...
Tier 4 · Hot tenant fan-out
Tier 4 · Hot tenant fan-out
Sub-sharding
Sub-sharding
Split above 5k rps
{org:acme#0..7}
Split above 5k rps...
Merge on cool-down
5 min below threshold
Merge on cool-down...
Cost of the split
Cost of the split
Quota divided N ways
overshoot rises to 3%
Quota divided N ways...
Single org on one slot
the real ceiling, not total rps
Single org on one slot...
sticky by org
sticky by org
lease refill only
lease refill only
hot key detected
hot key detected
mitigated
mitigated
Scaling to One Million Decisions per Second
Scaling to One Million Decisions per Second
Interface / broker
Interface / broker
Decision point
Decision point
Application we own
Application we own
Data store
Data store
Risk / gap
Risk / gap
synchronous
synchronous
event / async
event / async
failure / alternate
failure / alternate
Answer to design question 6. Total throughput scales linearly with pods and shards; the binding constraint is a single organisation's keys landing on one Redis slot, which tier 4 exists to relieve.
Answer to design question 6. Total throughput scales linearly with pods and shards; the binding constraint is a single organisation's keys landing on one Redis slot, which tier 4 exists to relieve.
v 1.0 · owner Data & AI Global Practice
v 1.0 · owner Data & AI Global Practice
Text is not SVG - cannot display
Scaling to One Million Decisions per Second Design question 6, answered: what scales linearly, what does not, and where the real ceiling actually sits. HTML page SVG draw.io
Open svg/<view>.svg or drawio/<view>.drawio in draw.io Desktop or at app.diagrams.net to edit. The SVG carries the diagram inside it, so it is both the picture and the source. This folder is self-contained — copy it whole and every link still resolves.