Latency
Latency is the time delay between initiating a request or operation and receiving its result — for example, the time from sending a database query to getting the first byte of its response back.
Overview
Latency measures how long something takes from start to finish, typically expressed for a single operation (as opposed to throughput, which measures how much work completes over time). In distributed systems and databases, latency is usually reported as a distribution rather than a single number, because most systems have some fast requests and some slow ones — commonly summarized using percentiles like p50 (median), p95, and p99, since the tail of the distribution often matters more to user experience than the average.
Components of latency
End-to-end latency for a database query, for instance, can include network round-trip time, connection setup, query planning/optimization, actual execution time, and time to serialize and transfer the result. Reducing latency typically means attacking whichever component dominates: caching to avoid repeated computation, indexing to avoid full scans, connection pooling to avoid repeated handshakes, or moving compute closer to data to cut network round trips.
Measuring latency percentiles
Copy code
SELECT
quantile_cont(response_ms, [0.5, 0.95, 0.99]) AS latency_percentiles
FROM requests;
For very large request logs, approx_quantile gives a fast, bounded-error estimate of the same percentiles when exact computation is unnecessarily expensive.
Latency versus throughput
Latency and throughput are related but distinct, and often in tension: a system can have low latency per request but low throughput if it can't handle many requests concurrently, or high throughput with high per-request latency if it processes requests in large batches. Query engines like DuckDB are generally optimized for low latency on interactive, single-query analytical workloads on one machine, since it executes queries using all available cores on the local hardware rather than distributing work across a cluster — which is also why very large, distributed workloads may favor a system built for high aggregate throughput across many nodes instead.
Related terms
Throughput is the amount of work a system completes per unit of time — such as queries per second, rows processed per second, or requests handled per minute — measuring capacity rather than the speed of any single operation.
Percentile →A percentile is the value below which a given percentage of a dataset falls — for example, the 95th percentile (p95) of response times is the value that 95% of requests were faster than.
Webhook →A webhook is a way for one system to notify another in real time by sending an HTTP POST request to a pre-configured URL whenever a specific event happens, rather than the receiving system having to poll for updates.
in-memory database →An in-memory database is a type of database management system that primarily relies on a computer's main memory (RAM) for data storage and processing, as…
storage layer →The storage layer refers to the component of a data system responsible for persistently storing and managing data.
query engine →A query engine parses, optimizes, and executes SQL queries against data sources. Learn its core architecture, how it differs from a database, and see examples like DuckDB and Presto.
FAQS
Averages can hide the experience of the slowest requests. p95 or p99 latency specifically describes tail behavior — a system can have a great average but a terrible p99 if a small fraction of requests are very slow, which percentiles surface and averages don't.
Generally yes for user-facing responsiveness, but reducing latency can sometimes trade off against throughput or cost — for example, processing requests individually as they arrive lowers per-request latency but may process fewer requests overall per second than batching them.
