Sub topic 2
Little’s Law, Latency Budgets, and Service Targets
Assume you know basic request/response flow and can read simple Python. Little’s law connects three averages:
\[ L = \lambda W \]
- L is the average number of items in the system, such as in-flight requests.
- λ is the arrival rate, such as requests per second.
- W is the average time each item spends in the system.
For example, 2,000 requests per second with 50 ms average latency produces about 100 in-flight requests:
arrival_rate_per_s = 2000
avg_latency_ms = 50
in_flight = arrival_rate_per_s * avg_latency_ms / 1000
print(in_flight) # 100.0Little’s law describes a stable system over time. It does not by itself guarantee capacity, prevent queueing, or describe p99 latency. Use it to estimate average concurrency, then validate the result with load tests.
Splitting a Latency Budget
Start with an end-to-end target, such as 300 ms at p99. Allocate portions to the network, gateway, application, and database. Keep unused time as headroom.
| Component | p99 allocation |
|---|---|
| Network and edge | 20 ms |
| API gateway | 10 ms |
| Application service | 80 ms |
| Database | 120 ms |
These allocations use 230 ms, leaving 70 ms of headroom. They are planning targets, not a mathematical decomposition of the end-to-end p99. Percentiles from different components do not necessarily occur in the same requests. Measure both each component and the complete user path.
Writing SLIs, SLOs, and SLAs
An SLI (service level indicator) is the measured behavior, such as the percentage of successful requests completed within 300 ms. An SLO (service level objective) is the internal target for that indicator. An SLA (service level agreement) is a customer-facing promise, often with consequences if it is missed.
A precise target might be:
- SLI: percentage of valid checkout requests completed within 300 ms.
- SLO: at least 99% during each calendar month.
- SLA: at least 99% monthly, with service credits below that level.
Exercise
A service receives 500 requests per second and has 80 ms average latency. What average concurrency does Little’s law predict?
Show answer
L = 500 × 0.080 = 40 requests in flight.