By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
You're building an AI assistant for a large organization that needs to answer employee questions from internal documents, create IT tickets, and enforce document access controls. The challenge is making it work at scale—handling thousands of concurrent users, staying within a budget, and keeping it secure and auditable. This is a real constraint problem, not a demo.
Before you draw a single box, estimate your load and cost. For a 20,000-employee company where each person asks 5 questions a day, that's 100,000 requests daily. Most of those will land in an 8-hour window, which means you're looking at roughly 2.8 requests per second on average, spiking to 8 per second at peak.
20,000 daily users x 5 questions = 100,000 requests/day
80% in an 8-hour window: 80,000 / 28,800 s = ~2.8 req/s average
peak ~3x average = ~8 req/s
latency ~6 s per answer -> 8 x 6 = ~50 requests in flight at peak
tokens/request: 800 system + 1,500 retrieved + 700 history = 3,000 in
400 out
price (example): $3 in / $15 out per million tokens
cost/request = 0.009 + 0.006 = $0.015
x 100,000 x 30 = $45,000 / month (before optimization)That cost number—$45,000 per month before optimization—is what forces the real design decisions. It tells you immediately that you cannot afford to send every question to a large model, cache nothing, or retrieve huge amounts of context per request. The numbers make the trade-offs visible.
The architecture needs to enforce permissions at retrieval time, not after the model generates an answer. This means your hybrid search (vector plus keyword indexes) applies an ACL filter inside the query itself. Never retrieve a document and then filter it out based on the user's permissions after the LLM has already processed it.
Employee ─ SSO ─▶ API gateway (auth, per-user token limits)
│
▼
Orchestrator (workflow, max 6 steps, $ cap per request)
│
┌─────────────────┼──────────────────────┬─────────────────┐
▼ ▼ ▼ ▼
Semantic + Retrieval Ticket tools Memory store
prompt cache hybrid search (read/create; (per-user
(FAQ hits) + ACL filter + rerank approval to preferences)
from vector+keyword idx close/modify)
│
▼
LLM GATEWAY ─ router small 80% / large 20% ─ fallback
│
▼
Output guardrails (PII, citations, injection signals)
│
stream SSE to client ───▶ traces · cost · eval samplingStreaming responses over Server-Sent Events keeps the user experience responsive while you handle the orchestration behind the scenes. Ticket creation happens synchronously within the workflow, protected by an idempotency key so retries don't create duplicates. A shared session store and per-user memory handle state without forcing each API pod to keep it locally.
Route 80% of traffic—routine HR and IT FAQs—to a small model. Send the harder questions, the ones where confidence is low or multiple steps are needed, to a larger one. If the small model costs one-fifth as much, your cost per request drops from $0.015 to roughly $0.0066.
Prompt caching handles the stable parts: your system prompt and tool definitions stay the same across requests. Put those first in the cache key, then the user's question last. That way the ~800 tokens of overhead get cached and reused. Semantic caching works only for public company-wide FAQs; never cache personalized or permissioned answers across users.
When the LLM provider rate-limits you, back off with jitter, then try a fallback region or model, then return a graceful error. If your vector index gets slow, time out and fall back to keyword search only, but flag the confidence as lower. Treat all retrieved text as untrusted: ticket tools are scoped to what the user can do, and ticket creation requires confirmation.
Runaway agent loops get stopped with hard limits on steps, tokens, and time. Set a circuit breaker that trips if a single request's cost goes anomalous. Keep your document index fresh by re-indexing on change events and deleting vectors when sources are removed.
Build a 100-question test set from real help-desk tickets. Score each answer on groundedness, correctness, and citation accuracy. Run a canary with one department first, watching quality, latency, and cost per request. Every week, pull the thumbs-down answers from production and add them to your test set so you catch regressions early.
Notice the pattern: estimate first, draw the boxes second, then attack your own design with 'what if this fails?' and 'what if this is abused?'
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.