The Unavailable Service
Recommendations are a small widget at the bottom of the page. Why did the entire homepage go down with them?
此挑战尚未翻译为简体中文,你正在阅读英文版本。
任务:With recommendations down, keep the homepage fast and error-free, and stop hammering the failing service so it can recover.
Fernway's homepage service calls the recommendations service on every request. Tonight recommendations is overloaded: each call takes 600 ms or more, and requests pile up until it barely answers at all. The homepage waits, its 120 threads fill up, and the site is down — over a non-critical feature.
任务: With recommendations down, keep the homepage fast and error-free, and stop hammering the failing service so it can recover.
学习目标
- Identify critical vs non-critical dependencies.
- Combine timeouts, circuit breakers and fallbacks.
- Give a failing dependency room to recover.
模拟模拟数据
@CircuitBreaker(name = "recommendations", fallbackMethod = "popularProducts")@TimeLimiter(name = "recommendations") // timeout-duration: 200mspublic CompletableFuture<List<Product>> recommendations(long userId) { return CompletableFuture.supplyAsync(() -> recoClient.forUser(userId));}CompletableFuture<List<Product>> popularProducts(long userId, Throwable t) { return CompletableFuture.completedFuture(popularCache.top(12)); // non-personalised, but the page renders}// resilience4j.circuitbreaker.instances.recommendations: failure-rate-threshold 50, wait-duration-in-open-state 30s