HLDArena
HLD-134·Caching & Edge
Easy · 500 pts

LLM Semantic Prompt Cache & Cost-Saving AI Gateway

Design an AI gateway caching tier that serves exact prompt-hash and high-similarity semantic hits in milliseconds to avoid redundant GPU inference calls across FAQ, support, and coding assistants.

Max p99
≤ 35 ms
Availability
≥ 99.5%
Budget
≤ $3,050

Functional Requirements

  • FR-1POST /v1/prompt-cache/lookup — Computes normalized prompt hash + embedding lookup and returns cached completion when similarity >= threshold.
  • FR-2PUT /v1/prompt-cache/entries/{prompt_hash} — Stores verified model completion, token counts, and tenant-scoped TTL.
  • FR-3DELETE /v1/prompt-cache/tenants/{tenant_id} — Purges stale cached completions when a tenant updates system prompts or knowledge docs.
  • FR-4Must coalesce identical concurrent cache misses so viral prompts do not trigger duplicate upstream model calls.

Workload Profile

Steady Assistant Traffic20,000 Cache Lookup Read RPS / 2,000 Completion Store Write RPS
Product Launch FAQ Spike56,000 Lookup Read RPS / 5,200 Write RPS
Active Working Set16 GB hot prompt hashes, quantized embeddings & completions
Traffic DistributionHigh Zipfian skew on common onboarding & docs queries

Consistency Model

Bounded eventual invalidation (< 5s) on tenant prompt-version bumps; strict tenant_id namespace isolation.

Relevant practice for

Click an item in Inventory above, or press B to add a component, double-click to name, C to connect.

Design Write-up

Write under ### Architecture for Diagram to take that up directly

Compulsory section · if not written yet, Diagram reads from the start of your write-up.
Architecture: required·FRs mentioned: 0/4·0 boxes · 0 edges
0 words
Hidden Cases #4–#7 run automatically on Submit
Case 1: Smoke & API ContractInput Workload
Read RPS
2,000 rps
Write RPS
200 rps
Key Distribution
Uniform (Low Skew)
Chaos Fault
None (Healthy Cluster)
Expected Pass CriteriaASSERTIONS
• Tail Latency: p99 ≤ 70 ms
• Availability: ≥ 99.5%
Valid end-to-end Client → Compute → Storage topology