← All mindmapsMAIN TOPIC · 14 / 14AI System Design
Scalable inference, RAG architecture and system tradeoffs
Explore full topic ↗ Readable revision notes (19 concepts)
The same content as the visual sheet, optimized for mobile and assistive technology.
01 · Requirements
- Define task, quality target, traffic and latency SLO
- Estimate peak QPS, tokens/request and concurrency
- Clarify privacy, budget and availability constraints
02 · High-level architecture
- Gateway authenticates and rate-limits
- Router selects model/retrieval; worker serves request
- Store metadata, logs and artifacts separately
03 · Capacity & latency
- Little's law: L=λW under steady-state assumptions
- Latency = queue + compute + network overhead
- Track p50/p95/p99, TTFT and tokens/sec
04 · Inference optimization
- Dynamic batching raises throughput with queue tradeoff
- KV cache, quantization, model routing
- GPU memory: weights + activations + KV + overhead
05 · Scaling & resilience
- Horizontal replicas; autoscale with workload metrics
- Backpressure and bounded queues prevent overload
- Circuit breaker, timeout, retries, fallback; avoid retry storms
06 · RAG system architecture
- Ingestion → versioned index; retrieval at request time
- ACL filters, reranker, context budget, citations
- Incremental reindex; handle stale/deleted documents
07 · Caching & consistency
- Exact cache keys include version, permissions and context
- Semantic cache can return mismatched answers; evaluate
- Invalidate on data/model change; avoid cross-tenant leakage
08 · Evaluation & operations
- Offline golden set; online quality samples
- Monitor errors, drift, throughput and cost per request
- Canary deploy; rollback; incident runbooks
09 · Design interview checklist
- Explain alternatives and bottlenecks, not just boxes
- Threat model, retention, encryption, least privilege
- Quantify tradeoffs; revisit assumptions under load
10 · Requirements & capacity math
- Define availability, p95 latency, quality, max context and privacy constraints.
- QPS=queries/sec; token throughput=QPS×mean output tokens (steady demand).
- Little's law L=λW; queue grows if arrival exceeds service capacity.
11 · Inference service architecture
- Gateway auth/rate limit; router selects model/region/priority.
- Worker hosts model and tokenizer; cache, logs and metadata isolated.
- Admission control prevents GPU OOM; fail fast when saturated.
12 · Latency breakdown & SLO
- TTFT includes queue/prefill; inter-token latency measures streaming pace.
- End-to-end includes generated length; measure p50/p95/p99 not mean only.
- Set per-stage latency budgets and load test realistic distributions.
13 · GPU memory & batching
- Weights ≈ parameters×bytes per weight (excluding overhead).
- KV cache ≈ 2×layers×seq×KV heads×head dim×bytes per active sequence.
- Continuous batching improves utilization; longer queues raise tail latency.
14 · Caching & routing
- Exact/prefix caching reduces repeated work; semantic cache risks wrong matches.
- Scope cache by tenant/ACL/model/data version; invalidation on change.
- Route easy requests to smaller model; evaluate quality and fallback costs.
15 · Horizontal scaling & overload
- Scale on queue depth, GPU utilization, latency and token throughput.
- Cold starts/model loading costly; maintain warm capacity for peaks.
- Bounded queue, backpressure, priority and load shedding; avoid retry storms.
16 · Reliability patterns
- Timeout per dependency; jittered retries with budget and idempotency.
- Circuit breaker opens when failing; half-open probe before reset.
- Fallback smaller model/cached safe response or graceful error; communicate limits.
17 · Production RAG design
- Ingest asynchronously; chunk metadata and ACL; version embeddings/index.
- At query: authorize, retrieve hybrid, rerank, assemble context and citations.
- Handle stale docs/deletion, injection, insufficient evidence and index failover.
18 · Data/storage & consistency
- SQL for metadata/transactions; object store for artifacts; ANN for retrieval.
- Queues for asynchronous work; outbox/idempotent consumer for durable events.
- Replication/backup, tenant partitioning and retention; choose consistency per operation.
19 · Evaluation, cost & security
- Golden eval + live quality sampling; monitor regressions by traffic slice.
- Cost per request includes tokens, GPU time, retrieval and tools.
- Threat model, access checks, encryption, PII retention; canary + rollback.
References & further study
Original schematics illustrate concepts, not measured data. Review these references for full derivations and implementation details.