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

Design an Enterprise RAG
& LLM Inference Gateway.

Design a multi-tenant Enterprise RAG & LLM Gateway serving 2,000 QPS with sub-400ms Time To First Token (TTFT), strict tenant ACL enforcement, semantic caching, and token-aware rate limiting.
Start the journey2 stages
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

To keep serving pipelines predictable under bursty prompts, fast TTFT, zero ACL leaks, and predictable token spend.

TL;DR30-second simplified summary
▾

The design partitions state, bounds tail latency, and isolates failure domains.

Fast TTFT, zero ACL leaks, and predictable token spend.

Full walkthrough · 2 stages
01
SYSTEM-DESIGN · STAGE 01L4 · FUNDAMENTALS

ACL-filtered Hybrid Retrieval & Reranking.

Combine dense HNSW vector search with sparse BM25 lexical search using Reciprocal Rank Fusion (RRF), filtering strictly by the user's document ACLs before ranking. Read more on how Input & Output Tokens shape prompt budgets.

ChoiceWhat it buysWhat it costs
Semantic Cache in RedisSub-20ms cache hits for recurring queriesMust key cache by `(tenant_id, acl_group)` to prevent cross-tenant data leaks

Insight 1

Enforce tenant/role ACL filters inside the vector index metadata filter—never filter only after retrieving Top-K.

Insight 2

Use a lightweight cross-encoder reranker to narrow Top-50 hybrid hits down to the 5 sharpest chunks.

02
SYSTEM-DESIGN · STAGE 02L5 · APPLIED DESIGN

Token Budgeting, Prefix Caching & Rate Limiting.

Track token-per-minute (TPM) quotas in Redis alongside request-per-minute limits, and place static system prompts at index 0 so the LLM engine reuses KV prefix caches.

Insight 1

Reserve max_tokens for output before fitting retrieved chunks into the context window.

Insight 2

Stream responses over SSE so users perceive low latency even when Decode takes several seconds.

Cross-Tenant Semantic Cache Leak

User B hits a cached answer generated from User A's confidential document.

Put it together · Synthesis

Put the Enterprise RAG Gateway together

Unite [Redis](/domains/redis) semantic/token rate limiting, ACL-enforced hybrid retrieval, and KV-cache-friendly prompt assembly for [LLM](/domains/llm) serving.

A candidate architecture, not a universal answer

Reference Topology & Execution Flow

Step 1
Step 2
Step 3
  1. Check tenant-scoped semantic cache and TPM token bucket in Redis.
  2. Run ACL-filtered Hybrid Search (Dense + BM25) and rerank to Top-5 chunks.
  3. Assemble prompt with static prefix first and stream tokens via SSE.
Fast TTFT, zero ACL leaks, and predictable token spend.
Interview Readiness Check

Fast TTFT, zero ACL leaks, and predictable token spend.

Walk through bottlenecks, back-of-the-envelope math, and failure recovery.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Practice Check

Test your understanding

Question 1 of 1

Why does placing request_timestamp at the very beginning of a 3,000-token system prompt hurt latency and cost?

Recommended Learning Flow