Scrivio Interview library

Reactive streams and Project Reactor

22 questions in 6 subtopics.

Reactive Streams specification

ConceptFoundations6 min read
Describe the four interfaces of the Reactive Streams specification and the order of signals between a Publisher and a Subscriber.
InternalsIntermediate7 min read
Why does the Reactive Streams specification forbid calling onNext concurrently and require request(n) to be positive? What goes wrong in a hand-written Publisher that ignores these rules?
LeadershipPrincipal5 min read
Reactive Streams became a standard interface (and part of the JDK as Flow) so that libraries could interoperate. What does its adoption history suggest about betting on low-level concurrency standards for an organisation?

Mono and Flux

ConceptFoundations5 min read
What is the difference between Mono.just(loadUser()) and Mono.fromCallable(() -> loadUser())?
DebuggingFoundations6 min read
In this code, sendEmail is called even when the user exists: findUser(id).switchIfEmpty(createUser(id)).flatMap(...) where createUser sends a welcome email when the method is called. Why, and how do you fix it?
CodingIntermediate6 min read
Review this method:
public Mono<Order> place(Order o) {
repository.save(o).subscribe();
return Mono.just(o);
}
What is wrong and how would you write it?

Operators

ConceptFoundations5 min read
Explain the difference between map, flatMap, concatMap and flatMapSequential in Reactor.
CodingFoundations6 min read
You have Flux<Long> userIds and a method Mono<User> fetch(Long id) that calls a remote service. Write a pipeline that fetches at most 10 users concurrently and collects them into a List.
DebuggingIntermediate7 min read
A Flux pipeline uses .flatMap(x -> repo.save(x)) to save 1 million records and exhausts the database connection pool, failing with pool acquire timeouts. Why, and how do you fix it?
DesignAdvanced6 min read
You are writing coding guidelines for reactive code in your organisation. Which operator-level rules would you include to prevent the most common production bugs?

Backpressure

ConceptFoundations8 min read
What is backpressure in Reactor and what happens when a producer like Flux.interval emits faster than the subscriber can process?
ScenarioIntermediate7 min read
A WebFlux endpoint streams database rows to slow clients over HTTP. How does backpressure flow end to end, and where can it break?
DesignAdvanced7 min read
Design how a Kafka-consuming reactive service applies backpressure so that a slow downstream database does not cause unbounded memory growth or lag spikes.
DesignPrincipal7 min read
Your company's data flows (APIs, event streams, batch feeds) have no consistent way of handling overload: some drop data, some buffer until memory runs out. Describe a company-wide approach to flow control and overload that will hold up as traffic grows over years.

Hot vs cold publishers

ConceptFoundations6 min read
What is the difference between a cold and a hot publisher in Reactor? Give an example of each.
CodingIntermediate7 min read
How would you use Reactor Sinks to broadcast events from a non-reactive listener to multiple SSE subscribers, and what thread-safety rule must you follow?
DebuggingIntermediate6 min read
A service calls a pricing API twice per request. The code builds Mono<Price> price = client.getPrice(id); and then uses price in two places in Mono.zip(price.map(...), price.map(...)). Why are there two calls and how do you fix it?
ScenarioAdvanced7 min read
A reactive service caches the result of a configuration call with a Mono stored in a field and cache(). Months later, stale configuration causes an incident. What went wrong, and what pattern would you standardise?

Schedulers and threading

ConceptFoundations6 min read
What is the difference between publishOn and subscribeOn, and which scheduler should you use for wrapping a blocking call?
InternalsIntermediate6 min read
How is Schedulers.boundedElastic() bounded, what happens when the bound is reached, and how does it relate to virtual threads on Java 21?
ScenarioAdvanced6 min read
A team built a reactive service but wraps almost every call (JPA, a legacy SOAP client, file I/O) in subscribeOn(boundedElastic). Throughput is worse than the old MVC service. What would you advise?
LeadershipPrincipal6 min read
Java concurrency models for servers have shifted from thread pools to asynchronous callbacks, to reactive streams, and now to virtual threads. How should a long-lived organisation make concurrency-model choices so that each shift does not require rewriting its services?