Reactor Challenges
Master reactive programming with hands-on Kotlin challenges. Write, run, and validate your Reactor code.
0/40 completed (0%)
Mono & Flux
0/4- Easy#1
Create Your First Mono
Create a Mono that emits the string "Hello Reactor" and subscribe to it, printing the value.
Solve - Easy#2
Sum a Flux Range
Create a Flux that emits integers from 1 to 10, then reduce them to compute their sum and print it.
Solve - Medium#3
Handle Empty Mono
Create an empty Mono and provide a default value of "Default Value" using the appropriate operator, then subscribe and print.
Solve - Medium#4
Collect Flux to List
Create a Flux emitting "Kotlin", "Spring", "Reactor" and collect all elements into a single List. Print the list.
Solve
Operators
0/4- Easy#1
Transform with Map
Create a Flux emitting 1, 2, 3, 4, 5. Use the map operator to square each number, then subscribe and print each result on a new line.
Solve - Easy#2
Filter Even Numbers
Create a Flux emitting integers 1 through 10. Use the filter operator to keep only even numbers. Subscribe and print each on a new line.
Solve - Medium#3
Expand with FlatMap
Create a Flux emitting "Hello", "World". Use flatMap to split each word into individual characters (as separate emissions). Subscribe and print each character.
Solve - Medium#4
Combine with Zip
Zip two Flux sources together:
Solve
Error Handling
0/4- Easy#1
Fallback on Error
Create a Flux that emits 1, 2, 3 then throws a RuntimeException("Boom!"). Use onErrorReturn() to provide -1 as a fallback value. Subscribe and print all values.
Solve - Medium#2
Resume with Fallback Stream
Create a Flux that emits "A", "B" then throws an error. Use onErrorResume() to switch to a fallback Flux emitting "X", "Y", "Z". Subscribe and print all values.
Solve - Medium#3
Retry on Failure
Create a Flux using Flux.defer() with a counter. On the first 2 calls, emit an error. On the 3rd call, emit "Success!". Use retry(2) to automatically retry. Print the output.
Solve - Hard#4
Log Errors with doOnError
Create a Flux that emits 10, 20, 0, 30. Map each to 100/element. Use doOnError to print "Error: <message>" before recovering with onErrorReturn(-1). Subscribe and print.
Solve
Backpressure
0/4- Easy#1
Limit Consumption Rate
Create a Flux emitting 1 through 20 and use limitRate(5) to request items in batches of 5. Use doOnRequest to print how many items are requested at each batch. Subscribe and print each value.
Solve - Medium#2
Buffer Elements
Create a Flux emitting 1 through 12 and use buffer(4) to collect elements in batches of 4. Subscribe and print each batch.
Solve - Medium#3
Sample Latest Values
Create a Flux emitting 1 through 10, then use take(3) to only consume the first 3 elements (simulating a slow consumer). Subscribe and print.
Solve - Hard#4
Window Processing
Create a Flux of 1 through 9 and use window(3) to split it into windows of 3. For each window, collect to a list and print it.
Solve
Hot vs Cold Publishers
0/4- Easy#1
Cold Publisher Behavior
Create a cold Flux that emits "A", "B", "C". Subscribe to it twice, and for each subscriber print with a prefix: "Sub1: A" and "Sub2: A". This demonstrates that cold publishers replay for each subscriber.
Solve - Medium#2
Share a Hot Publisher
Create a Flux emitting "A", "B", "C" and use .share() to make it hot. Subscribe twice. Hot publishers share the execution: the second subscriber may miss items already emitted.
Solve - Medium#3
Replay with Cache
Create a Flux emitting "A", "B", "C" and use .cache() to replay all elements to late subscribers. Subscribe twice and verify both get all values.
Solve - Hard#4
ConnectableFlux with AutoConnect
Create a Flux of "X", "Y", "Z". Use .publish() to make it connectable, then .autoConnect(2) to auto-start when 2 subscribers are connected. Subscribe twice and print with prefixes.
Solve
WebClient & WebFlux
0/4- Easy#1
WebClient GET Pattern
Write the Kotlin code that demonstrates a WebClient GET request pattern. Create a mock function that simulates fetching a user by ID. Return a Mono with "User: John (id=1)". Print the result.
Solve - Medium#2
Chain Reactive Calls
Simulate two chained WebClient calls. First, fetch a user ID from getActiveUserId() which returns Mono<Int> with value 42. Then, use flatMap to fetch user details from getUserDetails(id) which returns Mono<String> with "User #42 - Active". Print the final result.
Solve - Medium#3
Parallel Calls with Zip
Simulate two parallel WebClient calls using Mono.zip(). Call getUser() which returns Mono.just("Alice") and getRole() which returns Mono.just("Admin"). Zip them together and print "Alice is Admin".
Solve - Hard#4
HTTP Error Fallback Pattern
Simulate a WebClient call that fails. Create fetchFromPrimary() that returns Mono.error(RuntimeException("Service unavailable")). Create fetchFromFallback() that returns Mono.just("Fallback data"). Chain them with onErrorResume and print the result.
Solve
Testing Reactive Code
0/4- Easy#1
StepVerifier Basics
Write a StepVerifier test for a Flux emitting "A", "B", "C". Verify each element in order, then verify completion. Print "Test passed!" at the end.
Solve - Medium#2
Verify Error Signals
Write a StepVerifier test for a Flux that emits "OK" then throws an IllegalStateException("Boom"). Verify the element, then verify the error. Print "Error test passed!".
Solve - Medium#3
Verify Element Count
Create a Flux emitting 1 through 100 and verify it emits exactly 100 elements using StepVerifier. Use expectNextCount(). Print "Count test passed!".
Solve - Hard#4
Custom Assertions
Create a Flux of 2, 4, 6, 8 and use StepVerifier with assertNext() to verify each element is even. Print "Assert test passed!" after verification.
Solve
Kafka & Messaging Patterns
0/4- Easy#1
Publish-Subscribe Pattern
Simulate a Kafka pub-sub pattern. Create a "topic" as a Flux emitting "order-1", "order-2", "order-3". Subscribe two consumers: "Consumer A" and "Consumer B". Each should print their name and the message.
Solve - Medium#2
Dead Letter Queue Pattern
Simulate a DLQ pattern. Process messages "msg-1", "msg-2", "POISON", "msg-3". If a message equals "POISON", route it to a DLQ (print "DLQ: POISON"), otherwise process normally (print "Processed: msg-1"). Use Flux operators to implement this.
Solve - Medium#3
Request-Reply Pattern
Simulate a request-reply pattern. Create a processRequest() function that takes a String request and returns Mono<String> with "Reply to: <request>". Send requests "ping", "hello", "status" and print each reply.
Solve - Hard#4
Content-Based Routing
Implement content-based routing. Given messages with types: "ORDER:laptop", "LOG:debug info", "ORDER:phone", "LOG:error info". Route ORDER messages to an orders stream and LOG messages to a logs stream. Use groupBy() operator and print with appropriate labels.
Solve
Resilience Patterns
0/4- Easy#1
Timeout with Fallback
Create a Mono that simulates a slow service by delaying 5 seconds. Apply a timeout of 1 second and provide a fallback value "Timeout fallback" using onErrorReturn. Subscribe and print.
Solve - Medium#2
Retry with Backoff
Create a service that fails the first 2 times and succeeds on the 3rd. Use retryWhen with Retry.fixedDelay(2, Duration.ofMillis(100)) to retry with delay. Print the result.
Solve - Hard#3
Circuit Breaker Simulation
Simulate a circuit breaker. Create a call counter and a function callService() that:
Solve - Hard#4
Bulkhead with FlatMap Concurrency
Simulate the bulkhead pattern using flatMap concurrency. Create a Flux of task IDs 1 through 6 and process them with flatMap limited to 2 concurrent tasks. Each task should print "Processing task <id>" and return "Done <id>". Print results.
Solve
Advanced Reactive Patterns
0/4- Easy#1
Merge Multiple Streams
Merge three Flux sources into one:
Solve - Medium#2
Running Total with Scan
Create a Flux of 1, 2, 3, 4, 5 and use scan() to compute a running total. Print each intermediate sum.
Solve - Medium#3
Switch to Latest with SwitchMap
Create a Flux of "search-1", "search-2", "search-3" (simulating user typing). Use switchMap to process only the latest emission. Each should transform to "Results for: <query>". Print results.
Solve - Hard#4
Reusable Transform Pipeline
Create a reusable transform function called `addLogging` that takes a Flux<String> and returns a Flux<String> that:
Solve