Spring WebFlux
26 questions in 7 subtopics.
WebFlux vs MVC
What are the main differences between Spring MVC and Spring WebFlux in threading model, supported servers and programming model?A team proposes rewriting a CRUD service backed by PostgreSQL and JPA from MVC to WebFlux for better performance. How do you evaluate this proposal?Set a company standard for choosing among Spring MVC, Spring MVC with virtual threads, and WebFlux for new services. What criteria would you write down?Looking back, many organisations adopted reactive stacks around 2017-2020 and some later moved back to blocking code with virtual threads. What lessons do you draw about adopting programming-model shifts?Annotated and functional endpoints
Write a WebFlux functional endpoint that routes GET /persons/{id} and POST /persons to a handler class, and compare it with the annotated controller style.Your team mixes annotated controllers and router functions in one WebFlux service. How do you keep cross-cutting concerns (validation, error handling, security, documentation) consistent?Should your organisation standardise on annotated controllers or functional endpoints for Spring web services? What factors would you weigh?Netty event loop
How many event-loop threads does Reactor Netty use by default in a Spring WebFlux application, and what are they responsible for?p99 latency in a WebFlux service spikes from 20 ms to 3 seconds under moderate load while CPU usage stays low. Thread dumps show reactor-http-nio threads insocketRead and in a JDBC driver. Explain the cause and the fix.A gateway built on Spring Cloud Gateway (WebFlux) handles 50,000 requests per second. A custom filter added by one team makes a synchronous call to a token introspection endpoint. What is the fleet-level risk and how do you prevent this class of problem?Your API gateway and several edge services run on a Netty-based reactive stack maintained by a small group of experts who are leaving. How do you manage the long-term risk of critical infrastructure depending on scarce skills?Blocking calls in reactive code
A WebFlux handler callssomeMono.block() and fails with IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3. Why does Reactor throw this, and what should the code do instead?What is BlockHound, and how would you use it in a WebFlux project?You must call a legacy blocking SDK (sdk.lookup(id) takes 200 ms) from a WebFlux service handling 2,000 requests per second. Write the code and explain how to size the resources.R2DBC
What is R2DBC and how does Spring Data R2DBC differ from Spring Data JPA?You are designing a reactive service with R2DBC that needs an Order with itsOrderLines. How do you load and save aggregates without JPA relationships?Would you allow R2DBC as a standard data access option across the organisation? What would you compare it with?Five years ago your organisation chose R2DBC for all new services to be fully reactive. Driver support, tooling and hiring have been harder than expected, and virtual threads now offer an alternative. How would you reassess the bet and manage the exit cost?Error handling
In Reactor, what areonErrorResume, onErrorReturn, onErrorMap and doOnError used for? Write a pipeline that maps a WebClient 404 to an empty result and any other error to a ServiceUnavailableException.A Flux of 10,000 items stops processing at item 37 because one item throws an exception in map. The team wants processing to continue for the other items. What options exist?Define a consistent error-handling standard for WebFlux services: how exceptions map to HTTP responses, what is logged, and how upstream errors are translated.After years of growth, every service in your company reports errors differently, which makes cross-service incident analysis slow. What error-reporting standard would you set across MVC and WebFlux services, and how would you sustain it?Context propagation
Why does MDC-based logging lose the trace id in a Reactor pipeline, and what does Reactor Context offer instead?How does automatic context propagation work in Spring Boot 3 with Reactor and Micrometer, so that log lines inside operators include the trace id?Tracing data is missing for calls that go through a mix of WebFlux services, Kafka consumers and MVC services. How would you get consistent context propagation across the fleet?Observability and security context (trace ids, user identity, tenant) must flow through MVC, WebFlux, virtual threads, messaging and batch jobs across hundreds of services for the next decade. What long-term standard would you set?No question matches these choices.