Card 03/ 06
All 6 cards
ConceptDifficulty: Advanced1 min
A Slow Call You Don't Own
A ride-matching endpoint calls a pricing microservice. The pricing service has no bearing on your own database, your own code, or your own deployment — and if it's slow, your endpoint is exactly as slow, by default, with no limit on how long "slow" can get.
@Bean
RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder
.setConnectTimeout(Duration.ofSeconds(2))
.setReadTimeout(Duration.ofSeconds(3))
.build();
}A timeout is the first mitigation, and the cheapest: without one, a caller waits as long as the other side takes, which under a real outage can mean forever. A circuit breaker goes further — after enough recent failures, it stops calling the failing service at all for a while, failing fast instead of piling up slow, doomed requests behind it. Neither fixes the pricing service; both stop its problem from becoming yours at the same scale.
- Spring Boot
- Performance