Spring / Spring7 Intermediate to Advanced Interview questions
Which is better and why: RestClient or WebClient for a blocking Spring MVC service?
RestClient is the better fit for a classic, blocking Spring MVC application. It's purpose-built for synchronous use - a call to .retrieve().body(Product.class) returns the object directly, with no Mono/Flux wrapping or .block() calls needed - which matches how an MVC controller thread already operates and keeps the client code simple to read, debug, and unit test with plain mocks.
// RestClient: fits naturally in a blocking MVC method Product product = restClient.get().uri("/products/{id}", id).retrieve().body(Product.class); // WebClient in the same MVC method: adds reactive overhead for no benefit Product product = webClient.get().uri("/products/{id}", id).retrieve() .bodyToMono(Product.class).block();
WebClient earns its place specifically inside a WebFlux, reactive stack, or when a service genuinely needs to fan out multiple concurrent downstream calls and compose their results non-blockingly with Mono/Flux operators. Reaching for WebClient inside a blocking MVC controller just to "use the newer API" adds a layer of reactive wrapping and an explicit .block() call that provides no real concurrency benefit in a thread-per-request (or virtual-thread) model, while making the code harder to follow than the equivalent RestClient call.
More Related questions...