# Latency percentiles are not additive

DevFeed: [Latency percentiles are not additive](<https://devfeed.tech/articles/latency-percentiles-are-not-additive-25907.md>)

Original publisher: [Read original article](<https://chao2zhang.medium.com/latency-percentiles-are-not-additive-4f306ced9cd6?source=rss-d19045640fe------2>)

Author: Chao Zhang

Published: 2023-10-07T17:02:37Z

Content type: opinion

Language: en

Sources: [Stories by Chao Zhang on Medium](<https://devfeed.tech/sources/stories-by-chao-zhang-on-medium.md>)

Topics: [Latency](<https://devfeed.tech/topics/latency.md>), [Back end](<https://devfeed.tech/topics/backend.md>), [client](<https://devfeed.tech/topics/client.md>), [Caching](<https://devfeed.tech/topics/caching.md>), [Network](<https://devfeed.tech/topics/network.md>)

Tags: [analysis](<https://devfeed.tech/tags/analysis.md>), [android](<https://devfeed.tech/tags/android.md>), [app-development](<https://devfeed.tech/tags/app-development.md>), [backend](<https://devfeed.tech/tags/backend.md>), [caching](<https://devfeed.tech/tags/caching.md>), [ios](<https://devfeed.tech/tags/ios.md>), [latency](<https://devfeed.tech/tags/latency.md>), [mobile](<https://devfeed.tech/tags/mobile.md>), [network](<https://devfeed.tech/tags/network.md>), [performance](<https://devfeed.tech/tags/performance.md>), [request](<https://devfeed.tech/tags/request.md>), [software-engineering](<https://devfeed.tech/tags/software-engineering.md>), [ui](<https://devfeed.tech/tags/ui.md>)

## AI overview

The article explains why adding the p90 latencies of sequential backend requests can overestimate the combined perceived latency. It uses a simplified example to show how client processing, network latency, and the relationship between request latency distributions affect the result.

## Source excerpt

Generated from https://mage.space/ When we are estimating the latency spanning multiple requests on the backend, we tend to use napkin math to add 90th percentile (p90) of those requests and use their summation as the estimation. However, the summation is often too pessimistic and follow me to understand why that is the case. In this simplified example, we have a UI feature displayed on the client after request A and request B are completed. Request B depends on request A, so they are sequential. The illustration of perceived latency with Request A and Request B We have backend latency p90(Request A) = 910ms, and p90(Request B) = 910ms, so we conclude the feature latency to be p90(Feature) = p90(Request A) + p90(Request B) = 1820ms. The above math is common in the latency analysis of our engineering requirement document. What did we miss here? A few points: Client logic: Client code does have non-trivial complexity. Regardless of iOS or Android, any caching layer, data transformation layer and view layer could add latency at the magnitude of 100ms or more. Network latency: The device needs to be connected to Home Wifi or 5G network, and then hit the nodes through ISP, CDN, Data Center and eventually reached our application server. These are perceived by the end user but very difficult to measure. Latency percentiles are not additive: p90(Request A and B) ≠ p90(Request A) + p90(Request B) Let's assume our feature has 10 end users from Alice to Jessica. And let's ignore client logic and estimate the network latency to be 128ms (Average of 2 RTT from US West to US East). In the most pessimistic case (napkin math pitfall!), Alice has the lowest backend latency for both requests and Jessica has the highest latency for both requests. p90(Request A and B) is 1948ms = p90(Request A) + p90(Request B) + avg(network latency) = 910ms + 910ms + 128ms. In the most optimistic though, Alice has the lowest backend latency for request A but the highest backend latency for request B,