SDE & MLE Prep

LLM Inference Serving (ChatGPT-like)

Requirements: chat completions with streaming tokens, low time-to-first-token (TTFT), high throughput on expensive GPUs, multiple models, rate limits per user/tier, conversation history.

client --SSE stream--> API gateway (auth, quotas, rate limits)
                           -> router (model, region, load) -> inference cluster (GPU pods)
                                                                continuous batching scheduler
                                                                prefill -> decode loop (KV cache in GPU memory)
                           <- tokens streamed back as generated
side services: conversation store, safety filters (input/output), prompt cache, usage metering/billing, eval logging

Deep dives

  • Metrics: TTFT (prefill-bound), inter-token latency / tokens per second (decode, memory-bandwidth-bound), cost per 1M tokens, GPU utilization.
  • Batching: continuous (in-flight) batching; separate or chunked prefill to protect decode latency; paged KV cache (vLLM) to avoid fragmentation.
  • Scaling the model: tensor parallelism within a node, pipeline parallelism across nodes; quantization (FP8/INT4); speculative decoding.
  • Prompt/prefix caching for shared system prompts; route a conversation to the same replica to reuse its KV cache.
  • Capacity: GPUs are scarce → priority queues per tier, load shedding, autoscaling with warm pools (model load takes minutes).