What it is
Latency is the time one operation takes, from the moment it is requested to the moment the result is available. For a user-facing request, that means from the click until the answer arrives. It is measured in milliseconds and reported per request, so a system does not have "a latency" but a distribution of them.
Why it exists
Every request travels over a network, may wait for a free worker, is processed, and usually calls other components that do the same. Each of these takes time, and some of it is variable. Latency matters because people notice it: interfaces that respond within roughly 100 ms feel instant, while delays of a second or more change behaviour, and services that call other services inherit all of their delays.
How it works
Latency is a sum of parts:
- Network time. Bounded by distance: light in fibre covers roughly 200 km per millisecond, so a round trip across an ocean costs tens to over a hundred milliseconds before any work happens. It is paid on every round trip, and protocols such as TCP and TLS add round trips when a connection is set up.
- Queueing time. When every worker is busy, a request waits. With random arrivals, waiting grows slowly at moderate load and steeply as utilisation approaches 100%. This is why a server can be "only" 85% busy and already noticeably slower.
- Processing time. The work itself: parsing, logic, serialisation.
- Dependency time. Calls to databases, caches and other services. Sequential calls add up; parallel calls cost roughly the slowest one.
Because these parts vary, latency is reported as percentiles. P50 (the median) is the typical request; P95 and P99 are the times that 5% and 1% of requests exceed. The average is easily dragged by a few outliers and hides the tail at the same time. The tail matters because a page that triggers many requests, or a service that fans out to many back ends, is likely to hit at least one slow response.
When to use it
Latency is the primary metric for anything interactive: page loads, API calls, search, checkout. It is also the most sensitive early signal of overload, because queueing raises it before errors appear. Service level objectives are usually written as percentile targets, for example "P99 under 300 ms over 28 days".
When not to
For batch jobs, data pipelines and background processing, the metric that matters is usually throughput or time to finish the whole job, not the latency of any single item. Optimising per-item latency there often wastes effort; batching items may even raise latency per item while finishing the job sooner.
Trade-offs
| Technique | Lower latency because | Cost |
|---|---|---|
| Caching | Skips slow work for repeated reads | Staleness, invalidation, memory |
| Regions, CDNs, edge | Removes distance | Data replication, consistency, cost |
| Parallel calls | Pays only the slowest dependency | More concurrent load, harder error handling |
| Keeping headroom (lower utilisation) | Shorter queues | Paying for idle capacity |
| Hedged or duplicate requests | Cuts tail latency | Extra load on back ends |
| Batching | Fewer round trips per item | Higher latency for each item waiting in a batch |
Alternatives
Latency is a property, not a choice, so the alternatives are in how you measure and hide it. Asynchronous processing returns immediately and finishes the work later, so the user-facing latency is short even if the job is long. Optimistic UI updates show the expected result before the server confirms it. Prefetching starts work before the user asks.
Failure modes
- Averages in dashboards. A healthy average hides a terrible P99.
- Coordinated omission. Load tests that wait for each response before sending the next under-report latency during stalls.
- Fan-out amplification. A request that calls 50 back ends is as slow as the slowest of them; one slow shard slows everyone.
- Retry storms. Slow responses trigger client timeouts and retries, which add load and make responses slower still.
- No timeouts. A dependency that hangs ties up workers until the caller saturates too.
In production
Measure latency where the user experiences it (real-user monitoring) and per hop (tracing), and keep histograms rather than averages. Set timeouts on every outbound call, shorter than the caller's own deadline. Watch utilisation as a leading indicator: a component running near capacity will show latency growth first. Put static content on a CDN, serve users from nearby regions where data allows it, cache hot reads, and remove sequential round trips from critical paths.
Common misconceptions
- "Latency and throughput are the same thing." A system can serve many requests per second while each one is slow, or answer quickly but only a few at a time.
- "A faster CPU fixes latency." Only the processing part. Network distance and queueing at a saturated dependency remain.
- "The server is at 80%, so we have 20% headroom." Latency rises well before 100%; the effective headroom is smaller.
- "P99 is just outliers." On a busy page or a fan-out service, the P99 of a component becomes the typical experience of the user.
Interview angle
State latency targets as percentiles and build a rough budget: client to edge, edge to service, service to database, with numbers. Point out which calls can run in parallel, where a cache removes a round trip, and when users far away need a nearby region or CDN. Mentioning that queueing raises latency long before saturation, and that you would keep utilisation below about 70–80% for latency-sensitive services, shows you understand the mechanics.
Model assumptions
The simulation is a simplified model, not a benchmark. Network hops take a fixed time (20 or 80 ms each way to the users, 1–5 ms inside the data centre) with no jitter, loss or connection setup. The app server has 8 workers and a 30 ms mean service time; a worker waiting for the database stays busy. The database has 8 connections and a 40 ms mean query time; in the tail step its variability rises (lognormal, cv 2) while the mean stays the same. The cache answers a fixed 90% of lookups in about 2 ms. Arrivals are random (Poisson). Numbers show behaviour and orders of magnitude only.