Lesson 2 · Scaling and Trade-offs

Latency, Throughput & Availability

The three pillars of system observability — if you can't measure these, you can't operate.

Before you can reason about scaling, consistency, or fault tolerance, you need a shared language for measuring system health. These three metrics are that language. Latency tells you how fast the system responds. Throughput tells you how much work it can handle. Availability tells you how often it's actually reachable.

They are related but not interchangeable — and optimizing for one often creates pressure on another. Understanding their definitions, how they're measured, and where they conflict is the prerequisite to every architectural decision that follows.

When an architecture buckles under load or degrades in production, it is almost never because of an obscure syntax bug. It fails because someone miscalculated the relationship between how fast an operation completes, how many operations can run concurrently, and what proportion of them succeed over time. Treat these three as mathematical constraints that push against one another, not as isolated target numbers on a dashboard.

Metric 01

LatencyTime to complete a request

Latency is the time it takes for a single request to complete. In a distributed architecture, this is not a single number — it's a distribution. The most common mistake is reporting latency as an arithmetic mean.

If 99% of requests take 10ms but 1% take 5 seconds, your average looks healthy while a real slice of users hits timeouts. The mean hides outliers entirely.

Never use the mean for latency. Use percentiles. The mean is mathematically valid but operationally misleading in skewed distributions — which is exactly what request latency produces.
p50
Median
Half your users experience this or better. Your "typical" user's experience.
p95
95th Percentile
The slowest 5% of requests. Start of the "bad day" zone for users.
p99
Tail Latency
The unluckiest 1% of requests. Your SLA should be defined here, not at p50.

Latency = Total Round-Trip Time

Client
Request →
──────
← Response
Gateway
Request →
──────
← Response
Service

Latency = time from client sends request → client receives response

Latency is often confused with response time. Response time is the total elapsed time the client experiences. Latency is the portion of it introduced by network transit, queuing, and compute along the path. Those three pieces are additive:

Total Latency = Network Transit + Queue Wait + Execution

Knowing which term dominates tells you which fix is worth attempting. Adding a CDN does nothing for a request stuck in a connection pool, and a faster query does nothing for a client three continents away.

Network Transit

Bounded by physics. Light travels roughly 200 km per millisecond through fiber, and every routing hop adds more. You cannot optimize this away, you can only move the data closer.

Queue Wait

Time spent sitting in thread pools, TCP buffers, and database connection pools waiting for a free worker. The only dynamic term, and it dominates as the system approaches saturation.

Execution

Raw CPU and I/O: parsing payloads, running business logic, reading from storage engines. This is what profilers measure and what most engineers instinctively try to fix first.

A healthy system spends its latency on execution. When queue wait becomes the largest term, you are no longer looking at a slow service, you are looking at an under-provisioned one. The fix is capacity or shedding, not micro-optimization.
Jitter — a significantly higher p99 than p50 — indicates inconsistency in your system. Common causes: GC pauses, lock contention, or slow database queries. Horizontal scaling will not fix jitter.

Metric 02

ThroughputRate of work processed

Throughput is the rate at which your system processes requests — measured in Requests Per Second (RPS) or Transactions Per Second (TPS).

Units follow the workload. Web services report RPS or QPS (queries per second), while data pipelines report records per second or MB/s. The unit changes, the reasoning does not.

High throughput does not imply low latency. A system can process 10,000 RPS while taking 2 seconds to respond to each. This happens when a system is heavily queued — work is being accepted, but users wait in line before processing begins.

Common mistake

Engineers often assume throughput is simply the inverse of latency. That identity holds for exactly one case: a strictly synchronous, single-threaded worker handling one request at a time. At 50ms per request:

1 request ÷ 0.05s = 20 RPS

Real architectures break that ceiling with concurrency: multiple threads, event loops, CPU cores, and distributed nodes. A 50ms endpoint on 64 concurrent workers serves 1,280 RPS without getting a single millisecond faster.

Little's Law ties the two together: L = λW, where concurrency (L) equals arrival rate (λ) times latency (W). Hold arrival rate steady and double latency, and the number of in-flight requests doubles. That is why rising latency silently drains a worker pool until the pool itself becomes the outage.
Identify the Bottleneck

Is the system CPU-bound (compute exhausted), memory-bound (heap pressure / GC), or I/O-bound (disk or network saturated)? Each bottleneck type demands a different fix.

Saturation Point

The point at which throughput plateaus. Beyond it, adding more load causes exponential latency spikes rather than more processed requests. This is your effective capacity ceiling.

Throughput ≠ Latency. A heavily queued system can look healthy on throughput dashboards while individual users experience degraded performance. Always monitor both together.

Metric 03

AvailabilityPercentage of time the system is reachable

Availability is the percentage of time a system is functional and reachable, expressed in "nines". It is calculated as:

Availability = Uptime ÷ (Uptime + Downtime)

In distributed systems, availability is rarely binary. A system can be "up" while returning 500 errors to 5% of users. The inverse metric is Error Rate — Failed Requests ÷ Total Requests.

AvailabilityDowntime / yearDowntime / monthTypical architecture required
99% 2 nines~3.65 days~43.8 hoursSingle server with manual recovery
99.9% 3 nines~8.76 hours~43.8 minutesRedundant app servers, managed database failover
99.99% 4 nines~52.6 minutes~4.38 minutesMulti-zone redundancy, automated health checks, zero-downtime deploys
99.999% 5 nines~5.26 minutes~26.3 secondsMulti-region active-active, automated chaos engineering
Each additional nine is an order of magnitude less allowable downtime, not an incremental improvement. Five nines means eliminating every manual operational step, because a human takes 15 to 30 minutes just to acknowledge a page and open a terminal. That alone is six years of a five-nines budget.
In series, availability multiplies
0.999⁵ ≈ 99.5%

A request that must touch five services, each at 99.9%, succeeds only 99.5% of the time. Every hard dependency you add subtracts uptime, which is why deep synchronous call chains are so expensive.

In parallel, failure multiplies
1 − (1 − 0.99)² = 99.99%

Two redundant 99% replicas fail together only 0.01% of the time. Redundancy is the only structural move that buys nines, and it only works if the replicas do not share a failure domain.

High availability ≠ fast. A system that takes 30 seconds to respond but eventually succeeds is technically "available." Availability measures uptime, not speed. You need all three metrics to describe system health accurately.

Putting it together

The Tension Between Metrics

These metrics don't exist in isolation — optimizing for one creates pressure on the others.

To improve latency, you might cache results — increasing memory usage and cache consistency complexity. To improve availability, you add redundant nodes — which increases consistency complexity. To improve throughput, you scale horizontally — which introduces distributed state challenges covered in the previous lesson.

Latency
Improve via caching. Trade-off: memory pressure and consistency risk.
Throughput
Improve via horizontal scaling. Trade-off: distributed state complexity.
Availability
Improve via redundancy. Trade-off: consistency model complexity.
Throughput vs LatencyBatching & queues

Grouping 1,000 individual inserts into one bulk write collapses connection and disk sync overhead, so database throughput climbs sharply. Each individual record pays for it by waiting in a memory buffer until the batch window closes.

Availability vs LatencyMulti-region replication

Writing synchronously to two regions means a total loss of Region A costs zero data. It also adds a cross-region round trip of 50ms to 150ms to every single write, forever, including the 99.99% of days nothing fails.

Availability vs ThroughputRetries & load shedding

Aggressive client retries mask transient blips and improve perceived availability. Under sustained saturation those same retries become a thundering herd that multiplies load against an already struggling system, turning a partial slowdown into a full outage.

Recap. Latency is governed by network physics, execution cycles, and queuing, with percentiles exposing the tail the mean hides. Throughput is bounded by concurrency under Little's Law, where rising latency quietly drains the worker pool. Availability is decided by topology, since dependencies in series multiply risk while redundancy in parallel absorbs it. Every architecture ahead is a negotiation between these three.
These metrics form the foundation for evaluating every architectural trade-off ahead — starting with the CAP Theorem, which formalizes exactly this tension between consistency and availability in distributed systems.

Quiz Review

Check your understanding

Question 1 of 13

Why should you never use the arithmetic mean to report latency?

  • The mean hides outliers — a small number of very slow requests can be masked by the fast majority, making the system appear healthier than it is.