Exercise — Bulkhead Pattern: isolate a slow dependency behind its own pool.
Topic: microservices, Resilience. Level: Intermediate.
Answer
Give the slow dependency a dedicated, small thread pool (thread-pool bulkhead) so its saturation rejects only its own calls while the main request threads stay free. Combine with a fallback when the bulkhead is full.
```java
@Service
class ReportService {
@Bulkhead(name = "report", type = Bulkhead.Type.THREADPOOL,
fallbackMethod = "busy")
public CompletableFuture<Report> generate(String id) {
return CompletableFuture.completedFuture(reportClient.build(id));
}
CompletableFuture<Report> busy(String id, Throwable t) {
return CompletableFuture.completedFuture(Report.tryLater()); // rejected when full
}
}
```