HTTP clients
36 questions in 9 subtopics.
RestTemplate
What is the status ofRestTemplate in current Spring versions, and what would you use for new synchronous HTTP code?A service using new RestTemplate() hangs for minutes when a downstream service stops responding, eventually exhausting the Tomcat thread pool. What is wrong and how do you fix it?Your codebase has 300 RestTemplate call sites with custom interceptors and error handlers. Plan a migration to RestClient that does not stop feature work.Spring has introduced several HTTP client APIs over the years (RestTemplate, AsyncRestTemplate, WebClient, RestClient, HTTP interfaces). What lessons does this offer for how much application code should depend on a specific client API?RestClient
What is the difference betweenretrieve() and exchange() in RestClient?Write a RestClient call that fetches GET /users/{id} into a UserDto, throws a custom NotFoundException on 404, and sets a bearer token header.Design how a Spring Boot service configures RestClient instances for five downstream services, each with different base URLs, timeouts, authentication and observability needs.Your organisation uses Feign, RestTemplate, WebClient and RestClient across services. Would you standardise on one HTTP client approach, and how?WebClient
A Spring MVC service callswebClient.get().uri(url).retrieve().bodyToMono(Dto.class) but nothing is ever sent to the downstream service. Why?A WebClient-based service logs 'PrematureCloseException: Connection prematurely closed BEFORE response' intermittently. What is a likely cause and how do you address it?A WebFlux service makes three independent WebClient calls per request and returns a combined result. Latency equals the sum of the three. What is wrong in code like a.flatMap(x -> b.flatMap(y -> c.map(z -> combine(x,y,z)))) and how do you fix it?A blocking Spring MVC service uses WebClient with block() everywhere because RestClient did not exist when it was written. Should it be changed, and how would you decide?HTTP interface clients
Write an HTTP interface client for GET /products/{id} and POST /products, and show how to create the proxy backed byRestClient.Your team uses Spring Cloud OpenFeign. Would you move to Spring HTTP interface clients, and what would you check before doing so?Would you publish shared HTTP interface client libraries for each service so consumers just add a dependency? Discuss the coupling and versioning consequences.Your company integrates with more than 300 external and internal HTTP APIs. Should outbound integration be a central platform (an integration team, gateway or iPaaS) or a set of standards each team applies with its own clients? Discuss the long-term costs of each.Timeouts and connection pools
Name the different timeouts that apply to an outgoing HTTP call from a Spring service and explain what each protects against.Under load, outgoing calls through ApacheHttpClient 5 queue for seconds even though the downstream service responds in 20 ms. Thread dumps show threads waiting in the connection pool. What do you check and change?A service calls a dependency with a 10 second read timeout, and its own callers use a 5 second timeout. What problems does this cause and how should timeouts be set along a call chain?After several cascading outages caused by missing or very long HTTP timeouts, how would you set and enforce timeout standards across 100 services?Over many years, outages in your organisation have repeatedly come from outbound calls without limits: missing timeouts, unbounded pools, retry storms. How would you make resilient client behaviour a lasting property of the organisation rather than something each new team must relearn?Retries
When is it safe to retry a failed HTTP call, and what retry policy would you use?How would you add retries with exponential backoff to a WebClient call that should only retry on connection errors and 503 responses?During a downstream slowdown, traffic to that service increased to 27 times normal and it collapsed. Each of three layers retried 3 times. Explain the effect and how to fix it.Design a resilience policy (retries, timeouts, circuit breakers, bulkheads) for a checkout flow that calls pricing, inventory and payment services. Which calls do you retry and which do you not?Client-side load balancing
What does@LoadBalanced do on a RestClient.Builder or WebClient.Builder bean in Spring Cloud?Your services run on Kubernetes. Would you use Spring Cloud LoadBalancer with discovery, rely on Kubernetes Services, or use a service mesh? What trade-offs drive the choice?Your platform has client-side load balancing and retries in Java libraries, and a mesh is being introduced. How would you decide which concerns live in the application and which in the platform?A cloud provider's managed load balancing and service discovery would replace your self-run Spring Cloud discovery and client-side balancing. How do you weigh the reduced operations against vendor dependency over a ten-year horizon?Over 15 years the industry moved from hardware load balancers to client libraries (Ribbon, Hystrix) to service meshes. What does this history suggest for long-term decisions about where networking logic should live?Retrofit
Write a Retrofit interface for GET /users/{id} returning a User, build the client with a Jackson converter and timeouts, and make a synchronous call.A Spring Boot team uses Retrofit with OkHttp for all outbound calls. Should they move to Spring's HTTP interface clients withRestClient? What would you compare?A shared Retrofit-based SDK used by 40 services creates a new OkHttpClient for every API instance, and services run out of threads and file descriptors. Explain and fix at the library level.HTTP client logging
Log the method, URL, status and duration of every outgoing call made with Spring'sRestClient without logging secrets.You need to see what bytes a WebClient call sends and receives to debug a TLS or header problem in staging. How do you enable wire logging, and what are the risks?Define a standard for outbound HTTP logging and telemetry across 100 services.No question matches these choices.