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

Design a Conversational AI
Serving Platform (ChatGPT Scale).

Design a globally distributed conversational AI platform supporting 100M DAU, <300ms TTFT, <30ms ITL, branching chat histories, and real-time SSE token streaming.
Start the journey7 stages· Last modified Nov 24, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

To keep serving pipelines predictable under bursty prompts, use Anycast Edge POPs for SSE termination, sharded Postgres + Redis for branching conversation trees, consistent-hash KV-prefix routing, and disaggregated Prefill/Decode GPU pools.

TL;DR30-second simplified summary
▾

Serving 35K peak QPS with 350K concurrent SSE streams requires separating edge termination, context hydration, GPU inference, and observability. Envoy Edge POPs proxy to Go/Rust SSE gateways with 15s keepalives and Last-Event-ID Redis Stream replay.

Sharded PostgreSQL + Redis store branching message trees, while bounded-load consistent hashing routes turns to warm RadixAttention GPU replicas. Metering and moderation logs flow asynchronously via Kafka to ClickHouse and S3.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Conversational AI Serving & SSE Streaming
Conversational AI serving combines stateful multi-turn context hydration, continuous GPU batching, KV-cache prefix reuse, and backpressure-aware Server-Sent Events (SSE) to deliver sub-300ms Time-to-First-Token (TTFT) at 100M+ DAU.
Full walkthrough · 7 stages
01
foundation

Capacity Estimation & SLO Targets.

Why this matters: Quantify QPS, concurrent SSE connections, GPU HBM capacity, and network egress for 100M DAU.

Assume 100M DAU averaging 10 turns/day = 1B turns/day (~11,500 avg QPS, ~35,000 peak QPS).

With an average response of 400 tokens at 40 tok/s (10s stream duration), peak concurrent open SSE streams reach 350,000.

Stage 1 - Back-of-Envelope Sizing

100M DAU Capacity Model

100M DAU Trafficsource350K Concurrent SSEprocessor140 TB KV HBMstorageSLOs: <300ms TTFTsink400MB/stream KV

1.Peak Multiplier: Use 3x peak-to-average ratio for global diurnal traffic waves.

2.Egress Bandwidth: 350K streams * 40 tok/s * 50B SSE frame = ~700 MB/s (5.6 Gbps) edge egress.

Capacity math drives 350K concurrent SSE sockets and 140TB of GPU KV-cache memory.

02
foundation

Edge Ingress, Anycast POPs & SSE Connection Management.

Why this matters: Terminate TLS close to users and maintain 350K+ long-lived SSE streams without exhausting gateway memory.

Geo-DNS routes users to the nearest Anycast Edge POP running Envoy.

Envoy terminates HTTP/3/TLS and proxies /v1/chat/completions over persistent gRPC streams to regional Go/Rust SSE Gateways.

Stage 2 - Edge Termination

Anycast POP to SSE Gateway Bridge

Geo-DNS + AnycastsourceEnvoy TLS EdgerouterGo/Rust SSE Gatewayprocessor15s Keepalive +ResumecachegRPC stream

1.SSE vs WebSocket: SSE works natively over HTTP/2 multiplexing without custom upgrade handshakes.

2.Resumable Streams: Buffer last 60s of tokens in Redis Streams so mobile reconnects resume cleanly.

Edge POPs decouple global TLS termination from regional streaming gateways.

Engineering Decision Framework
Problem
How to implement Design a Conversational AI Serving Platform (ChatGPT Scale) without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
To keep serving pipelines predictable under bursty prompts, use Anycast Edge POPs for SSE termination, sharded Postgres + Redis for branching conversation trees, consistent-hash KV-prefix routing, and disaggregated Prefill/Decode GPU pools.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a Conversational AI Serving Platform (ChatGPT Scale) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

Branching Conversation Store & Async Context Hydration.

Why this matters: Model editable/regenerable chat trees and hydrate context windows under 20ms p99.

Users frequently edit prompts or regenerate replies, forming a tree rather than a flat list.

PostgreSQL (sharded by user_id) stores conversations and messages(id, parent_id, role, token_count, content_ref) with large attachments in S3. Active conversations are cached in Redis Cluster (hash of recent turns + precomputed rolling summary).

Stage 3 - Conversation State

Sharded Postgres + Redis Turn Hydrator

New User TurnsourceRedis ClustercacheSharded PostgreSQLstorageAsync SummarizerprocessorFallback on miss

1.Tree Schema: Adjacency list with parent_id enables O(depth) branch traversal and instant edits.

2.Async Compaction: Summarize older turns asynchronously after response completion, never on the hot path.

Sharded PostgreSQL and Redis keep context hydration under 20ms even for branching chats.

04
intermediate

KV-Prefix Affine Routing & Bounded-Load Consistent Hashing.

Why this matters: Maximize RadixAttention prefix cache hits while preventing hot GPUs during viral workloads.

The Inference Router hashes conversation_id onto a consistent-hash ring of Decode/Prefill pods (e.g., Maglev or Ketama with virtual nodes).

To prevent a single power user or retry storm from overloading one GPU, each node has a bounded-load ceiling (1.25x cluster average active tokens).

Stage 4 - Smart Inference Routing

Bounded-Load Consistent Hash Ring

Inference RouterrouterPrimary GPU PodprocessorSecondary GPU PodprocessorEWMA Load ProbecacheSpill if overloaded

1.Hit Rate Impact: Sticky routing achieves >85% KV-prefix cache hit rate on multi-turn sessions.

2.Graceful Spillover: Spilling at 1.25x load trades a one-time prefill for cluster-wide tail-latency stability.

Bounded-load consistent hashing balances KV-cache locality against GPU saturation.

05
intermediate

Disaggregated Prefill/Decode & Speculative Decoding.

Why this matters: Hit <300ms TTFT and <30ms ITL simultaneously using disaggregated pools and draft verification.

Think of Disaggregated Prefill/Decode & Speculative Decoding as the intuition layer for Design a Conversational AI Serving Platform (ChatGPT Scale): Hit <300ms TTFT and <30ms ITL simultaneously using disaggregated pools and draft verification.

Prefill workers process input prompts in chunked passes and push KV-cache blocks over InfiniBand/RoCEv2 RDMA to Decode workers. To accelerate Decode ITL beyond memory-bandwidth limits, small draft models (or Medusa/EAGLE heads) propose 4-5 candidate tokens verified in a single parallel target-model forward pass, boosting effective decode speed by 2x-2.5x without changing output distribution.

Stage 5 - Inference Engine

Disaggregated Prefill + Speculative Decode

Prefill PoolprocessorRDMA KV TransfercacheDecode PoolprocessorNVMe Offload TierstorageVerify 4-5 draft tokens

1.Speculative Speedup: Lossless speculative verification doubles tok/s on memory-bound decode batches.

2.NVMe Offload: Offloading evicted KV prefixes to local NVMe extends prefix retention to hours.

Disaggregation plus speculative decoding hits both TTFT and ITL SLOs at high batch sizes.

06
advanced

Multi-Region Failover, Model Tier Fallback & Load Shedding.

Why this matters: Maintain availability during regional GPU outages or sudden viral traffic surges.

Think of Multi-Region Failover, Model Tier Fallback & Load Shedding as the intuition layer for Design a Conversational AI Serving Platform (ChatGPT Scale): Maintain availability during regional GPU outages or sudden viral traffic surges.

Each region runs active-active stateless gateways and replicated Redis/Postgres metadata. If a region's GPU pool hits >90% HBM saturation, the router performs priority-based load shedding: paid/interactive requests stay on primary frontier models, free-tier or background tasks degrade gracefully to a distilled fast model, and excess traffic overflows cross-region via Geo-DNS weighted shifting.

Stage 6 - Resilience & Degradation

Priority Load Shedder & Cross-Region Failover

Regional GPUMonitorrouterPriority LoadShedderprocessorDistilled Fast PoolcacheCross-Region SpillsinkRoute free/batch tier

1.Zero Retry Storms: Return 429 with Retry-After jitter rather than letting clients hammer saturated GPUs.

2.Circuit Breakers: Trip cross-region failover if regional TTFT p99 exceeds 1.5s for 30s.

Priority load shedding and model-tier fallback keep interactive chat responsive under overload.

07
advanced

Async Telemetry, Token Billing & Moderation Audit Pipeline.

Why this matters: Track exact token usage, latency percentiles, and compliance logs off the critical path.

Think of Async Telemetry, Token Billing & Moderation Audit Pipeline as the intuition layer for Design a Conversational AI Serving Platform (ChatGPT Scale): Track exact token usage, latency percentiles, and compliance logs off the critical path.

Once a stream finishes or aborts, the SSE Gateway emits a single CompletionAuditEvent (user_id, prompt_tokens, cached_tokens, completion_tokens, TTFT, ITL, safety_flags) to Kafka with idempotent producer keys. Flink aggregates real-time FinOps cost and quota counters into Redis/ClickHouse, while encrypted audit transcripts land in S3 Parquet for compliance.

Stage 7 - Async Observability

Kafka-Flink Metering & Audit Pipeline

SSE Gateway EmittersourceKafka Audit TopicprocessorFlink Metering JobcacheS3 Parquet +ClickHousesinkUpdate token quotas

1.Zero Hot-Path Cost: Metering and S3 persistence never add latency to the user's SSE stream.

2.Cached Token Billing: Track cached_prefix_tokens separately to pass KV-cache savings to tenants.

Asynchronous Kafka pipelines decouple billing, FinOps, and compliance from token streaming.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why is consistent hashing with bounded load preferred over pure round-robin when routing multi-turn ChatGPT requests to GPU replicas?

Recommended Learning Flow