Module 1 · Beginner · System design fundamentals

Latency, throughput and availability

Latency vs throughput vs availability: percentiles like p99, the latency numbers every programmer should know, and what 99.9% uptime means.

By theprogrammers team · · 6 min read

"Is it fast?" and "does it stay up?" are the two questions behind almost every system design decision. To answer them properly, engineers use three words with precise meanings: latency (how long one request takes), throughput (how many requests per second the system handles) and availability (what fraction of the time it works).

This lesson explains each one with everyday examples, shows how to measure them properly with percentiles and "nines", and lists the latency numbers every programmer should know.

Latency: how long one request takes

Latency is the time between asking and getting an answer: you tap "Pay" and 300 milliseconds later you see "Payment successful". It's measured in milliseconds (ms): 1,000 ms is one second.

Think of a highway. Latency is how long one car takes to drive from Kanpur to Lucknow.

What users feel:

LatencyFeels like
Under 100 msInstant
100 ms to 1 secondA small, noticeable delay
Over 1 secondSlow; people lose focus
Over 10 secondsBroken; people leave

Throughput: how much work per second

Throughput is how many requests the system completes per unit of time, usually requests per second (RPS) or queries per second (QPS). For data, it's bytes per second.

On the highway, throughput is how many cars per hour reach Lucknow. Adding lanes increases throughput, but doesn't make any single car faster.

That's the key insight: latency and throughput are different, and improving one doesn't automatically improve the other.

  • Adding more servers behind a load balancer raises throughput, but each request takes about the same time.
  • Batching (sending 100 rows to the database in one go instead of 100 separate calls) raises throughput, but the first row waits longer.
  • A cache lowers latency and raises throughput, because each request does less work.

When they connect: queues

They do interact under load. A server that handles 100 requests per second is fine at 80 per second. At 120 per second, the extra 20 requests every second have to wait in a queue, the queue grows, and latency climbs for everyone, even though each request's actual work hasn't changed. This is why systems slow down sharply when they get near full capacity, and why engineers aim to run at, say, 60 to 70% of capacity.

Measure latency with percentiles, not averages

Suppose 99 requests take 50 ms and one takes 5 seconds. The average is about 100 ms, which sounds fine but describes nobody's actual experience. Engineers use percentiles instead:

  • p50 (the median): half of requests are faster than this.
  • p95: 95% are faster; 1 in 20 is slower.
  • p99: 99% are faster; 1 in 100 is slower.
import numpy as np

rng = np.random.default_rng(0)
latencies = np.concatenate([
    rng.normal(80, 15, 9_800),     # most requests: about 80 ms
    rng.normal(900, 200, 200),     # a slow 2%: about 900 ms
])

print(f"average {latencies.mean():.0f} ms")
for p in (50, 95, 99):
    print(f"p{p}   {np.percentile(latencies, p):.0f} ms")
average 96 ms
p50   80 ms
p95   108 ms
p99   909 ms

The average says 96 ms. The p99 shows that 1 in 100 requests takes about a second. And slow requests aren't rare in practice: a page that makes 20 requests will very often hit at least one slow one. That's why big companies set goals like "p99 under 300 ms".

Availability: the "nines"

Availability is the percentage of time a system works correctly. It's described in nines:

AvailabilityNicknameDowntime per yearDowntime per month
99%two nines3.65 daysabout 7.2 hours
99.9%three nines8.76 hoursabout 43 minutes
99.99%four nines52.6 minutesabout 4.3 minutes
99.999%five nines5.26 minutesabout 26 seconds

Each extra nine is ten times harder and much more expensive. A college website is fine at two nines; a payment system like UPI aims for far more.

A promise to customers about availability is called an SLA (service level agreement). The internal target is an SLO (objective), and the measurement is an SLI (indicator). For example: SLI = percentage of successful requests; SLO = 99.9% per month; SLA = refunds if it falls below 99.5%.

Availability of connected parts

When parts depend on each other in series (all must work), multiply their availabilities. An app server at 99.9% that needs a database at 99.9%:

0.999 × 0.999 = 0.998, so 99.8%

Every dependency lowers availability. When parts are in parallel (any one is enough), the system fails only if all fail. Two servers that are each up 99% of the time:

1 − (0.01 × 0.01) = 0.9999, so 99.99%

That's the maths behind redundancy: two ordinary servers behind a load balancer beat one excellent one.

Latency numbers every programmer should know

Rough figures, worth memorising as orders of magnitude:

OperationTime
Read from CPU cacheabout 1 nanosecond
Read from RAMabout 100 nanoseconds
Read 1 MB from RAMabout 10 microseconds
Read from an SSD (random)about 100 microseconds
Round trip within a data centreabout 0.5 milliseconds
Read 1 MB from an SSDabout 1 millisecond
Hard disk seekabout 10 milliseconds
Round trip Mumbai to Singaporeabout 60 milliseconds
Round trip India to the USabout 200 to 250 milliseconds

(1 millisecond = 1,000 microseconds = 1,000,000 nanoseconds.)

The lessons: memory is about 1,000 times faster than SSD, which is why caches in RAM (like Redis) are so effective; and distance is expensive, which is why CDNs put content near users.

Practice

  1. A page loads in 2 seconds on average, but users still complain. What should you measure next?
Show the answer

The latency percentiles, especially p95 and p99, broken down by page and by step (DNS, server time, database time, download). A minority of very slow requests can hide behind a reasonable-looking average.

  1. Your API depends on three services, each 99.9% available, all required. What's the best possible availability?
Show the answer

0.999³ ≈ 0.997, about 99.7%, or roughly 26 hours of downtime a year.

  1. Adding a second server doubled throughput, but the p50 latency didn't change. Is that a surprise?
Show the answer

No. More servers let you handle more requests at once (throughput), but each request still does the same work, so its latency stays the same, unless the old server was overloaded and requests were queuing.

Interview questions

What is the difference between latency and throughput?

Latency is the time to complete one operation; throughput is how many operations complete per unit of time. Parallelism and batching raise throughput without lowering, and sometimes while raising, latency.

Why use p99 instead of average latency?

Averages hide outliers; a small share of very slow requests can ruin the experience, especially when a page makes many requests. Percentiles show what most users, and the unlucky ones, actually see.

How much downtime does 99.9% availability allow?

About 8.76 hours per year, or roughly 43 minutes per month.

How do you increase availability?

Remove single points of failure with redundancy (multiple servers, replicas, regions), add health checks and automatic failover, reduce dependencies in series, and deploy changes gradually so mistakes can be rolled back.

What to learn next

  1. Put numbers on a design in back-of-the-envelope estimation.
  2. Raise throughput by adding machines in vertical vs horizontal scaling.