When Online Adaptation of Resilience Policies Hurts: Safe Exploration and Measurement Pitfalls in Resilience4j
Organizations: Department of Computer Science, State University of New York, Binghamton, Binghamton, NY, USA · Department of Software Engineering, Arizona State University, Tempe, AZ, USA
Abstract
Circuit breaker, retry, and bulkhead settings in Java microservices are tuned once and frozen, although the best setting depends on the fault a dependency is currently showing. We study whether an online learner can pick these settings at runtime. AdaptR4j swaps Resilience4j policies atomically in Spring Boot 3 and lets a contextual bandit choose among complete CircuitBreaker/Retry/Bulkhead configurations from Prometheus signals. Our first, naive design scored worse than keeping the default policy in three of four winnable fault scenarios under the reward it optimised: exploring a menu that contained aggressive circuit breakers rejected most traffic while the learner was still learning. Two safeguards fix this: a safe policy menu (no breaker stricter than the latency SLO) and safe exploration with a bounded reward. With them, AdaptR4j beats the production default in every winnable scenario (p < 0.001, three runs each, run-to-run SD <= 0.03), beats the best fixed policy when the fault changes over time, and cuts user-visible failures up to 3.7x compared with the naive design. A context-free bandit on the same safe menu performs statistically indistinguishably, so the safeguards - not the learner - carry most of the benefit. We also report how an earlier version of our harness produced convincing but wrong results: a unit mismatch made every circuit breaker 100x too strict and rejected calls were invisible to the metrics, so 94% of user requests failed while latency and error metrics looked excellent.
Figures & tables
| Harness | Scen. | p99 seen | errors seen | users failed |
|---|---|---|---|---|
| original | S1 | 138 ms | 0.10 % | 94.5 % |
| original | S2 | 106 ms | 0.06 % | 97.4 % |
| fixed | S1 | 280 ms | 0.12 % | 0.1 % |
| fixed | S2 | 854 ms | 3.64 % | 6.0 % |
| AdaptR4j (safe design) | Default p01 | Best fixed policy | UCB1, safe menu | Naive design | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Scen. | reward | late | fail% | reward | fail% | reward | fail% | reward | fail% | reward | fail% |
| S1 | 0.1 | 0.1 | 0.0 | 0.8 | 0.3 | ||||||
| S2 | 5.8 | 1.0 | 9.4 | 4.0 | 9.4 | ||||||
| S3 | (1 run) | 0.8 | 0.0 | 0.0 | – | – | 10.6 | ||||
| S4 | 9.4 | 32.5 | 2.6 | 14.0 | 31.4 | ||||||
| S5 | 2.3 | 0.0 | 0.0 | 0.4 | 8.5 | ||||||
Contextual Bandits
Contextual bandits learn which action to take from features of each situation when only the chosen action’s reward is observed.
See all 164 papers