Sub topic 1
Latency, Throughput, and Concurrency
Prerequisites
Assume you understand basic client-server requests and common backend components such as load balancers, services, and databases. You should also be comfortable with simple Python arithmetic.
Latency, throughput, and concurrency
Latency is the time one request takes from start to finish. It is usually measured in milliseconds. Throughput is the number of requests completed per second. Concurrency is the number of requests being processed at the same time.
These measures describe different limits:
| Measure | Question it answers |
|---|---|
| Latency | How long does one request take? |
| Throughput | How many requests can the system complete? |
| Concurrency | How many requests are active now? |
A system can have high throughput but poor latency if it processes many slow requests in parallel. Concurrency connects the two: more concurrent work can increase throughput until queues, CPU, memory, or another resource becomes saturated.
Starting from user and business requirements
Begin with user-visible outcomes, then make them measurable. For example:
- “Search should feel fast” becomes “95% of searches finish within 300 ms.”
- “The service must support 50,000 daily users” becomes a request rate after estimating actions per user.
- “Checkout must remain available” becomes an availability target over a stated period.
State the workload, measurement window, percentile, and failure definition. A target without these details cannot guide design or testing.
Why percentiles beat averages
An average hides the distribution. If nine requests take 10 ms and one takes 900 ms, the average is 99 ms. Most users experienced about 10 ms, but one user experienced a long wait.
A percentile gives a threshold that a specified share of requests meets. The p50 is the median. The p99 is the value that 99% of requests meet, leaving 1% slower. Track several percentiles because p50 describes typical behavior while p95 or p99 exposes tail latency.
> callout note > Tail latency matters when requests are user-facing or when one slow dependency delays a larger operation.
Estimating load: average, peak, and headroom
Estimate average traffic from users and actions, then apply a peak factor. Add headroom for growth, retries, and uneven traffic.
daily_requests = 4_320_000
average_rate = daily_requests / (24 * 60 * 60)
peak_rate = average_rate * 4
target_rate = peak_rate * 1.5
print(round(average_rate, 1), round(target_rate, 1))Document assumptions and validate them with production measurements or a load test.
Exercise
A service receives 500 requests per second with 200 ms average latency. What average concurrency does this imply?
Show answer
100 requests, because concurrency is approximately throughput × latency: 500 × 0.2.