Introduce 500 ms latency
Introduce 500 ms latency
In this lab the load balancer gives up on an API instance after 400 ms, and retries once. The healthy system answers in about 100 ms, so 400 ms looks generous. You add 500 ms of latency to the network between the load balancer and the API tier. No component fails and none is slower. Watch what the timeout and the retry make of it.
The failure lab needs JavaScript. The healthy system is shown below.
1. Break it
The healthy system is shown first. When you press the button the failure strikes, and the run follows the 30 seconds after it.
What the failure does: The network between the load balancer and the API tier becomes 500 ms slower.
Each dot stands for many requests. The numbers show the real rate.
No bottleneck: every component has headroom.
Cause and effect
Each step leads to the next. A step that is changing right now is marked.
- Traffic900 req/sNormal steady
- API utilisation75%Normal steady
- API queuenone waitingNormal steady
- Latency (p99)96 msNormal steady
- Timeouts and rejections0%Normal steady
- Errors0%Normal steady
| Component | State | Utilisation | Offered (req/s) | Served (req/s) | Rejected (req/s) | p50 | p95 | p99 |
|---|---|---|---|---|---|---|---|---|
| Clients | Healthy | <1% | 900 | 900 | 0 | 0 ms | 0 ms | 0 ms |
| Load balancer | Healthy | <1% | 900 | 900 | 0 | 0.03 ms | 0.15 ms | 0.23 ms |
| API | Busy | 75% | 900 | 900 | 0 | 14 ms | 60 ms | 93 ms |
| Cache | Healthy | 1% | 810 | 810 | 0 | 0.14 ms | 0.6 ms | 0.92 ms |
| Database | Healthy | 20% | 252 | 252 | 0 | 5.5 ms | 24 ms | 37 ms |
- Traffic
- 900 req/s
- Successful
- 900 req/s
- Error rate
- 0%
- Mean latency
- 24 ms
Sources
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- Requests arrive at random, as a Poisson process, at a constant average rate.
- Each node is one queue, served first-come first-served by several identical slots (instances × concurrency).
- Service times are random with the stated mean; by default they are exponentially distributed.
- Each node is analysed separately, with the traffic it receives treated as Poisson.
- The system starts healthy at 900 requests a second. Three API instances can serve 1,200 a second and the database about 1,250 operations a second. Nine in ten requests read through the cache, which answers four in five of those reads; the rest, and every write, go to the database.
- A failure strikes at one instant and nothing repairs it during the run: no restart, no autoscaling, no operator. The load balancer notices a dead instance at once.
- The instances of a component are identical, and each request is independent of the others.
Simplifications
- The delay is a constant 500 ms on every request that crosses the link. Real latency varies from request to request, and it often comes with lost packets.
- While it waits for the slow link, a real API instance would hold a worker. Here it does not, which makes the model kinder than reality (see the engine’s notes).
- A retry is a fresh, independent attempt with the same chance of failing as the last one. How long a real client library waits between attempts (backoff, jitter), and any retry budget or circuit breaker, are not simulated: attempts are counted, not scheduled.
- A client gives up when its first timeout runs out, so the latency shown stops at what a client would wait: the timeout of the first hop, times its attempts. After that the request counts as a failure.
- The cache's hit ratio is constant. Warming, stampedes and hot keys have their own labs.
- Nothing here models garbage collection, connection pools on the client, DNS, TLS handshakes, CPU throttling, noisy neighbours or cold caches. A real system fails in more ways, and in messier ones, than this model does.
- Above capacity there is no steady state. The model switches to a fluid approximation: the node serves at capacity, its queue grows until it reaches its limit, and further requests are rejected.
- Percentiles assume an exponential tail. A service-time variability other than exponential changes the mean wait but not the shape of the tail.
- A node frees its slot as soon as it has done its own work, before waiting on the services it calls. Real thread-per-request servers hold the slot, so a slow dependency exhausts them faster than this model shows.
- A request calls its dependencies one after another. Parallel fan-out is not modelled.
- When a caller times out and gives up, the callee still finishes the work, so abandoned requests keep consuming capacity.
- Retries add load. Their backoff and jitter decide when that load arrives, which only the per-request simulation shows.
- A caller’s timeout counts the mean time its dependencies take, not their full distribution.
- Latency percentiles for a whole request are estimated, over every request, including those that are rejected and fail quickly. The mean is exact, and the percentiles come from a gamma distribution that has that mean and the variance of the time spent in each component.
Parameter values are illustrative. They are not benchmarks of any real product.
Built by GhaziAlibi.
© ShardCraft. All rights reserved.