FullStack AI Hub
Studio
System Design · 01. Foundations
10 min
10 steps
Beginner

Latency & Throughput

Understand why averages lie, how Little’s Law governs concurrency, why queues explode past 80% load, and how hedged requests tame P99 tail latency.

System Design01. FoundationsLesson 2 of 3
10 minBeginner10 steps

Latency & Throughput

Understand why averages lie, how Little’s Law governs concurrency, why queues explode past 80% load, and how hedged requests tame P99 tail latency.

P50 MEDIAN
22 ms
AVERAGE
48 ms
P99 TAIL
940 ms
THROUGHPUT
2,400/s
slow tail2,400 req/sLoadBalancer34%Server A(Fast)42%P50: 22 msServer B(GC)74%P99: 940 msPERCENTILE BREAKDOWNP5022 ms (happy)P95180 ms (noticeable)P99940 ms (painful!)
normal request (P50)
slow tail (P99)
batched / hedged
queue timeout
In This LessonStep 1 of 10
What You Will Master
  • ✓Measure P50, P95, and P99 tail latency instead of misleading arithmetic averages
  • ✓Apply Little’s Law (L = λ·W) and keep utilization below the ~75–80% queueing knee
  • ✓Diagnose fan-out tail amplification across microservices and tame it with Hedged Requests
  • ✓Balance micro-batching throughput gains against per-request latency budgets

Architectural Trade-Off Comparison Matrix

PatternBest ForKey Trade-Off
P95 / P99 PercentilesSLOs and catching slow outliers hidden by averagesCannot average percentiles across servers—must merge histograms
Headroom (< 75% Util)Interactive APIs avoiding exponential queue-wait hockey sticksCosts ~25–30% idle compute headroom during normal hours
Hedged RequestsFan-out read services suffering 1% straggler shardsAdds ~5% extra load; requires strictly idempotent reads
Micro-BatchingHigh-throughput telemetry, logs, and ML inference pipelinesAdds deliberate batch-fill delay (e.g., 10–50 ms) to single items

Step-by-Step Architectural Breakdown (10 Steps)

Full architectural walkthrough transcript and state transitions for Latency & Throughput.

STEP 01 · PROBLEMJump to step →

Why average latency hides painful user slowness

Your dashboard proudly reports an **average latency of 48 ms**, yet your most active power users complain the app feels sluggish. Looking at percentiles reveals the truth: **P50 is 22 ms**, **P95 is 180 ms**, and **P99 is 940 ms**!

Because a single slow page makes **10 API calls**, a 1% slow rate means roughly **10% of every page load** hits at least one 940 ms straggler.

watch:Never put arithmetic average latency in an SLA—99 fast responses easily mask 1 catastrophic 2-second freeze.

P50 / P95 / P99Tail LatencyAverage Illusion
STEP 02 · SETUPJump to step →

Latency vs Throughput: pipe length vs pipe width

**Latency** is the time a single request takes end-to-end (milliseconds). **Throughput** is how many requests the system finishes per second (RPS). They are distinct dimensions!

Adding more parallel lanes doubles **throughput** (from 1,500/s to 3,000/s) while each individual request still takes the same **24 ms** to traverse a single server.

idea:Horizontal scaling widens the highway (higher throughput), whereas caching and locality shorten the road (lower latency).

Latency (ms)Throughput (RPS)Parallel Lanes
STEP 03 · TECHNIQUEJump to step →

Little’s Law: L = λ · W governs every server

In any stable system, **Little’s Law** states **`L = λ · W`**: the number of concurrent requests in flight (`L`) equals arrival rate (`λ` RPS) multiplied by average latency (`W` seconds).

At **2,000 req/s** and **50 ms (0.05s)** latency, you only hold **100 open connections**. If a slow DB pushes latency to **500 ms (0.5s)**, concurrency explodes **10× to 1,000 threads**—exhausting your thread pool!

idea:Every millisecond shaved off latency directly frees up thread-pool slots and memory across your entire fleet via Little’s Law.

Little’s Law (L = λ·W)In-Flight ConcurrencyThread Pool Exhaustion
STEP 04 · PROBLEMJump to step →

The 80% utilization knee (hockey-stick latency)

Queueing theory (`Wait ∝ ρ / (1 − ρ)`) explains why running servers at **95% CPU** is disastrous. Between 20% and 70% utilization, latency stays almost completely flat.

Cross **80% utilization**, however, and random burst overlaps make queue wait times shoot up like a **hockey stick**—at 95% load, requests spend **19× longer waiting in line** than actually executing!

watch:Autoscale interactive API fleets around 65–70% CPU—never wait for 90% CPU or tail latency will already be on fire.

Queueing Theory (M/M/1)Utilization KneeAutoscaling Headroom
STEP 05 · TECHNIQUEJump to step →

Physical speed of light: why locality beats faster CPUs

Even if your backend executes in **0.1 ms**, light traveling through fiber-optic glass from London to Sydney and back takes **~260 ms** minimum! Three sequential round-trips (DNS + TCP + TLS + API) quickly burn **750 ms**.

Cutting round-trips (HTTP/2 multiplexing, GraphQL/BFF batching) and placing **Edge Caches** near users beats buying faster server CPUs every single time.

idea:Rule of thumb for rough math: intra-AZ RTT ~0.5 ms, cross-coast US ~70 ms, transatlantic ~90 ms, US-to-Asia ~160 ms.

Speed-of-Light RTTEdge LocalityRound-Trip Amplification
STEP 06 · PROBLEMJump to step →

Tail amplification: one slow leaf delays the entire response

Suppose a Search Aggregator fans out in parallel to **3 backend shards** and must wait for **all 3** before returning. Even if each individual shard is fast 95% of the time, the chance that **at least one** shard hits its slow P95 tail climbs to **`1 − 0.95³ = 14.3%`**!

At 50 shards (like web search), a mere **1% per-shard slow rate** means **39% of all user searches** suffer a P99 straggler!

watch:Fan-out amplifies tail latency exponentially: `P(slow) = 1 − (1 − p)^N`. The slowest single leaf dictates your user’s total wait.

Tail Latency AmplificationFan-Out Scatter-GatherStraggler Problem
STEP 07 · SOLUTIONJump to step →

Tame stragglers with Hedged Requests

Popularized by Google’s *"The Tail at Scale"*, **Hedged Requests** fire a duplicate read to a healthy **Replica** if the primary read hasn’t answered after the **P95 threshold (e.g., 25 ms)**—and take whichever answer arrives first!

Because only the slowest **5%** of requests ever trigger a hedge, extra cluster load is just **+5%**, yet **P99 latency drops by 70%+**!

good:Only hedge idempotent read operations—never send speculative duplicate payment charges!

Hedged RequestsTail at ScaleSpeculative Backup Read
STEP 08 · TRADE-OFFJump to step →

Micro-Batching: trade 15 ms latency for 5× throughput

Sending 5,000 tiny single-row database inserts per second wastes most CPU on TCP framing and disk `fsync` overhead. A **Micro-Batcher** collects events for **15 ms (or 100 items)** and flushes them in a single bulk write.

Aggregate **throughput jumps 5×** while DB load drops by **75%**—at the explicit cost of adding **~15 ms of linger delay** to each individual item.

idea:Micro-batching powers Kafka producers, analytics collectors, and GPU LLM inference—trading a tiny intentional delay for massive throughput.

Micro-BatchingLinger Delay (linger.ms)Amortized fsync
STEP 09 · SOLUTIONJump to step →

Bounded concurrency protects P99 under overload

Without a concurrency cap, a 2× surge floods queues until **100% of users time out**. Adding an **Adaptive Concurrency Limiter** (inspired by Little’s Law) caps active in-flight slots at the sweet spot right below the 80% knee.

Excess requests get fast-rejected with 503 in **2 ms**, while the admitted 80% of paying users continue receiving crisp **35 ms responses**—**goodput stays maximized**!

good:Serving 2,200 users in 35 ms and rejecting 600 fast is vastly better than making all 2,800 users wait 4 seconds and time out.

Adaptive ConcurrencyGoodput vs Raw ThroughputLoad Shedding
STEP 10 · RECAPJump to step →

Performance engineering mental model recap

Fast systems are engineered intentionally: track **P95/P99** (never averages), stay below the **75% queueing knee**, cut round-trips via **Edge Locality**, rescue fan-out stragglers with **Hedged Requests**, and protect goodput with **Concurrency Limits**.

Stress-test the complete performance stack below with a 1.8× surge plus a straggler degradation.

good:Watch P99, size for < 75% peak utilization, cap concurrency to preserve goodput, and use hedging + edge caching to defeat tail latency.

P99 EngineeringGoodput ProtectionTail Mitigation

Related Production Deep-Dives & Simulators

Included In Free Course
Free · Verifiable Credential

FS-102LLM Systems Foundations

Build a connected mental model from tokens through retrieval evaluation security and operations.

24 concepts~18h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.