Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Zero-Trust Multi-Service Delegated Authorization
Gateway with Offline Token Attenuation.

Replace 4-hop OAuth2 token-exchange calls with Biscuit Ed25519 capability tokens, 5s verification caches, bounded Datalog evaluators, and 3.2 MB Pub/Sub revocation sets.
Start the journey5 stages· Last modified Nov 25, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When multi-hop microservices or AI agents must narrow user permissions at 100K RPS without bottlenecking a central Identity Provider, issue Biscuit root tokens at the edge, attenuate caveats offline per hop, and verify locally with a 5-second cache and bounded revocation set.

TL;DR30-second simplified summary
▾

In a 100K RPS microservice and AI-agent platform where requests fan out across 4–6 internal hops, calling a central Authorization / IdP service on every hop to exchange narrowed JWTs adds 4–6x load to the IdP and turns it into a latency bottleneck.

A Zero-Trust Delegated Authorization Gateway issues root Biscuit capability tokens at the edge, lets intermediate services and AI agents attenuate tokens offline with narrow Datalog caveats (op=read, resource=..., exp < now + 60s), and verifies tokens locally at every downstream service using the edge public key + a 5-second cached Datalog evaluation.

Emergency revocations propagate via compact revocation_id push streams (Redis Pub/Sub -> local in-memory Bloom/HashSet), bounded by Datalog execution step limits to prevent adversarial token CPU DoS.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Decentralized Capability Tokens
Macaroons and Biscuit let holders append restrictions offline without being able to remove earlier ones.
SPIFFE / mTLS Workload Identity
Workload identity proves which service is calling, while capability tokens prove what user permissions it carries.
Full walkthrough · 5 stages
01
R · REQUIREMENTS & SCENARIOfoundation

Eliminating 5-Hop IdP Bottlenecks & Confused Deputies at 100K RPS.

Why this matters: Establish the multi-hop delegation scenario, zero-IdP-hop latency goal, and emergency revocation requirements.

Suppose a user asks your platform's AI orchestrator to summarize a private Drive folder. The request traverses API Gateway -> Agent Planner -> Document Fetcher -> Storage Service. Forwarding a broad OAuth2 JWT lets a prompt-injected Document Fetcher delete files; calling OAuth2 Token Exchange on every hop adds 40–80 ms and crashes the IdP during traffic spikes.

Functional & Non-Functional Targets:

  • 100K edge RPS (~400K internal downstream verifications/sec across 4 hops).
  • Offline attenuation at every hop with zero synchronous IdP calls on the hot path.
  • <2 ms p99 local token verification + Datalog check.
  • <5s emergency revocation propagation for compromised root sessions.
R · DELEGATED AUTH TOPOLOGY

Public-Key Edge Verification + Offline Multi-Hop Attenuation

Root Auth IssuerMints Block 0…Edge GatewayRevocation + VerifyAgent / WorkerAppends Offline CaveatStorage ServiceDatalog + PubKey CheckRoot PubKey + Revoke StreamRoot BiscuitAttenuated Biscuit (0 IdP calls)

Services attenuate Biscuit tokens offline and verify downstream using only the issuer's public key.

02
E · ESTIMATIONS & CPU PHYSICSfoundation

Sizing Ed25519 Verification CPU & Revocation Set Memory.

Why this matters: Calculate exact CPU cores needed for 400K Ed25519 verifications/sec and how a 5s local verification cache cuts CPU by 10x.

Illustrative CPU Math: At 100K edge RPS × 4 hops = 400,000 token verifications/sec cluster-wide. A 3-block Biscuit Ed25519 verification takes ~150–200 us on one core (~5,000–6,500 verifications/sec/core). Without caching, 400K/s requires ~65–80 dedicated CPU cores just for signature math!

Caching verified (sha256(raw_token), policy_hash) -> allow/deny in a 5-second process-local LRU (bounded to min(5s, token_ttl_remaining)) absorbs repeated multi-call bursts from the same agent session—cutting CPU by ~5–10x in fan-out workloads (exact hit rate depends on per-request token reuse).

E · CPU & MEMORY SIZING

Cutting 400K/s Ed25519 Verification Overhead with 5s Local Caching

400K/s Raw Verify
200 us / 3-Block Token
~80 CPU Cores Burned
5s Verify LRU
Keyed by sha256(token)
<10 us Cache Hit
Revocation Set
100K Active IDs x 32B
3.2 MB RAM / Pod

Short-lived local verification caching and 3.2 MB revocation sets keep p99 auth latency under 2 ms.

03
S+H+A · SCHEMA, REVOCATION & API CONTRACTSintermediate

Revocation Stream, Datalog Policy Facts & Fail-Closed HTTP 401/403.

Why this matters: Define the token block schema, revocation push stream, and explicit HTTP error semantics.

Every Biscuit block carries a unique revocation_id (SHA256(block_signature)). When a user clicks 'Sign out everywhere' or an API key is compromised, the Issuer writes (revocation_id, expires_at) to PostgreSQL and broadcasts it over Redis Pub/Sub.

API Contract:

  • 401 Unauthorized: Invalid Ed25519 signature, malformed block, expired ttl, or revocation_id hit.
  • 403 Forbidden: Signature valid, but Datalog check if policy fails (e.g., op=write attempted on op=read attenuated token).
  • 400 Bad Request: Token exceeds max_blocks = 8 or Datalog max_facts = 256 (anti-DoS cap).
A · REVOCATION & VERIFY FLOW

Hydrated Revocation Set + Fail-Closed Datalog Enforcement

Agent WorkerStorage GuardRedis Revoke Stream1. Push revocation_id (TTL 1h)2. GET /reports/q4 (AttenuatedBiscuit)3. Check Revoke Set -> Ed25519 -> Datalog4. 403 if write attempted; 200 onread

Local revocation sets, Ed25519 verification, and Datalog policy evaluation execute in <2 ms without IdP calls.

Interactive Visual Simulation

Multi-Hop Delegated Auth & Emergency Revocation

edge

Edge Gateway

Mints / Attenuates

1. Root Biscuit
agent

AI Agent

Adds read + 60s

2. Attenuated Token
store

Storage API

Revoke + Datalog

blocks

2

caveat

op=read, ttl=60s

idp_calls

0

Delegate Narrow TokenHealthy
AI Agent narrows the token offline to read-only for 60s before invoking Storage API.
04
D · DETAILED DESIGN & DECISIONintermediate

Datalog DoS Bounds, Key Rotation & Safe Verifier Middleware.

Why this matters: Protect Datalog evaluators against CPU exhaustion bombs and handle multi-key Ed25519 rotation cleanly.

Because any intermediate caller can append Datalog blocks, an adversarial caller could craft a 50-block token with recursive rules designed to stall the verifier's CPU.

MAX_BLOCKS = 8
MAX_TOKEN_BYTES = 4096

def verify_biscuit_middleware(raw_token: bytes, pubkeys: dict[str, bytes], revoke_set: set[bytes], evaluator) -> dict:
    if not raw_token or len(raw_token) > MAX_TOKEN_BYTES:
        return {'allow': False, 'status': 400, 'reason': 'Token size exceeds 4KB cap'}
    parsed = evaluator.parse(raw_token)
    if len(parsed.blocks) > MAX_BLOCKS:
        return {'allow': False, 'status': 400, 'reason': 'Block chain exceeds depth 8'}
    if any(b.revocation_id in revoke_set for b in parsed.blocks):
        return {'allow': False, 'status': 401, 'reason': 'Block revoked'}
    pk = pubkeys.get(parsed.root_key_id)
    if not pk or not evaluator.verify_signatures(parsed, pk):
        return {'allow': False, 'status': 401, 'reason': 'Invalid signature or unknown key_id'}
    if not evaluator.run_datalog(parsed, max_facts=256, max_iterations=100, timeout_ms=2):
        return {'allow': False, 'status': 403, 'reason': 'Policy denied or budget exceeded'}
    return {'allow': True, 'status': 200}
Engineering Decision Framework
Problem
Untrusted or compromised intermediate agents could craft huge Biscuit chains or need emergency revocation.
Naive Solution
Allow unbounded Biscuit blocks and omit revocation checks to keep verification 100% stateless.
Why It Fails
Adversarial tokens trigger Datalog CPU DoS, and stolen 1-hour root tokens remain valid until expiry.
Alternatives
Pure stateless short-TTL (30s) tokens vs. 1h tokens + bounded Datalog + compact revocation stream.
Engineering Decision
Enforce 4 KB / 8-block / 2 ms Datalog caps plus a 3.2 MB Pub/Sub revocation set hydrated from DB on boot.
Trade-Offs
Adds ~3 MB RAM and a 1–5s revocation propagation window in exchange for 1h UX and DoS immunity.
Decision Exercise · Make the Call

A Storage pod restarts during a traffic spike and hasn't finished downloading the active revocation_id snapshot from PostgreSQL yet. A request arrives with a valid Ed25519 Biscuit. What should the pod do?

05
E+D · EVALUATION, DURABILITY & GLOSSARYadvanced

Trade-Offs, Assumptions, Limitations & Glossary.

Why this matters: Evaluate when capability tokens beat OAuth2 JWTs, document revocation propagation bounds, and define core terms.

Assumptions & Limitations

  • Propagation Lag: Pub/Sub revocation updates propagate in ~1–5s; if a Redis Pub/Sub disconnect occurs, pods fall back to periodic 10s DB delta polls and fail closed if stale beyond max_revoke_staleness.
  • Clock Skew: Time-bounded caveats (ttl=60s) assume NTP clock skew under 1–2s across services.
  • When NOT to Use: Simple single-hop APIs without delegation are simpler with standard OAuth2 JWTs.

Concise Glossary

  • Offline Attenuation: Appending restrictive caveats locally without contacting the issuer.
  • Biscuit: Asymmetric Ed25519 capability token with an embedded bounded Datalog policy engine.
  • Revocation ID: Deterministic per-block identifier (SHA256(sig)) used to blacklist compromised tokens.
  • SPIFFE SVID: Short-lived mTLS workload identity certificate authenticating service-to-service callers.
  • Fail Closed: Rejecting requests (401/503) whenever policy, key, or revocation state is unknown or unavailable.
D · RESILIENCE & GUARDRAILS

Readiness Hydration, Pub/Sub Fallback & Datalog DoS Caps

Boot HydrationLoad Revokes Before ReadyPub/Sub + 10s PollBounded Revoke Lag4KB / 8-Block CapBlock Datalog CPU DoS

Boot-time revocation hydration, 10s DB poll fallbacks, and 4 KB/8-block caps harden delegated auth at 100K RPS.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 4
Score: 0/4

Why does caching verified Biscuit evaluations for 5 seconds (`sha256(raw_token)`) cut CPU from ~80 cores to ~8–16 cores in a 400K/s fan-out?

Recommended Learning Flow