According to the Reactive Manifesto (version 2.0, 2014), a Reactive System is responsive, resilient, elastic and message-driven. Responsiveness is the goal; resilience and elasticity keep it responsive under failure and changing load; asynchronous message passing is the foundation that makes the other three possible.
Read full answerHide full answer
Applies tothe Reactive Manifesto 2.0 (architecture-level, independent of language or framework)
The Four Traits
Responsive: the system answers in a timely, consistent way. Users and callers get predictable latency (for example a p99 that stays under a few hundred milliseconds), and problems are detected quickly instead of hanging.
Resilient: the system stays responsive when parts of it fail. Failures are contained inside a component (isolation), handled by another component (delegation) and recovered from by restarting or failing over (replication).
Elastic: the system stays responsive as load changes, by adding or removing resources (instances, partitions, threads) automatically. This needs a design with no central bottleneck, so work can be sharded or replicated.
Message-driven: components talk through asynchronous, non-blocking messages. This gives loose coupling in time and space, explicit back-pressure, and location transparency (a component does not care whether the receiver is local or remote).
How the Traits Depend on Each Other
Trait
Role
Made possible by
Responsive
The value delivered to users
Resilience + elasticity
Resilient
Responsive under failure
Message-driven isolation
Elastic
Responsive under varying load
Message-driven, location-transparent design
Message-driven
The foundation
Asynchronous messaging, back-pressure
A useful way to say it in an interview: message-driven is the means, elastic and resilient are the forms, responsive is the value.
A Concrete Example
Consider an order service in an e-commerce checkout:
The API accepts the order, writes an OrderPlaced event to a log such as Kafka and returns 202 Accepted quickly (responsive).
Payment, inventory and email consumers process the event independently. If the email service crashes, orders are still accepted and the email is sent once it restarts (resilient).
During a sale, more consumer instances join the consumer group and partitions are rebalanced across them (elastic).
All of this works because services exchange messages instead of calling each other synchronously (message-driven).
Reactive Systems vs Reactive Programming
Reactive programming (Reactor, RxJava, Akka Streams) is a coding style for asynchronous data streams inside one component.
Reactive systems is an architecture property across components. You can use reactive programming without building a reactive system, and you can build a reactive system with plain message queues.
Trade-offs and Common Mistakes
Cost: asynchronous flows are harder to debug and trace; you need correlation IDs, distributed tracing and idempotent consumers.
Eventual consistency: message-driven designs usually give up immediate consistency across services.
Common mistake: listing the four traits as a checklist without explaining how message-driven communication enables the other three. Interviewers usually follow up with “how would you make this service resilient?” or “what is back-pressure?”.
2
How is back-pressure implemented in Reactive Systems?
KnownRevise
Back-pressure is a feedback mechanism that lets a slow consumer tell a fast producer how much data it can accept, so the producer slows down instead of overwhelming the consumer. In the Reactive Streams standard it is implemented as demand signalling: the subscriber calls request(n) and the publisher may send at most n more items.
Without back-pressure, a producer emitting 50,000 events per second into a consumer that handles 5,000 per second fills an unbounded buffer until the process runs out of memory, or it drops data silently. Back-pressure turns that hidden failure into an explicit, controlled flow rate.
How Demand Signalling Works
The subscriber subscribes and receives a Subscription.
It calls subscription.request(n) to ask for n items.
The publisher emits at most n items via onNext, then waits for more demand.
The subscriber requests more as it finishes work, often in small batches.
The stream ends with onComplete or onError.
This is a pull-push hybrid: data is pushed, but only as much as has been pulled.
Strategies When the Source Cannot Slow Down
Some sources, such as user clicks, market ticks or sensor readings, cannot be paused. Operators then decide what to do with the excess:
Strategy
Reactor operator
Trade-off
Bounded buffer
onBackpressureBuffer(n)
Absorbs bursts; fails or drops when full
Drop newest
onBackpressureDrop()
No memory growth; data loss
Keep latest
onBackpressureLatest()
Good for prices or status; intermediate values lost
Batch
buffer(n) / window(...)
Fewer, larger units of work
Sample / throttle
sample(Duration)
Lower rate, approximate data
Across Service Boundaries
Back-pressure must also cross the network, or it stops at the first socket:
TCP flow control slows the sender when the receiver’s window fills.
RSocket and gRPC streaming carry demand (request(n) frames, HTTP/2 flow-control windows) between services.
Message brokers give natural back-pressure: Kafka consumers pull records at their own pace, and consumer lag shows the pressure.
Code Example
A Reactor subscriber that processes items in batches of 10:
import org.reactivestreams.Subscription;
import reactor.core.publisher.BaseSubscriber;
import reactor.core.publisher.Flux;
public class BatchedSubscriber extends BaseSubscriber<Integer> {
private int received = 0;
@Override
protected void hookOnSubscribe(Subscription subscription) {
request(10); // initial demand: at most 10 items
}
@Override
protected void hookOnNext(Integer value) {
System.out.println("processing " + value);
if (++received % 10 == 0) {
request(10); // ask for the next batch only when this one is done
}
}
public static void main(String[] args) {
Flux.range(1, 35).subscribe(new BatchedSubscriber());
}
}
Best Practices and Pitfalls
Keep buffers bounded: an unbounded buffer only delays the out-of-memory error.
Decide the overflow policy per data type: payments must never be dropped; UI telemetry can be sampled.
Watch for blocking calls: a blocking JDBC call inside a reactive chain stalls the thread and breaks the flow; move it to a bounded thread pool.
Monitor it: buffer sizes, dropped-item counts and consumer lag are the signals that back-pressure is active.
A common interview follow-up is “what happens at the HTTP edge?” The usual answer is rate limiting and 429 Too Many Requests with Retry-After.
3
What is the difference between elasticity and scalability in Reactive Systems?
KnownRevise
Scalability is a system’s ability to handle more load by adding resources; elasticity is the automatic, ongoing adjustment of those resources up and down to match the current load. A scalable system can grow; an elastic system grows and shrinks by itself, in near real time, without a human resizing it.
Read full answerHide full answer
Applies toarchitecture concepts from the Reactive Manifesto 2.0; examples use Kubernetes HPA and Kafka consumer groups
Scalability
Definition: throughput grows roughly in proportion to added resources.
Vertical scaling: a bigger machine (more CPU, RAM). Simple, but limited and usually needs a restart.
Horizontal scaling: more machines or instances. Needs stateless services or partitioned state.
Time scale: often a planned change (capacity planning for next quarter).
Limit: any shared bottleneck, such as a single database primary, a global lock or a central coordinator, caps it (Amdahl’s law).
Elasticity
Definition: capacity follows demand automatically, both up and down.
Requires: scalability first, plus metrics, an autoscaler and fast startup.
Time scale: seconds to minutes.
Value: stays responsive during spikes and saves money when quiet.
Comparison
Aspect
Scalability
Elasticity
Question it answers
Can we handle 10x load?
Do we follow load as it changes?
Direction
Usually up
Up and down
Trigger
Planned, often manual
Automatic, metric-driven
Main benefit
Capacity
Responsiveness + cost efficiency
Example
Sharding a database to 8 nodes
Kubernetes HPA going from 3 to 20 pods during a sale
Examples in Reactive Systems
Scalable but not elastic: a Cassandra cluster sized for peak load. It handles Black Friday traffic, but runs 12 nodes all year.
Elastic: a stateless checkout API on Kubernetes with a Horizontal Pod Autoscaler targeting 60% CPU. Pods scale from 3 to 30 during a flash sale, then back.
Elastic consumers: a Kafka consumer group whose instance count follows consumer lag (for example with KEDA). More instances join, partitions rebalance, lag drops. The partition count caps parallelism: a topic with 12 partitions cannot use more than 12 active consumers in one group.
Why Reactive Systems Are Easier to Make Elastic
Message-driven design means producers do not know how many consumers exist, so instances can be added without reconfiguring callers.
Location transparency lets work move to a new node.
Back-pressure and queue depth give a clear signal for when to scale.
Pitfalls
Slow startup (JVM warm-up, large container images, cache warming) makes elasticity lag behind spikes; keep a small buffer of spare capacity.
Flapping: scaling up and down too often. Use stabilization windows and cooldowns.
Stateful bottlenecks: scaling the API tier does nothing if every request still hits one database primary.
Common mistake: using the two words as synonyms. Interviewers expect you to say elasticity builds on scalability and adds automation in both directions.
4
How does a Reactive System stay responsive when a component fails?
KnownRevise
A Reactive System stays responsive during a component failure by containing the failure and degrading gracefully: it detects the problem fast with timeouts, stops calling the broken component with a circuit breaker, serves a fallback or cached result, and lets a supervisor or orchestrator restart or replace the failed part in the background.
Take a product page that calls a recommendations service:
Fail fast with timeouts: the call to recommendations has a 200 ms timeout. A hung dependency costs at most 200 ms, not 30 seconds.
Stop the bleeding with a circuit breaker: after, for example, 50% failures over the last 20 calls, the breaker opens and calls fail immediately for 30 seconds, giving the service time to recover.
Degrade gracefully: instead of an error page, show “popular products” from a cache, or hide the recommendations block. The core function (viewing and buying the product) still works.
Isolate resources with bulkheads: the recommendations client has its own small connection pool, so its slowness cannot use up threads needed for checkout.
Recover automatically: Kubernetes liveness probes restart the crashed pod; a supervisor actor restarts a failed child; replicas behind a load balancer take over.
Close the breaker carefully: in the half-open state a few trial calls go through, and the breaker closes only if they succeed.
Supporting Techniques
Technique
What it protects
Cost
Timeouts
Caller threads and latency
Must be tuned; too short gives false failures
Retries with backoff + jitter
Transient errors
Extra load; only for idempotent calls
Circuit breaker
Failing dependency, caller
Stale or partial results while open
Bulkhead
Shared thread and connection pools
More pools to size and monitor
Fallback / cache
User experience
Data may be stale
Replication
Availability of the component
More infrastructure, consistency work
Asynchronous queue
Writes during an outage
Eventual processing, not immediate
Message-Driven Buffering
For writes, a queue is often the best fallback. If the email service is down, order confirmations wait in the queue and are sent when it returns. The user still gets “order placed” immediately, so the system stays responsive even though one part is unavailable.
What Responsiveness Means Here
Responsive does not mean every feature works. It means the system answers in bounded time, with either a full result, a degraded result, or a clear error such as 503 Service Unavailable with Retry-After, never a hang.
Pitfalls
Retry storms: every layer retrying three times multiplies load on a struggling service; retry at one layer, with jitter and a budget.
Fallbacks that share the failure: a fallback that queries the same failing database does not help.
No observability: track breaker state, fallback rate and timeout counts, or degradation goes unnoticed.
Common mistake: naming only “add retries”. Interviewers look for detection (timeouts), isolation (bulkheads, breakers), degradation (fallbacks) and recovery (supervision, replication) as separate steps.
5
How does message-driven architecture make Reactive Systems resilient?
KnownRevise
Message-driven architecture makes a Reactive System resilient because components communicate through asynchronous messages instead of direct synchronous calls, so a failure in one component does not immediately block or crash the others. Messages are buffered, retried and redelivered, which turns failures into delays rather than outages.
In a chain like API → Orders → Payments → Notifications built on HTTP calls, if Notifications hangs, Payments waits, Orders waits, and the API’s threads fill up. One slow service brings the whole chain down. This is a cascading failure.
How Messaging Contains Failures
Temporal decoupling: the sender does not need the receiver to be up right now. The broker stores the message until the consumer is back.
Isolation: each component has its own queue and its own failure boundary. A crash in the email consumer affects only email.
Failures as messages: in actor systems, a failing child’s error is sent to its supervisor as a message, which decides to restart, resume or stop it.
Redelivery: if a consumer crashes before acknowledging a message, the broker redelivers it to another instance.
Load levelling: a burst of 10,000 orders queues up instead of overloading downstream services.
Location transparency: a message can be routed to any healthy replica, local or remote.
Request Flow Example
Client → Order API → (OrderPlaced event) → Broker → Payment / Inventory / Email consumers
If the inventory service is down for 5 minutes:
The Order API still accepts orders and publishes events.
Payment and Email keep working.
Inventory events build up as consumer lag.
When Inventory restarts, it processes the backlog from its last committed offset.
What You Must Add for It to Work
Concern
Technique
Duplicate delivery (at-least-once)
Idempotent consumers, deduplication by message ID
Poison messages
Limited retries, then a dead-letter queue
Ordering
Partition by key (for example order_id)
Lost messages
Durable, replicated topics; acknowledge after processing
Visibility
Correlation IDs, distributed tracing, lag alerts
Trade-offs
Eventual consistency: the order exists before inventory is reserved; the design must handle “reserved later” or compensate with a saga.
Operational cost: the broker is critical infrastructure and must itself be replicated (for example Kafka with replication factor 3 and min.insync.replicas=2).
Harder debugging: there is no single stack trace across services.
Not for everything: a user waiting for a search result needs a synchronous answer; messaging fits work that can happen in the background.
Interview Tip
A strong answer names the mechanism, not just “it is decoupled”: buffering, redelivery, isolation and supervision. The common mistake is forgetting that at-least-once delivery means consumers must be idempotent.
6
How does the bulkhead pattern improve resilience in Reactive Systems?
KnownRevise
The bulkhead pattern splits a system’s resources (threads, connection pools, instances, queues) into isolated compartments, so a failure or overload in one part uses up only its own compartment and cannot sink the rest. The name comes from ship bulkheads: a breach floods one section, not the whole hull.
A service with one shared pool of 200 threads calls three dependencies. If the reporting dependency becomes slow, requests to it hold threads for seconds each. Soon all 200 threads are waiting on reporting, and requests for checkout, which uses a perfectly healthy dependency, are rejected too. One slow dependency has taken down unrelated features.
How Bulkheads Fix It
Give each dependency or workload its own bounded resources:
Checkout client: 100 threads or connections
Search client: 60
Reporting client: 20
When reporting slows down, only its 20 slots fill up. Extra reporting calls are rejected immediately, while checkout and search keep their capacity.
Levels of Isolation
Level
Example
Isolates
Thread / semaphore
Separate pool or concurrent-call limit per client
Threads inside one process
Connection pool
Separate DB pools for OLTP and reports
Database connections
Process / pod
Separate deployments for public API and admin
CPU, memory, crashes
Queue / consumer
Separate topics for payments and analytics
Processing capacity
Cell / tenant
Large customers in their own cells
Noisy neighbours
Region / zone
Deploy across availability zones
Infrastructure failures
How It Minimizes Impact
Limits the blast radius: one feature degrades instead of the whole service.
Fails fast: when a compartment is full, callers get an immediate rejection instead of waiting, keeping latency bounded.
Works with other patterns: a circuit breaker stops calls to a failing dependency; the bulkhead caps how many calls can be in flight before the breaker reacts; timeouts free slots quickly.
Code Example
A semaphore bulkhead with Resilience4j, limiting concurrent calls to a reporting service:
import io.github.resilience4j.bulkhead.Bulkhead;
import io.github.resilience4j.bulkhead.BulkheadConfig;
import java.time.Duration;
import java.util.function.Supplier;
public class ReportingClient {
private final Bulkhead bulkhead = Bulkhead.of("reporting",
BulkheadConfig.custom()
.maxConcurrentCalls(20) // at most 20 calls in flight
.maxWaitDuration(Duration.ofMillis(10)) // then reject instead of queueing
.build());
public String fetchReport(String id) {
Supplier<String> guarded = Bulkhead.decorateSupplier(bulkhead, () -> callRemote(id));
return guarded.get(); // throws BulkheadFullException when the compartment is full
}
private String callRemote(String id) {
return "report " + id; // placeholder for the real HTTP call
}
}
Trade-offs and Pitfalls
Lower utilization: reserved capacity may sit idle while another compartment is full.
Sizing is hard: base pool sizes on measured throughput and latency (Little’s law: concurrency ≈ arrival rate × latency).
Too many compartments add tuning and monitoring work.
Common mistake: adding bulkheads without timeouts, so slots stay occupied by hung calls. Interviewers often ask how bulkheads differ from circuit breakers: bulkheads limit concurrency; breakers stop calls after failures.
7
Why does Reactive Programming need non-blocking I/O?
KnownRevise
Reactive Programming needs non-blocking I/O because its model relies on a small number of threads serving many concurrent operations; if any of those threads blocks while waiting for a network or disk response, it can serve nothing else, and throughput collapses. Non-blocking I/O lets a thread start an operation, move on, and get a callback or event when the data is ready.
In the classic thread-per-request model, each request holds a thread while it waits on the database or a remote API:
A request takes 5 ms of CPU but spends 200 ms waiting on I/O.
With 200 threads, the server handles about 1,000 requests per second, even though the CPU is almost idle.
Adding threads costs memory (each platform thread typically reserves around 1 MB of stack by default) and context-switching time.
Under a slow dependency, all threads end up waiting, and new requests queue or fail.
How Non-Blocking I/O Solves It
The application registers interest in a socket with the operating system (epoll on Linux, kqueue on BSD/macOS, IOCP on Windows).
An event loop thread waits for readiness events for thousands of sockets at once.
When data arrives, the loop runs the callback or emits the next item in the reactive stream.
No thread sits idle waiting for a single connection.
This is how Netty-based servers and Node.js handle tens of thousands of connections with a handful of threads (often one per CPU core).
What It Gives Reactive Systems
High concurrency with few resources: memory and thread count no longer grow with connections.
Back-pressure end to end: non-blocking reads let the consumer control when it reads more data.
Responsiveness under slow dependencies: a slow database delays its own requests but does not freeze the server.
Natural fit for streams: data arrives as events, which maps directly onto Flux, Observable or async iterators.
Comparison
Aspect
Blocking, thread per request
Non-blocking, event loop
Threads needed
One per concurrent request
About one per core
Memory per connection
High (thread stack)
Low
Code style
Simple, sequential
Callbacks, streams, async/await
Risk
Thread pool exhaustion
One blocking call stalls the loop
Debugging
Easy stack traces
Harder, fragmented traces
Pitfalls
Hidden blocking calls: a JDBC query, Thread.sleep or a synchronous file read on an event-loop thread stalls every connection on it. Move blocking work to a bounded pool (for example Schedulers.boundedElastic() in Reactor) or use non-blocking drivers such as R2DBC.
CPU-heavy work on the event loop has the same effect; offload it.
Complexity: reactive code is harder to read and debug.
What About Virtual Threads?
Java 21 virtual threads make blocking cheap again: a blocked virtual thread releases its carrier thread. They remove much of the throughput reason for reactive code in Java, but not stream composition or back-pressure. A strong interview answer mentions this trade-off: choose reactive libraries for streaming and back-pressure, virtual threads for simple request-response code.
8
How does Domain-Driven Design improve Reactive System design?
KnownRevise
Domain-Driven Design (DDD) improves a Reactive System by giving it the right boundaries and the right messages: bounded contexts become independent, failure-isolated services; aggregates define the unit of consistency that one actor or partition owns; and domain events become the asynchronous messages the system is built on.
Read full answerHide full answer
Applies toarchitecture concepts (DDD as described by Eric Evans; Reactive Manifesto 2.0)
Why the Two Fit Together
Reactive Systems need components that are isolated, own their state and communicate by messages. Choosing those components badly, for example splitting by technical layer, creates chatty services that must call each other synchronously, which destroys resilience. DDD answers “where should the boundaries be?” using the business domain.
DDD Building Blocks Mapped to Reactive Concepts
DDD concept
Reactive System role
Bounded context
A service with its own data and failure boundary
Aggregate
Unit of consistency; owned by one actor, entity or partition
Domain event (OrderPlaced)
Asynchronous message between contexts
Ubiquitous language
Clear, stable message names and schemas
Context map
Defines which events flow where (publisher, consumer, anti-corruption layer)
Saga / process manager
Coordinates multi-step workflows across contexts
How Each One Helps
Bounded contexts give isolation: Orders, Payments and Shipping each own their database. If Shipping fails, Orders keeps accepting orders, which is the resilience trait.
Aggregates give safe concurrency and elasticity: all commands for Order 42 go to the single owner of that aggregate (an actor in Akka Cluster Sharding, or a Kafka partition keyed by order_id). There is no shared lock, and aggregates can be spread across nodes as load grows.
Domain events make the system message-driven: instead of Orders calling Shipping, it publishes OrderPaid. New consumers (analytics, loyalty points) subscribe without changing Orders.
Event sourcing fits naturally: an aggregate’s state is the sum of its events, which gives an audit trail and lets other services build read models (CQRS).
Anti-corruption layers protect a context from a legacy system’s model, translating its calls into clean domain events.
Each arrow between contexts is an asynchronous message; each aggregate processes its own commands one at a time.
Trade-offs
Eventual consistency between contexts: a paid order may not show “shipped” for a few seconds; the UI and business rules must accept that.
Upfront modelling effort: finding good boundaries takes time with domain experts, and wrong boundaries are expensive to move.
Event schema evolution: published events are a contract; version them and keep changes backward compatible.
Overkill for simple CRUD: a small app with little business logic gains little from aggregates and events.
Interview Tip
The common mistake is mapping “one microservice per entity” (a Customer service, an Address service). Interviewers look for boundaries drawn around business capabilities and consistency rules, and for small aggregates, since large aggregates become contention hot spots.
9
Can a system be reactive without meeting every Reactive Manifesto trait?
KnownRevise
Yes, in practice a system is often called reactive when it is message-driven and responsive but only partly meets the other traits. A common example is a single-node event-driven server (for example a Node.js or Netty service consuming from a queue): it is non-blocking and message-driven, and responsive under normal load, but it is not resilient to the loss of its machine and not elastic, because it cannot add capacity by itself.
It consumes OrderPlaced events from RabbitMQ and sends emails asynchronously.
Its I/O is non-blocking, so one process handles thousands of in-flight emails.
When the email provider slows down, it uses bounded buffers and back-pressure (it stops fetching more messages until it catches up).
Which traits does it have?
Trait
Present?
Why
Message-driven
Yes
Asynchronous messages, non-blocking processing
Responsive
Mostly
Bounded latency under normal load
Resilient
Partly
Crashed messages are redelivered by the broker, but the service itself has no replica
Elastic
No
One fixed instance; capacity never changes
Why It Still Qualifies (Loosely)
It uses the core mechanism of reactive systems: asynchronous message passing with back-pressure.
The broker gives partial resilience: unacknowledged messages survive a crash and are processed after restart, so failures cause delays rather than data loss.
It follows reactive programming principles inside the component.
Why It Is Not a Full Reactive System
The manifesto treats the traits as a whole: message-driven design is the means, and elasticity and resilience are what keep the system responsive. Without replication there is a single point of failure, so during a machine outage the system is not responsive at all. Without elasticity, a load spike turns into a growing backlog.
A stricter view is that this is reactive programming inside a non-reactive system, a distinction interviewers like to hear.
Other Common Partial Examples
A reactive UI (React, RxJS) is responsive and event-driven but has no notion of elasticity.
An auto-scaled synchronous REST API is elastic and replicated, but not message-driven; a slow downstream service can still cause cascading failures.
A batch pipeline on Kafka is message-driven and elastic, but not responsive in the user-facing sense, since results arrive minutes later.
How to Close the Gaps
Run at least two replicas across availability zones (resilience).
Scale consumers on queue depth or lag, for example with KEDA (elasticity).
Add health checks, timeouts and a dead-letter queue (resilience).
Keep it stateless or partition its state so instances are interchangeable (elasticity).
Interview Tip
Do not claim that any asynchronous code is a reactive system. Say which traits are present, which are missing, and what it would cost to add them. That shows you understand the traits as connected, not as a checklist.
10
How do Reactive Systems handle transient failures versus network partitions?
KnownRevise
A Reactive System handles a transient failure (a short glitch such as a dropped packet, a timeout or a brief overload) by retrying with backoff, because the same request will probably succeed moments later. A network partition (nodes are up but cannot reach each other for an extended time) cannot be retried away: the system must detect it, decide which side keeps serving, and choose between consistency and availability until the network heals.
Read full answerHide full answer
Applies todistributed-systems concepts (examples: Resilience4j 2.x, Akka/Pekko Cluster, Raft-based stores such as etcd)
Transient Failures
Typical causes: a TCP reset, a GC pause, a 503 during a deployment, a lost message.
Duration: milliseconds to a few seconds.
Strategy:
Timeouts so the caller does not wait forever.
Retries with exponential backoff and jitter (for example 100 ms, 200 ms, 400 ms, with random spread) to avoid synchronized retry storms.
Idempotency keys so a retried payment or order is not applied twice.
Redelivery in message-driven systems: an unacknowledged message is delivered again.
A circuit breaker if transient errors pile up, so retries do not overload a struggling service.
Network Partitions
Typical causes: a failed switch, a misconfigured firewall, a cross-region link outage.
Duration: seconds to hours. Both sides may still be running and accepting traffic.
The core danger: each side may think the other is dead. If both keep accepting writes, you get split brain and conflicting data.
Strategy:
Failure detection with heartbeats (for example a phi-accrual detector) that marks unreachable nodes.
Quorums and leader election: in Raft-based systems, only the side with a majority can elect a leader and commit writes; the minority side rejects writes (choosing consistency).
Split-brain resolvers: in Akka/Pekko Cluster, a strategy such as keep majority downs the minority side so only one side owns the sharded entities.
Availability-first designs: Dynamo-style stores (Cassandra, Riak) accept writes on both sides and reconcile later with timestamps, vector clocks or CRDTs.
Graceful degradation: serve reads from local replicas, queue writes, or show “temporarily read-only”.
Comparison
Aspect
Transient failure
Network partition
Duration
Very short
Long, unpredictable
Nodes alive?
Yes
Yes, but isolated
Main tool
Retry with backoff
Quorum, leader election, split-brain resolution
Risk if mishandled
Retry storm, duplicates
Split brain, data conflicts
CAP relevance
None
Must choose consistency or availability
The CAP Connection
During a partition, CAP says you must choose: reject some requests to stay consistent (CP), or accept them and reconcile later (AP). Without a partition, PACELC adds that you trade latency against consistency.
Telling Them Apart
The hard part is that both look like timeouts at first. Reactive systems use escalation: retry a few times; if failures persist, the breaker opens and the failure detector marks the node unreachable; after a configured window (often 10–20 seconds or more), the cluster treats it as a partition and runs the resolution strategy.
Interview Tip
The common mistake is “just retry” for every failure. Retrying during a partition only adds load and delays the real decision. Strong answers mention idempotency for retries, and quorum or split-brain handling for partitions.
11
Which messaging technology suits asynchronous communication in Reactive Systems?
KnownRevise
For most Reactive Systems, Apache Kafka is a strong default for asynchronous communication between services: it is a durable, partitioned, replicated log that consumers pull from at their own pace, which gives natural back-pressure, replay and horizontal scaling. For streaming request-response between services, RSocket or gRPC streaming are better choices, because they carry flow control directly over the connection.
Message-driven: producers and consumers are fully decoupled in time; neither needs the other to be up.
Back-pressure by design: consumers pull batches of records, so a slow consumer only builds lag. It never overloads.
Resilient: topics are replicated (typically replication factor 3 with min.insync.replicas=2), and consumers resume from committed offsets after a crash.
Elastic: partitions are spread across a consumer group; adding consumers (up to the partition count) increases throughput.
Replay: retained events can be reprocessed to rebuild a read model or fix a bug, which suits event sourcing and CQRS.
Ordering per key: records with the same key (for example order_id) go to one partition and keep their order.
When to Choose Something Else
Technology
Best for
Limitation
Kafka
Event streams, high throughput, replay
Operational weight; per-message routing is basic
RabbitMQ
Task queues, flexible routing, per-message acks
Classic queues are not a replayable log (streams add this)
RSocket
Reactive request-stream and channel between services
Smaller ecosystem
gRPC streaming
Typed, low-latency service-to-service streams
Both sides must be online; no durable buffering
NATS / JetStream
Lightweight, low-latency messaging
Fewer stream-processing tools than Kafka
Cloud queues (SQS, Pub/Sub)
Managed, low operations
Vendor lock-in, provider limits
How I Would Justify the Choice in an Interview
Clarify the need: fire-and-forget events, durable work queues, or live streams between two services?
For domain events between many services (orders, payments, shipping), choose Kafka: durability, replay and fan-out to many consumer groups.
For per-task work with retries and priorities (sending emails, image resizing), RabbitMQ is often simpler.
For streaming RPC (live price updates to a gateway), use RSocket or gRPC streaming, which propagate demand over the network.
Things to Get Right With Kafka
Partition count caps consumer parallelism; plan it for peak load.
Delivery semantics: the default is at-least-once, so make consumers idempotent. Kafka’s idempotent producer and transactions give exactly-once within Kafka (read-process-write), not for external side effects.
Dead-letter topics for messages that keep failing.
Schemas: use Avro or Protobuf with a schema registry, and evolve schemas compatibly.
Monitoring: consumer lag is the key back-pressure signal.
Trade-offs
Kafka adds infrastructure that must be run, monitored and upgraded, or paid for as a managed service. For a small system with a few services, a managed queue may be the better trade-off. A common mistake is choosing Kafka for synchronous lookups, which it is not designed for.
12
How do Reactive Systems process continuous data streams?
KnownRevise
Reactive Systems process continuous data streams by treating data as an unbounded flow of events that moves through asynchronous, non-blocking stages, each with back-pressure so slow stages are not overwhelmed. Results are computed incrementally, often within milliseconds of the event, instead of waiting for a batch job.
Ingestion into a durable log (for example Kafka) buffers bursts and decouples producers from processors.
Stream processors filter, enrich, join and aggregate events, often over windows (for example “orders per minute”).
Sinks write results to a database, cache, dashboard or another topic, or trigger an alert.
Reactive Traits in Stream Processing
Responsive: incremental processing gives low-latency results (sub-second for alerting).
Resilient: processors checkpoint their state and offsets; after a crash they resume from the last checkpoint.
Elastic: the stream is partitioned by key, so more processor instances can share the load.
Message-driven with back-pressure: each stage pulls at its own speed; a slow sink causes lag rather than lost data.
Key Concepts
Event time vs processing time: aggregate by when the event happened, not when it arrived, so late data is counted correctly.
Windows: tumbling (fixed, non-overlapping), sliding (overlapping) and session (gap-based).
Watermarks: an estimate of how far event time has progressed, used to decide when a window can close.
Stateful operators: counts and joins keep state, stored locally and backed by a changelog or checkpoint.
Delivery guarantees: at-least-once is common; Flink and Kafka Streams can give exactly-once state updates within their pipeline.
Industry Use Cases
Industry
Use case
Why streaming
Payments / banking
Fraud scoring on each card transaction
Decide before the transaction is approved
E-commerce
Live inventory, real-time recommendations
Avoid overselling; react to the current session
Telecom / IoT
Sensor and network telemetry monitoring
Detect faults within seconds
Logistics
Vehicle tracking and ETA updates
Location changes continuously
Ad tech
Budget pacing and click counting
Stop spending when a budget runs out
Operations
Log and metric alerting
Page on-call engineers quickly
Trade-offs
Complexity: windowing, late data, state management and reprocessing are harder than a nightly batch job.
Cost: always-on processors and replicated logs cost more than a scheduled batch.
Correctness: exactly-once end-to-end requires idempotent or transactional sinks.
When not to stream: monthly reports and data that can be minutes or hours old are often simpler and cheaper as batch jobs.
Interview Tip
Interviewers often ask how you handle late or out-of-order events, and how you recover state after a crash. The common mistake is aggregating by processing time, which gives wrong results when events arrive late.
13
What is Event Sourcing and how does it help Reactive Systems?
KnownRevise
Event Sourcing stores an entity’s state as an append-only sequence of events (OrderPlaced, ItemAdded, OrderPaid) instead of overwriting a current-state row. The current state is rebuilt by replaying those events. It suits Reactive Systems because the events are the messages: they drive other components asynchronously, give a complete audit trail and let failed components recover by replay.
Read full answerHide full answer
Applies toarchitecture pattern (examples: Akka/Pekko Persistence, EventStoreDB, Axon, Kafka as a transport)
How It Works
A command arrives: AddItem(order 42, sku 7).
The aggregate loads its state by replaying its past events (or from a snapshot plus newer events).
It validates the command against business rules.
If it is valid, it appends a new event ItemAdded to the event store; optimistic concurrency (an expected version number) stops two writers from conflicting.
The event is published to subscribers, which update read models, send emails or start other workflows.
Benefits for Reactive Systems
Message-driven by nature: every state change is already an event other services can react to, with no separate “publish” step that can drift from the database.
Resilience and recovery: a crashed actor or service rebuilds its state by replaying events; a buggy read model can be dropped and rebuilt from the log.
Elasticity: aggregates are independent, so they can be sharded across nodes (for example Akka Cluster Sharding keyed by entity ID).
Fast writes: appending to a log is cheaper and conflicts less than updating rows in place.
Audit and time travel: you can answer “what did this order look like at 10:05?”, useful in finance and compliance.
Pairs with CQRS: writes go to the event log; reads come from projections optimized for each query.
Comparison With CRUD
Aspect
CRUD (current state)
Event Sourcing
Stored data
Latest values
Every change as an event
History
Lost unless separately logged
Built in
Integration
Polling or change data capture
Subscribe to events
Reads
Simple queries
Projections / read models
Complexity
Low
High
Costs and Pitfalls
Eventual consistency of reads: projections lag behind writes by milliseconds to seconds; the UI must handle that.
Schema evolution: events are stored forever. Version them, use upcasters, and never change the meaning of an old event.
Replay time: long histories need snapshots (for example every 100 events).
Deleting personal data: an immutable log makes data-protection erasure harder; common fixes are crypto-shredding (encrypt per user and delete the key) or keeping personal data outside the events.
Not for every service: simple CRUD data with no history needs (a user’s profile picture) gains little.
Example
A bank account aggregate stores AccountOpened, MoneyDeposited(100), MoneyWithdrawn(30). The balance of 70 is computed, not stored. A fraud service subscribes to MoneyWithdrawn, and a statement service builds monthly statements from the same events.
Interview Tip
Distinguish Event Sourcing (how state is stored) from event-driven architecture (how services communicate). You can have either without the other. A common mistake is using Kafka with short retention as the only event store; a dedicated store or long-retention, compacted design is needed when events are the source of truth.
14
What is the difference between hot and cold reactive streams?
KnownRevise
A cold stream starts producing data only when someone subscribes, and each subscriber gets its own independent sequence from the beginning, like playing a recorded video on demand. A hot stream produces data whether or not anyone is listening, and subscribers share it, seeing only what is emitted after they join, like a live broadcast.
Read full answerHide full answer
Applies toProject Reactor 3.x (the same concepts apply to RxJava 3 and RxJS 7)
Cold Streams
Lazy: nothing happens until subscribe().
Per-subscriber execution: two subscribers to a cold Flux that reads a database run the query twice.
Replayable: every subscriber sees the full sequence.
Eager or shared: the source runs independently of subscribers.
Shared execution: all subscribers see the same events; late subscribers miss earlier ones unless the stream replays them.
Typical sources: mouse clicks, stock price ticks, sensor readings, a WebSocket feed, messages pushed into a Sinks.Many.
Comparison
Aspect
Cold
Hot
Starts when
A subscriber subscribes
Independently, or on first connect
Data per subscriber
Full, independent copy
Shared; from the moment of joining
Side effects
Repeated for each subscriber
Happen once
Back-pressure
Easy: the source can slow down
Hard: source cannot be paused; buffer or drop
Examples
DB query, HTTP request, file read
UI events, market data, live telemetry
Converting Between Them
Cold to hot: share() or publish().autoConnect(n) multicasts one execution to many subscribers; replay(n) / cache() also keeps the last n items for late subscribers.
Hot with a starting value: replay(1) gives new subscribers the latest value, useful for “current price” or “current user”.
Code Example
import java.time.Duration;
import reactor.core.publisher.Flux;
public class HotColdDemo {
public static void main(String[] args) throws InterruptedException {
// Cold: each subscriber triggers its own sequence 1, 2, 3
Flux<Integer> cold = Flux.range(1, 3)
.doOnSubscribe(s -> System.out.println("cold source started"));
cold.subscribe(v -> System.out.println("A got " + v));
cold.subscribe(v -> System.out.println("B got " + v)); // runs again from 1
// Hot: one shared ticking source; late subscribers miss earlier ticks
Flux<Long> hot = Flux.interval(Duration.ofMillis(100)).share();
hot.subscribe(v -> System.out.println("C got " + v));
Thread.sleep(350);
hot.subscribe(v -> System.out.println("D got " + v)); // starts around tick 3
Thread.sleep(300);
}
}
Use Cases
Cold: fetching a user’s orders, paginated API reads, replaying a file, anything where each consumer needs the complete result.
Hot: dashboards showing live metrics, chat rooms, price feeds, broadcasting domain events to several in-process listeners.
Pitfalls
Accidental re-execution: subscribing twice to a cold WebClient call sends two HTTP requests. Use cache() or share() when you want one call.
Lost early events: subscribing to a hot stream too late misses data; use replay if new subscribers need recent history.
Overflow on hot sources: since you cannot slow the source, choose onBackpressureBuffer, onBackpressureDrop or onBackpressureLatest.
15
How does message-driven communication scale compared to synchronous request-response?
KnownRevise
Message-driven communication usually scales better than synchronous request-response because callers do not hold threads or connections while waiting, load spikes are absorbed by queues instead of failing requests, and producers and consumers scale independently. Synchronous calls are simpler and give an immediate answer, but every service in the chain must handle peak load at the same moment.
Read full answerHide full answer
Applies toarchitecture concepts (examples: HTTP/REST or gRPC vs Kafka or RabbitMQ)
Why Synchronous Calls Limit Scale
Coupled capacity: if the API receives 5,000 requests per second, every downstream service in the call chain must also handle 5,000 per second, right now.
Latency adds up: a chain of four calls at 50 ms each gives at least 200 ms, and tail latencies combine (the slowest service sets the pace).
Resource holding: each in-flight request holds a thread or connection while it waits. By Little’s law, concurrency = throughput × latency, so slow dependencies multiply the threads needed.
Cascading failure: when one service slows down, callers’ pools fill up and the slowdown spreads upstream.
Why Message-Driven Scales Better
Load levelling: a burst of 50,000 orders goes into a queue; consumers process at a steady 5,000 per second and catch up later.
Independent scaling: add consumer instances (up to the partition count in Kafka) without touching producers.
Fan-out: one event reaches many consumers (billing, analytics, email) without the producer calling each one.
No waiting: producers publish and move on, so they need fewer resources.
Natural back-pressure: consumers pull work at the rate they can handle.
Comparison
Aspect
Synchronous request-response
Message-driven
Coupling
Temporal: both must be up
Decoupled in time
Peak handling
Every service must handle the peak
Queue absorbs bursts
Scaling
Whole chain scales together
Each consumer scales on its own
Latency for the caller
Full chain latency
Fast acknowledgement; result later
Consistency
Easier, immediate
Eventual
Debugging
One trace, simple
Needs tracing and correlation IDs
Best for
Queries needing an answer now
Commands, events, background work
Example: Checkout
Synchronous: Client → Order API → Payment → Inventory → Email. A slow email provider makes checkout slow.
Message-driven: Order API saves the order, publishes OrderPlaced, returns 202 Accepted in about 20 ms. Payment, Inventory and Email consume independently. During a sale, only the Payment consumers need to scale up.
When Synchronous Is Still Right
The user needs the result immediately (search results, login, price lookup).
The operation is a simple read with no side effects.
Strong consistency is required at that moment.
Most real systems mix both: synchronous for queries, messages for commands and events.
Costs of Messaging
Eventual consistency and more complex UX (“your order is being processed”).
Duplicates from at-least-once delivery, so consumers must be idempotent.
Operational load: the broker must be replicated, monitored and capacity-planned.
Harder to trace a request end to end.
Interview Tip
The common mistake is saying messaging is “always faster”. It is often slower for a single request, but it gives higher throughput and better stability under load. Mention Little’s law and load levelling to show you understand why.
16
Why is the actor model well suited to Reactive Systems?
KnownRevise
The actor model is a design pattern well suited to Reactive Systems: the system is built from actors, small isolated units that own private state, process one message at a time from a mailbox and communicate only by sending asynchronous messages. This gives message-driven communication, concurrency without locks, supervision-based resilience and location transparency in a single model.
Read full answerHide full answer
Applies tothe actor model as implemented in Akka 2.x / Apache Pekko 1.x (JVM), Erlang/OTP and Microsoft Orleans
How an Actor Works
Each actor has an address and a mailbox.
Other actors send it messages asynchronously; senders never wait or share memory with it.
The actor processes one message at a time, so its internal state never needs locks.
In response it can update its state, send messages, create child actors or change its behaviour for the next message.
Why It Is Effective for Reactive Systems
Message-driven: asynchronous messaging is the only way actors interact, which is the base trait of the Reactive Manifesto.
Safe concurrency: millions of lightweight actors (each uses a few hundred bytes, not a thread) run on a small thread pool, with no shared mutable state and no deadlocks from locks.
Resilience through supervision: actors form a hierarchy; when a child fails, its parent decides to restart, resume or stop it. Failures stay inside one branch (“let it crash”).
Location transparency: sending to an actor looks the same whether it is local or on another node, so the system can spread actors across a cluster.
Elasticity: with cluster sharding, entities such as Order-42 live on whichever node owns their shard, and shards rebalance when nodes join or leave.
Example
A ride-sharing service models each driver as an actor:
Location updates arrive as messages to Driver-123.
The actor keeps the driver’s current position and status in memory.
A matching request is a message; only Driver-123 changes its own state, so there are no race conditions.
If a bug crashes the actor, its supervisor restarts it and the state is recovered from persisted events.
Comparison With Threads and Locks
Aspect
Threads + shared state
Actors
Concurrency control
Locks, synchronized blocks
One message at a time per actor
Failure handling
try/catch at each call
Supervisor hierarchy
Distribution
Separate RPC layer
Same messaging, local or remote
Main risk
Deadlocks, races
Mailbox overflow, message-ordering assumptions
Trade-offs and Pitfalls
Message delivery is at-most-once by default in Akka/Pekko: if guarantees matter, add acknowledgements or persistence.
Blocking inside an actor stalls its dispatcher thread; run blocking I/O on a dedicated dispatcher.
Unbounded mailboxes can run out of memory under load; use bounded mailboxes or reactive streams for back-pressure.
Debugging and testing asynchronous message flows is harder than call stacks.
Licensing: Akka moved to the Business Source License in 2022; Apache Pekko is the open-source fork of Akka 2.6.
Interview Tip
Other patterns suited to Reactive Systems include event sourcing, CQRS and circuit breakers. If you choose actors, explain the supervision tree and how sharding gives elasticity; a common mistake is presenting actors as “just lightweight threads”.
17
Which framework is good for building Reactive Systems, and why?
KnownRevise
For a distributed Reactive System with stateful services, Apache Pekko (the open-source fork of Akka 2.6) is a strong recommendation: it provides actors, clustering, sharding, persistence and reactive streams in one toolkit, covering all four Reactive Manifesto traits. For a stateless HTTP microservice on the JVM, Spring WebFlux with Project Reactor is often the more practical choice.
Read full answerHide full answer
Applies toApache Pekko 1.x, Spring Boot 3.x with Spring WebFlux and Project Reactor 3.x
Core Features of Apache Pekko
Typed actors: isolated units with private state that process one message at a time, giving concurrency without locks.
Supervision: parent actors decide how to handle a child’s failure (restart, resume, stop), so failures stay contained.
Cluster: nodes form a membership group with failure detection and split-brain resolution for network partitions.
Cluster Sharding: entities such as Order-42 are distributed across nodes by ID and rebalanced when nodes join or leave, giving elasticity for stateful workloads.
Persistence: event-sourced actors store events and recover state by replay, with snapshots for long histories.
Streams: a Reactive Streams implementation with built-in back-pressure for pipelines.
Connectors: Pekko HTTP, gRPC and Connectors (Kafka, AMQP, S3) for integration.
How It Maps to the Reactive Traits
Trait
Pekko feature
Message-driven
Asynchronous actor messaging, location transparency
Your team already uses Spring, and services are mostly stateless request handlers.
You need reactive HTTP (WebClient), R2DBC database access and Spring Security.
State lives in a database or cache, and messaging goes through Kafka or RabbitMQ.
Other Options
Framework
Strength
Consider when
Apache Pekko / Akka
Stateful, distributed, event sourcing
Complex domains, high concurrency
Spring WebFlux + Reactor
Ecosystem, familiarity
Stateless JVM microservices
Eclipse Vert.x
Lightweight event loop, polyglot
Low-latency services, small footprint
Quarkus (Mutiny, SmallRye Reactive Messaging)
Fast startup, Kubernetes-native
Containers and serverless
Erlang/OTP, Elixir
Supervision trees, soft real-time
Telecom-style high-availability systems
Microsoft Orleans
Virtual actors on .NET
.NET teams with stateful services
Trade-offs
Learning curve: actors, supervision and eventual consistency need a different way of thinking than request-response code.
Operational complexity: clustering needs careful configuration (seed nodes or discovery, split-brain resolver, rolling updates).
Licensing: Akka has used the Business Source License since 2022 (commercial use above a revenue threshold needs a licence); Pekko is Apache 2.0.
Overkill for simple CRUD: a few stateless services with a database and a queue do not need an actor cluster.
Interview Tip
There is no single right framework; justify the choice from requirements. Mention whether the service is stateful, the team’s skills and the operational cost. A common mistake is saying “use a reactive framework” as if the library alone made the system reactive; elasticity and resilience come from the architecture too.
18
How do reactive microservices manage state while keeping it consistent?
KnownRevise
Reactive microservices manage state by giving each piece of state a single owner (one service, and inside it one entity, actor or partition), changing it only through messages processed one at a time, and sharing it with other services through events rather than a shared database. Consistency is strong inside an entity and eventual between services, with sagas coordinating multi-service workflows.
Read full answerHide full answer
Applies toarchitecture concepts (examples: Akka/Pekko Cluster Sharding and Persistence, Kafka, the outbox pattern)
Principle 1: Single Writer per Entity
All commands for Account-42 are routed to the one actor or partition that owns it (cluster sharding or a Kafka partition keyed by account ID).
That owner processes commands sequentially, so there are no lost updates or lock contention.
This gives strong consistency for the entity without distributed locks.
Principle 2: Durable State Through Events or Snapshots
Event sourcing: the entity persists events (MoneyDeposited) and rebuilds state by replay after a crash or move to another node.
Durable state: alternatively, store the latest state in a database with optimistic concurrency (a version column).
In-memory state is a cache of the durable state, which makes it fast and recoverable.
Principle 3: Database per Service
Each service owns its data. Other services never query its tables directly; they consume its events and keep local read models of what they need. This avoids coupling and lets each service scale and fail independently.
Principle 4: Reliable Event Publishing
A service must not update its database and fail to publish the event (or the reverse). Solutions:
Transactional outbox: write the state change and an outbox row in one local transaction; a relay publishes outbox rows to the broker.
Change data capture (for example Debezium) reading the database log.
Event sourcing, where the stored event is the published message.
Principle 5: Sagas for Cross-Service Consistency
Distributed transactions (two-phase commit) block and hurt availability, so reactive systems use sagas: a sequence of local transactions with compensating actions.
Example checkout saga:
Orders: create order (pending).
Payments: charge card, then PaymentCaptured.
Inventory: reserve stock. If this fails, emit ReservationFailed.
Compensation: Payments refunds, Orders marks the order cancelled.
Consistency Levels
Scope
Consistency
Technique
Inside one entity
Strong
Single writer, sequential processing
Inside one service’s DB
Strong (ACID)
Local transactions
Across services
Eventual
Events, sagas, idempotent consumers
Read models
Eventual, with lag
Projections from events
Pitfalls
Duplicate events: at-least-once delivery means consumers must be idempotent (track processed event IDs).
Out-of-order events: partition by entity key and include version numbers.
Sticky in-memory state without persistence: lost on restart or rebalance.
Shared database between services: hidden coupling that defeats isolation.
Interview Tip
Interviewers want to hear where strong consistency is needed (a bank balance) and where eventual is acceptable (an order history page). The common mistake is reaching for distributed transactions or a shared database instead of sagas and events.
19
How do functional programming principles make Reactive Systems more resilient?
KnownRevise
Functional programming (FP) principles, mainly immutability, pure functions, explicit error values and composition, make Reactive Systems more resilient because they remove shared mutable state (the source of most concurrency bugs), make failures visible and recoverable as values, and make operations safe to retry or replay.
Messages and events are immutable, so a message can be sent to many consumers, buffered or retried without anyone changing it underneath.
No shared mutable state means no race conditions or lock-ordering deadlocks across threads.
State changes become new versions (state = apply(state, event)), which is exactly how event sourcing rebuilds state after a crash.
Pure Functions
A pure function’s output depends only on its input and has no side effects.
Safe retries: retrying a pure computation after a timeout cannot double-charge a customer.
Deterministic replay: reprocessing events through pure handlers gives the same state, which makes recovery reliable.
Easy testing: business rules can be tested without mocks, which reduces bugs that cause failures in production.
Side Effects at the Edges
FP pushes I/O (database writes, HTTP calls, sending emails) to the boundaries. The core decides what should happen; a thin outer layer performs it. Side effects become fewer, explicit and easier to make idempotent.
Errors as Values
Instead of exceptions that escape and crash a thread, errors travel as values: Either, Result, Try, or an error signal in a stream.
In reactive libraries, errors are part of the stream protocol (onError), and operators handle them declaratively:
retryWhen(Retry.backoff(3, Duration.ofMillis(100))) for transient failures
onErrorResume(e -> cachedFallback()) for graceful degradation
timeout(Duration.ofSeconds(2)) for fail-fast behaviour
This makes resilience policies visible in the code instead of scattered in try/catch blocks.
Composition
Small, reusable stream operators (map, filter, flatMap, retryWhen, timeout) are combined into pipelines. Resilience behaviour can be added as a composable step, for example wrapping any call with the same timeout-retry-fallback chain.
Principles and Their Resilience Benefit
FP principle
Resilience benefit
Immutability
No races; messages safe to share, buffer and replay
Pure functions
Safe retries, deterministic recovery
Effects at the edges
Fewer places that can fail; easier idempotency
Errors as values
Failures handled explicitly, never silently lost
Composition
Uniform timeout/retry/fallback policies
Higher-order functions
Resilience decorators (circuit breakers) wrap any call
Example in Reactor
Mono<Price> price = priceClient.fetch(productId) // side effect at the edge
.timeout(Duration.ofMillis(300)) // fail fast
.retryWhen(Retry.backoff(2, Duration.ofMillis(50))) // transient errors
.map(raw -> PriceRules.applyDiscount(raw, customer)) // pure business rule
.onErrorResume(e -> priceCache.lastKnown(productId)); // degrade gracefully
Limits
Pure functions do not remove the need for idempotency at the edges: the I/O layer must still deduplicate.
Heavy immutability can add allocation and GC pressure in hot paths.
Deeply nested functional pipelines can be hard to debug; keep them readable.
Interview Tip
Tie each principle to a concrete failure it prevents. The common mistake is listing FP terms without explaining how they help with retries, replay or concurrency.
20
What is the difference between the Observer and Publish-Subscribe patterns?
KnownRevise
In the Observer pattern, observers register directly with a subject, and the subject calls them when its state changes, so both sides know each other and usually live in the same process. In Publish-Subscribe, publishers and subscribers never know each other: publishers send messages to a topic on an intermediary (a broker or event bus), which delivers them to all subscribers, often asynchronously and across processes.
Structure: Subject keeps a list of Observer references and calls notify on each.
Coupling: the subject holds direct references to observers (through an interface).
Delivery: usually synchronous, in the same thread and process.
Reactive programming is built on it: an Observable or Publisher notifies its Subscriber through onNext, onError and onComplete, with back-pressure added in Reactive Streams.
Coupling: none between the parties; they share only the topic name and message format.
Delivery: asynchronous, often over the network, possibly durable.
Filtering: by topic or content; subscribers choose what to receive.
Comparison
Aspect
Observer
Publish-Subscribe
Knowledge of each other
Subject knows its observers
Neither knows the other
Intermediary
None
Broker, event bus or topic
Typical scope
In-process
Across services and machines
Timing
Usually synchronous
Usually asynchronous
Durability
None: missed if not registered
Can persist and replay (Kafka, JetStream)
Failure impact
Slow observer can block the subject
Broker buffers; slow subscribers lag
Example
UI component reacting to a model change
Order service publishing OrderPlaced to many services
Use Cases in Reactive Programming
Observer
A UI form field emitting value changes to validators, via an RxJS Observable.
A Reactor Flux pipeline inside one service, where each operator subscribes to the previous one.
A BehaviorSubject holding the current user, with components subscribing to updates.
Publish-Subscribe
Microservices reacting to domain events: billing, email and analytics all subscribe to OrderPlaced.
Live notifications fanned out to many WebSocket servers via Redis Pub/Sub.
IoT telemetry published to MQTT topics such as factory/line1/temperature.
How They Combine
Many reactive systems use both: Kafka (pub-sub) carries events between services, and inside each service a Reactor Flux (observer-based) processes the stream with back-pressure.
Trade-offs
Observer: simple and fast, but tight coupling, and a slow or throwing observer can affect the subject. Forgetting to unsubscribe causes memory leaks.
Pub-Sub: scalable and decoupled, but adds a broker to operate, eventual delivery, possible duplicates and harder end-to-end debugging.
Interview Tip
The key difference interviewers look for is the intermediary and the decoupling it provides. A common mistake is saying pub-sub is “just observer over a network”; mention durability, topic-based routing and independent scaling as the real differences.
21
When does Reactive Programming beat an imperative approach?
KnownRevise
Reactive Programming clearly beats an imperative approach when an application must combine many concurrent, slow or continuous asynchronous sources. A good example is a live dashboard or API gateway that aggregates several remote services and streaming updates for thousands of users at once. A reactive pipeline expresses that composition declaratively, handles timeouts and back-pressure, and serves high concurrency with few threads.
Read full answerHide full answer
Applies toProject Reactor 3.x / Spring WebFlux (Spring Boot 3), concepts also apply to RxJS 7
The Use Case: A Product Page Aggregator
A gateway builds a product page from four services: product details, price, stock and reviews. Each call takes 50–300 ms. Traffic peaks at 10,000 concurrent requests.
Imperative, blocking version
Calls run one after another (sum of latencies, about 600 ms) or need manual thread pools and futures to run in parallel.
Each request holds a thread while waiting, so 10,000 concurrent requests need thousands of threads.
Timeouts, fallbacks and cancellation are scattered through try/catch blocks.
Reactive version
The four calls run concurrently on a few event-loop threads; total latency is roughly the slowest call (about 300 ms).
Per-call timeouts and fallbacks are declared inline: if reviews are slow, show the page without them.
Cancellation propagates: if the user closes the page, in-flight calls are cancelled.
Back-pressure protects the gateway when a downstream service slows down.
Code Example
import java.time.Duration;
import reactor.core.publisher.Mono;
public Mono<ProductPage> productPage(String id) {
Mono<Product> product = productClient.get(id); // required
Mono<Price> price = priceClient.get(id).timeout(Duration.ofMillis(200));
Mono<Stock> stock = stockClient.get(id)
.timeout(Duration.ofMillis(200))
.onErrorReturn(Stock.unknown()); // degrade gracefully
Mono<Reviews> reviews = reviewClient.get(id)
.timeout(Duration.ofMillis(300))
.onErrorReturn(Reviews.empty());
// All four calls run concurrently; the page is built when all complete
return Mono.zip(product, price, stock, reviews)
.map(t -> new ProductPage(t.getT1(), t.getT2(), t.getT3(), t.getT4()));
}
Other Strong Use Cases
Live data feeds: stock tickers, sports scores, chat, where data is a continuous stream pushed to many clients over WebSockets or server-sent events.
Event-heavy UIs: type-ahead search with debounce, cancelling stale requests and merging results (RxJS debounceTime, switchMap).
Streaming ETL: processing a large file or Kafka topic with bounded memory and back-pressure.
IoT ingestion: thousands of devices sending readings concurrently.
Comparison
Aspect
Imperative
Reactive
Concurrency
Threads, futures, locks
Declarative operators
Threads under load
Grows with requests
About one per core
Timeouts and fallbacks
Manual
Built-in operators
Streaming data
Awkward
Natural
Readability for simple logic
Better
Worse
When Imperative Is Better
Simple CRUD with one database call per request and modest traffic.
CPU-bound work, where reactive gives no benefit.
Teams unfamiliar with reactive debugging.
In Java 21+, virtual threads give much of the scalability of non-blocking code with plain imperative style for request-response work.
Interview Tip
Choose a use case with real concurrency or streaming, and name the cost: harder debugging and a steeper learning curve. A common mistake is claiming reactive makes every app faster; it improves throughput and resource use under concurrency, not single-request speed.
22
How does a reactive stream differ from a list or array?
KnownRevise
In Reactive Programming, a stream is a sequence of values delivered over time, pushed asynchronously to subscribers along with completion and error signals. A list or array holds all of its values in memory at once and is read synchronously. A stream can be infinite, can arrive gradually from the network, and can be transformed before its data even exists.
onError(error): a failure, after which the stream ends
onComplete(): normal end (an infinite stream never completes)
Subscribers react to these signals instead of pulling values by index.
Stream vs Collection
Aspect
List / array
Reactive stream
When data exists
All at once, already in memory
Arrives over time
Size
Finite
Finite or infinite
Access
Pull, synchronous (list.get(i))
Push, asynchronous (onNext)
Memory
Whole collection held
One item or a small buffer at a time
Errors
Exceptions when reading
Error signal in the stream
Flow control
Not needed
Back-pressure (request(n))
Time operators
None
debounce, window, timeout, interval
Cancellation
Not applicable
Subscriber can cancel at any time
Advantages Over Collections
Bounded memory: processing a 10 GB log file as a stream keeps only a few lines in memory; loading it into a list may not fit at all.
Infinite and live data: mouse clicks, sensor readings and Kafka topics never “end”, so they cannot be a list.
Lower latency: the first result is processed as soon as it arrives, instead of after the whole collection is ready.
Asynchronous composition: combine data from several sources (merge, zip, combineLatest) without blocking threads.
Time-aware logic: debounce user input, batch events every second, or time out slow sources.
Back-pressure: a slow consumer controls how fast data is produced.
Cancellation: stop the upstream work (for example close a database cursor) when the consumer no longer needs data.
Code Example
A Reactor pipeline that processes an infinite stream of sensor readings:
import java.time.Duration;
import reactor.core.publisher.Flux;
public class SensorStream {
public static void main(String[] args) throws InterruptedException {
Flux.interval(Duration.ofMillis(100)) // infinite stream: 0, 1, 2, ...
.map(tick -> 20.0 + (tick % 10)) // pretend temperature reading
.filter(temp -> temp > 25.0) // only warm readings
.buffer(Duration.ofSeconds(1)) // batch per second
.map(batch -> batch.stream().mapToDouble(Double::doubleValue).average().orElse(0))
.take(3) // stop after 3 batches (cancels upstream)
.subscribe(avg -> System.out.println("avg warm temp: " + avg));
Thread.sleep(3500); // keep the demo alive while the stream runs
}
}
When a Collection Is Still Better
The data is small, already in memory and needed all at once (sorting, random access).
Code is simple and synchronous; a stream adds overhead and complexity.
You need to iterate several times; a cold stream would re-run its source each time.
Interview Tip
Mention that streams are lazy (nothing runs until subscription) and push-based, and that Java’s java.util.stream.Stream is a different thing: it is pull-based, synchronous and single-use, without time or back-pressure. Confusing the two is a common mistake.
23
How does a circuit breaker prevent cascading failures?
KnownRevise
A circuit breaker prevents cascading failures by watching calls to a dependency and, once failures or slow calls pass a threshold, opening so further calls fail immediately instead of waiting on the struggling service. Callers keep their threads and stay responsive, the failing service gets time to recover, and after a wait the breaker lets a few trial calls through to check whether it is healthy again.
The payment service becomes slow (database overloaded).
The order service’s calls to it wait for long timeouts, holding threads.
The order service’s thread pool fills; it can no longer serve any requests.
The API gateway waiting on orders fills up too. One slow service has taken down the whole path.
Retries make it worse by sending even more traffic to the struggling service.
The Three States
State
Behaviour
Moves to
Closed
Calls pass through; failures and slow calls are counted over a sliding window
Open when the failure rate exceeds the threshold (for example 50% of the last 20 calls)
Open
Calls fail immediately (or use a fallback) without touching the dependency
Half-open after a wait (for example 30 s)
Half-open
A few trial calls are allowed
Closed if they succeed; Open again if they fail
Why It Stops the Cascade
Fails fast: an open breaker returns an error in microseconds, so the caller’s threads and connections are freed instead of waiting.
Sheds load from the sick service: it receives almost no traffic while open, giving it room to recover.
Enables graceful degradation: the caller serves a fallback (cached price, “recommendations unavailable”, queue the request for later).
Limits retry storms: retries stop while the breaker is open.
Code Example
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
import java.time.Duration;
import java.util.function.Supplier;
public class PaymentClient {
private final CircuitBreaker breaker = CircuitBreaker.of("payments",
CircuitBreakerConfig.custom()
.slidingWindowSize(20) // last 20 calls
.failureRateThreshold(50) // open at 50% failures
.slowCallDurationThreshold(Duration.ofSeconds(1))
.slowCallRateThreshold(50) // slow calls count too
.waitDurationInOpenState(Duration.ofSeconds(30))
.permittedNumberOfCallsInHalfOpenState(3)
.build());
public String charge(String orderId) {
Supplier<String> call = CircuitBreaker.decorateSupplier(breaker, () -> callPaymentService(orderId));
try {
return call.get();
} catch (Exception e) { // includes CallNotPermittedException when open
return "PAYMENT_PENDING"; // fallback: retry asynchronously later
}
}
private String callPaymentService(String orderId) {
return "PAID"; // placeholder for the real HTTP call (with its own timeout)
}
}
Best Practices
Combine with timeouts: without a timeout, a hanging call never counts as a failure.
Count slow calls, not just errors; slowness causes most cascades.
One breaker per dependency (and sometimes per endpoint), so one bad endpoint does not block healthy ones.
Pair with bulkheads to cap concurrent calls before the breaker trips.
Meaningful fallbacks: never a fallback that calls the same failing dependency.
Monitor state changes and alert when a breaker stays open.
Pitfalls
Thresholds that are too sensitive cause flapping; too lax ones react too late.
Counting client errors (400 Bad Request) as failures opens the breaker for the wrong reason.
A common interview follow-up: “Where does the breaker live?” It can live in client code (Resilience4j) or in the service mesh (Envoy outlier detection), and each placement has trade-offs.
24
What is a good back-pressure strategy for a Reactive System under high load?
KnownRevise
An effective back-pressure strategy propagates “slow down” signals end to end, from the slowest component back to the edge. Inside services that means bounded buffers and demand-based streams; between services, pull-based messaging; and at the edge, admission control (rate limiting and load shedding). Work beyond capacity is then delayed, degraded or rejected early instead of exhausting memory deep inside the system.
Measure throughput and latency of each stage. Often it is a database, an external API with a quota, or a CPU-heavy step. Back-pressure should be designed around that stage’s capacity, for example “the payment provider handles 500 requests per second”.
Step 2: Bound Every Buffer
Every queue, mailbox and in-memory buffer has a maximum size.
Unbounded buffers hide overload until the process runs out of memory.
Size buffers for short bursts (seconds), not sustained overload.
Step 3: Use Demand-Based Flow Inside Services
Reactive Streams request(n) lets consumers pull only what they can handle.
Limit concurrency explicitly, for example flatMap(this::callDb, 32) to cap in-flight database calls at 32.
Move blocking work to a bounded thread pool so it cannot stall event loops.
Step 4: Use Pull-Based Messaging Between Services
Kafka consumers fetch at their own pace; overload shows up as consumer lag, not crashes.
With RabbitMQ, set a prefetch count (for example 50) so a consumer never holds more unacknowledged messages than it can process.
Use RSocket or gRPC streaming flow control when services stream directly.
Step 5: Control Admission at the Edge
When the system as a whole is over capacity, back-pressure must reach clients:
Rate limiting per user or API key (token bucket), returning 429 Too Many Requests with Retry-After.
Load shedding: reject or queue low-priority traffic first (analytics, bulk exports) to protect checkout and login.
Concurrency limits (adaptive limiters) that reduce accepted requests when latency rises.
Step 6: Choose an Overflow Policy per Data Type
Data
Policy
Reason
Payments, orders
Buffer durably, never drop; slow the producer
Loss is unacceptable
Price ticks, positions
Keep latest
Only the current value matters
Metrics, telemetry
Sample or drop
Approximate data is fine
User-triggered work
Reject early with 429 / 503
Client can retry later
Step 7: Scale and Degrade
Autoscale consumers on lag or queue depth (for example with KEDA), within partition limits.
Degrade: turn off expensive features (personalized recommendations) under pressure.
Circuit breakers stop calls to dependencies that are already failing.
Step 8: Monitor the Signals
Track queue depth, consumer lag, buffer fill levels, dropped or rejected counts, and p99 latency per stage. Alert when lag keeps growing, because that means sustained overload, not a burst.
Pitfalls
Back-pressure that stops at a boundary: a reactive service that accepts unlimited HTTP requests still collapses.
Retries without backoff turn back-pressure into a retry storm.
Timeouts longer than buffers can absorb, so work piles up while waiting.
Interview Tip
Say clearly that back-pressure only moves the overload to the edge; at some point you must scale, degrade or reject. A common mistake is “just add a bigger queue”, which delays failure instead of handling it.
25
What is a supervision strategy in Reactive Systems?
KnownRevise
A supervision strategy is the rule a parent component (a supervisor) applies when one of its children fails: resume it, restart it with fresh state, stop it, or escalate the failure to its own parent. It moves failure handling out of business code into a dedicated hierarchy, so failures stay contained and are recovered automatically instead of crashing the whole system.
Read full answerHide full answer
Applies tothe actor model as implemented in Erlang/OTP, Akka 2.x and Apache Pekko 1.x (Kubernetes restart policies apply the same idea at process level)
How It Works
Actors (or processes) are arranged in a tree: each child has exactly one supervisor.
When a child throws an exception, it does not try to recover itself; the failure is sent to its supervisor as a signal.
The supervisor applies its strategy based on the type of failure.
Children that keep failing can be restarted with backoff, and after too many restarts in a time window the supervisor gives up and escalates.
The Options
Directive
What happens
Use when
Resume
Keep the actor and its state, skip the failed message
A bad input message; state is still valid
Restart
Replace the actor with a fresh instance; state is reset (or recovered from persistence)
State may be corrupted, e.g. a broken connection
Stop
Terminate the actor permanently
The task is no longer needed or cannot succeed
Escalate
Pass the failure up to the parent’s supervisor
The supervisor cannot decide; a wider restart is needed
Erlang/OTP adds strategies for siblings: one_for_one (restart only the failed child), one_for_all (restart all children when one fails) and rest_for_one (restart the failed child and those started after it).
Its Role in Managing Failures
Isolation: a failure stays inside one branch of the tree; other actors keep working.
Let it crash: business code stays simple, with no defensive try/catch everywhere, because a clean restart is often the most reliable recovery.
Self-healing: transient problems (a dropped database connection) are fixed by restarting the component that owns the connection.
Controlled escalation: repeated failures move up the tree to a level that can make a bigger decision, such as restarting a whole subsystem.
Example
A payment gateway actor supervises one child actor per external provider. If the StripeClient child fails with a connection error, the supervisor restarts it with backoff (1 s, 2 s, 4 s, capped at 30 s). Other provider actors are not affected. If it fails more than 10 times in a minute, the supervisor escalates, and the parent routes payments to a backup provider.
Best Practices
Use backoff for restarts so a failing dependency is not hammered.
Persist important state (event sourcing) so a restart does not lose it.
Keep actors that hold critical state low in the tree, with risky work (I/O) delegated to child actors.
Limit restarts per time window to avoid endless restart loops.
Pitfalls
Restarting hides bugs if you never look at the logs; alert on restart rates.
A restart does not fix a permanent error (a wrong configuration); escalate or stop instead.
Common interview follow-up: compare with Kubernetes, where a Deployment controller restarts failed pods. That is the same idea at the process level, so mention both.
26
How do Reactive Systems use multicore and distributed resources?
KnownRevise
Reactive Systems use multicore and distributed resources by breaking work into many small, independent, message-driven units that share no mutable state. A scheduler can then spread them across every CPU core of one machine, and location transparency lets the same units spread across many machines. Throughput grows with the hardware instead of being limited by locks or a single thread.
Event loops per core: non-blocking servers such as Netty run about one event-loop thread per core, each handling thousands of connections without blocking.
Lightweight tasks: actors or reactive pipeline stages are scheduled on a small thread pool, so millions of units share a few threads with little context switching.
No shared mutable state: because units communicate by immutable messages, cores do not fight over locks. Lock contention is what stops multithreaded code from scaling (Amdahl’s law: the serial part limits the speed-up).
Explicit parallelism: operators such as parallel() / runOn(Schedulers.parallel()) in Reactor, or flatMap with a concurrency limit, run independent items on different cores.
Isolated pools for blocking work keep event-loop cores free.
Across Machines: Distribution
Partitioning by key: data and work are split by key (order ID, user ID). Kafka partitions or actor shards are assigned to different nodes, and each node owns its part.
Location transparency: a message to Order-42 is sent the same way whether the entity is local or remote, so entities can move between nodes.
Rebalancing: when a node joins, shards or partitions are reassigned to it automatically (elasticity); when it leaves, its share moves to the survivors (resilience).
Replication: read-heavy data is replicated so many nodes can serve it.
Why It Improves Performance
Technique
Benefit
Non-blocking I/O
Cores do useful work instead of waiting
Message passing, no locks
Near-linear scaling with cores
Partitioning
Each node handles a fraction of the load
Data locality
Process state where it lives; fewer network hops
Asynchronous pipelines
Stages overlap: one item computes while another waits on I/O
Example
A fraud-scoring service consumes card transactions from a Kafka topic with 48 partitions. Six nodes each run 8 consumer threads, one per core, covering all 48 partitions. Each partition’s events are processed in order by one thread, with state kept locally. Adding six more nodes lets the group rebalance to about 4 partitions per node, roughly doubling capacity until the partition count becomes the limit.
Limits and Trade-offs
Coordination costs: anything needing global agreement (a global counter, a distributed lock) does not scale; avoid it or make it rare.
Hot keys: one very busy key (a celebrity account) overloads its single owner; split hot keys or cache reads.
Network cost: a cross-machine message costs about 0.5 ms in one datacentre versus nanoseconds in memory, so keep chatty interactions local.
Ordering: parallelism breaks global ordering; you keep ordering only per key.
Interview Tip
Mention Amdahl’s law and why shared mutable state is the enemy of scaling. A common mistake is saying “just add threads”; without removing contention and blocking, more threads add overhead, not throughput.
27
What is location transparency in Reactive Systems?
KnownRevise
Location transparency means a component sends a message to another component using a logical address, without knowing or caring whether the receiver is in the same process, on another machine or has just moved to a new node. The runtime routes the message. In a distributed data store, clients address data by key, and the system decides which node holds that key, so data can be moved, replicated or rebalanced without clients changing anything.
Read full answerHide full answer
Applies todistributed-systems concepts (examples: Akka/Pekko actor references, Cassandra and DynamoDB-style partitioning, Kafka partitions)
How It Works in Reactive Systems
Components hold a reference or address (an actor reference, a topic name, an entity ID), never a host and port.
Communication is asynchronous message passing in all cases, so local and remote calls have the same semantics. Messages can be lost or delayed either way, so code is written for the network case from the start.
The runtime resolves the address to a physical location and forwards the message, and can change that location at runtime.
This is different from transparent remoting (making a remote call look like a local method call), which hides latency and failure. Location transparency does the opposite: it treats everything as potentially remote.
Why It Matters
Elasticity: new nodes can take over part of the work, and components move to them without callers being reconfigured.
Resilience: if a node dies, its components are restarted elsewhere and messages are routed to the new location.
Simpler code: the same component works in a single-process test and in a 50-node cluster.
Applying It to a Distributed Data Store
Clients use keys, not servers: get("user:42") without knowing which node stores it.
Partitioning: the store maps each key to a partition, typically with consistent hashing (Cassandra token ring, DynamoDB partitions).
Routing: either the client library knows the partition map (token-aware drivers), or any node acts as a coordinator and forwards the request.
Replication: each partition lives on several nodes (for example 3 replicas); reads and writes go to whichever replicas are healthy.
Rebalancing: when a node is added, some partitions move to it. Clients keep using the same keys; only the internal map changes.
Failover: if a replica’s node fails, requests go to the other replicas, and a new replica is built in the background.
Benefits and Costs
Benefit
Cost
Scale out by adding nodes
Every request may involve a network hop
Transparent failover
Routing metadata must be kept consistent
Data can move for balance
Rebalancing uses bandwidth and can affect latency
Clients stay simple
Hidden latency differences (local vs cross-zone)
Pitfalls
Ignoring latency: “transparent” does not mean free. A design that sends many tiny messages to remote entities is slow; batch them or co-locate related data.
Hot partitions: a popular key still lives on one partition; transparency does not spread its load.
Assuming exactly-once delivery because a message “looks local”.
Interview Tip
Interviewers like the contrast with transparent remoting (CORBA- or RMI-style calls). Explain that reactive location transparency embraces the network’s failure modes rather than hiding them, and tie it to consistent hashing for data stores.
28
What are common bottlenecks in streaming Reactive Systems and how do you monitor them?
KnownRevise
Common bottlenecks in a streaming Reactive System are a slow stage that causes back-pressure, blocking calls on event-loop threads, hot partitions, slow sinks (databases or external APIs), serialization and GC overhead, and state or checkpoint costs in stateful operators. You find them by monitoring lag, throughput and latency per stage, buffer fill levels, thread and GC metrics, and distributed traces.
Metrics: Prometheus and Grafana, Micrometer, Kafka exporter or Burrow for lag.
Tracing: OpenTelemetry with context propagated in message headers, to see time spent per hop.
Profiling: async-profiler or Java Flight Recorder to find hot code and blocking calls; Reactor’s BlockHound detects blocking calls on non-blocking threads during tests.
Logs with correlation IDs for individual problem events.
How to Diagnose
Start at the end: is the sink slow? Check its latency and error rate.
Walk upstream, comparing throughput per stage to find where input exceeds output.
Check partition-level lag for skew.
Check CPU versus waiting: high CPU points to compute or serialization; low CPU with high latency points to blocking I/O or slow dependencies.
Fix by scaling the slow stage, adding partitions, batching sink writes, moving blocking calls to bounded pools, or splitting hot keys.
Interview Tip
Name consumer lag first and explain the difference between a burst (lag that recovers) and sustained overload (lag that keeps growing). A common mistake is monitoring only averages; tail latency (p99) is where streaming problems show first.
29
How do you load test a Reactive System's scalability?
KnownRevise
To test a Reactive System’s scalability, run realistic, gradually increasing load against a production-like environment with a load generator such as Gatling, k6 or Locust. Measure throughput, latency percentiles and resource use at each step, then check that capacity grows roughly in proportion as you add instances, and that the system degrades gracefully (back-pressure, 429s, lag) rather than collapsing.
Read full answerHide full answer
Applies totesting practice (examples: Gatling 3.x, k6, Locust, Kafka performance tools, Prometheus and Grafana)
Step 1: Define Goals and Workload
Targets: for example 5,000 requests per second with p99 under 300 ms, or 50,000 events per second with consumer lag under 10 seconds.
Workload model: realistic mix of operations (80% reads, 20% writes), realistic payload sizes and key distribution (including hot keys).
Open vs closed model: use an open model (fixed arrival rate) for internet traffic. A closed model (fixed number of users waiting for responses) slows down with the system and hides overload.
Step 2: Prepare the Environment
Production-like sizing, configuration and data volume (caches and indexes behave differently with small data).
Mock or sandbox external dependencies that cannot take load, with realistic latency injected.
Full observability: metrics, traces and logs for every component.
Step 3: Run the Test Types
Test
Purpose
Baseline
Normal load, to get reference numbers
Ramp / stress
Increase load step by step to find the breaking point
Spike
Sudden 5–10x jump, to test elasticity and buffering
Soak
Hours at steady load, to find memory leaks and slow degradation
Scale-out
Repeat at 1, 2 and 4 instances to measure scaling efficiency
Failure under load
Kill a node or add network latency during load (chaos testing)
Step 4: Measure
Throughput and latency percentiles (p50, p95, p99), not averages.
Autoscaling behaviour: how fast new instances start and take traffic.
Step 5: Analyse Scalability
Scaling efficiency = (throughput at N instances) ÷ (N × throughput at one instance). Near 1.0 is good; a sharp drop points to a shared bottleneck (database, lock, partition count).
Find the knee of the latency curve, where latency rises sharply; operate well below it.
Check that overload produces controlled degradation, not timeouts everywhere or out-of-memory crashes.
Testing Streaming Parts
Use kafka-producer-perf-test and kafka-consumer-perf-test, or a custom producer, to push events at fixed rates.
Measure end-to-end latency by putting a timestamp in each event.
Confirm lag recovers after a spike, and that adding consumers reduces lag until the partition count is reached.
Pitfalls
The load generator becomes the bottleneck: monitor its CPU too, and distribute it if needed.
Coordinated omission: tools that wait for slow responses before sending the next request under-report latency; use arrival-rate-based tools.
Testing once: run load tests regularly (for example in CI on a schedule) to catch regressions.
Interview Tip
Interviewers look for percentiles, an open workload model, scale-out tests and failure injection. A common mistake is reporting only “max requests per second” without latency or error rates.
30
What are the main Reactive programming libraries, and what does Project Reactor offer?
KnownRevise
The main Reactive programming libraries are Project Reactor and RxJava on the JVM, Akka/Pekko Streams for actor-based streaming, Mutiny in Quarkus, RxJS in JavaScript, and Kotlin Flow for coroutines. Project Reactor, the foundation of Spring WebFlux, offers two core types, Mono (0–1 item) and Flux (0–N items), a large set of composable operators, schedulers for threading, and full Reactive Streams back-pressure.
Read full answerHide full answer
Applies toProject Reactor 3.x (used by Spring Boot 3 / Spring WebFlux)
Key Libraries
Library
Platform
Notes
Project Reactor
JVM
Spring WebFlux, R2DBC, Spring Cloud Gateway
RxJava 3
JVM, Android
Long-established; Observable, Flowable, Single
Akka / Pekko Streams
JVM (Scala, Java)
Graph-based streams on actors
SmallRye Mutiny
JVM (Quarkus)
Uni and Multi with an event-driven API
RxJS 7
JavaScript, TypeScript
Used heavily in Angular
Kotlin Flow
Kotlin coroutines
Cold flows; StateFlow and SharedFlow for hot streams
Reactor-style in .NET
.NET
Rx.NET (System.Reactive)
All JVM libraries interoperate through the Reactive Streams interfaces (Publisher, Subscriber, Subscription, Processor), also in the JDK as java.util.concurrent.Flow.
Project Reactor Core Features
Mono<T> and Flux<T>: Mono for a single async result (like an HTTP response), Flux for streams.
Lazy, cold by default: nothing runs until subscribe(); each subscription re-executes the source.
Steep learning curve and harder debugging than imperative code.
Blocking calls inside a chain break its benefits; use non-blocking drivers or boundedElastic.
With Java 21 virtual threads, simple request-response code may not need Reactor; it remains valuable for streaming, back-pressure and complex async composition.
Interview Tip
A good answer names the Reactive Streams standard as the common foundation, then explains Mono vs Flux, flatMap vs concatMap (concurrent vs ordered) and publishOn vs subscribeOn. Confusing the last two is a frequent mistake.
31
What role do message queues play in Reactive Systems?
KnownRevise
Message queues (and message brokers) are the asynchronous backbone of a Reactive System: they decouple producers from consumers in time and location, buffer bursts, deliver messages reliably to healthy instances and distribute work across consumers. The most important characteristics are durability, delivery guarantees, ordering, scalability and back-pressure support.
Message-driven foundation: services communicate by sending messages rather than calling each other directly.
Resilience: if a consumer crashes, messages wait in the queue and are redelivered when it returns or to another instance.
Elasticity: adding consumers spreads the work (competing consumers); queue depth is a natural autoscaling signal.
Load levelling: a spike of 100,000 events is absorbed and processed at a steady rate.
Back-pressure: consumers pull at their own pace, so overload turns into backlog rather than failure.
Fan-out: one event reaches many independent subscribers (publish-subscribe).
Important Characteristics
Characteristic
Why it matters
Example setting
Durability
Messages survive broker restarts
Persistent messages, disk-backed logs
Replication
No data loss when a broker node dies
Kafka replication factor 3, min.insync.replicas=2; RabbitMQ quorum queues
Delivery guarantee
Defines duplicates or losses
At-least-once with acks after processing
Ordering
Some events must be applied in order
Per-partition ordering by key in Kafka
Scalability
Throughput grows with nodes
Partitions, sharded queues
Consumer flow control
Prevents overwhelming consumers
Kafka pull, RabbitMQ prefetch
Retention / replay
Rebuild state, reprocess after bugs
Kafka retention, RabbitMQ streams
Dead-letter handling
Isolate poison messages
Dead-letter queue after N retries
Latency
Responsiveness
Low milliseconds for most brokers
Observability
Detect overload early
Queue depth, consumer lag metrics
Delivery Semantics
At-most-once: may lose messages, never duplicates. Fine for metrics.
At-least-once: no loss, possible duplicates. The usual default, so consumers must be idempotent.
Exactly-once: offered within Kafka (idempotent producers plus transactions for read-process-write); end to end with external systems, you still need idempotent writes.
Queue vs Log
Queue (RabbitMQ classic, SQS): a message is removed once acknowledged. Good for task distribution, routing and per-message retries.
Log (Kafka, Pulsar): messages are retained, and each consumer group tracks its own offset. Good for event streams, multiple consumers and replay.
Pitfalls
Unbounded queues hide overload until disks fill; set limits and alert on growth.
Treating the broker as infinitely reliable: it is critical infrastructure and needs replication and monitoring.
Large messages: put big payloads in object storage and send a reference.
Ignoring duplicates and reordering in consumer logic.
Interview Tip
The common mistake is saying a queue “guarantees delivery” without stating the semantics. Say at-least-once plus idempotent consumers, and name lag or queue depth as the signal you would monitor.
32
How do you integrate Reactive Systems with non-reactive legacy systems?
KnownRevise
Integrating a Reactive System with non-reactive legacy systems is hard because legacy systems are usually synchronous, blocking, limited in capacity and not built for failure isolation, so they can block threads, ignore back-pressure and become a bottleneck or single point of failure. You mitigate this by isolating the legacy system behind an adapter: run blocking calls on bounded pools, limit and buffer traffic to it, translate its model and protect callers with timeouts and circuit breakers.
Run them on a bounded pool (Schedulers.boundedElastic()), or use non-blocking drivers such as R2DBC
No back-pressure
Reactive callers can overwhelm it
Concurrency limits (bulkheads), rate limiting, queues in front
Limited capacity
Legacy mainframe or database handles a fixed rate
Queue requests and process at its pace; cache reads
Slow or unreliable
Timeouts and errors spread upstream
Timeouts, retries with backoff for idempotent calls, circuit breakers
Different data model
Legacy concepts leak into new services
Anti-corruption layer that translates models
Synchronous expectations
Legacy callers want an immediate answer
Request-reply over messaging with correlation IDs, or a synchronous facade
No events
Reactive services need change notifications
Change data capture (Debezium) or polling turned into events
Transactions
Legacy relies on ACID across tables
Keep transactions inside the legacy system; use sagas between new and old
Operations and visibility
Hard to trace across the boundary
Correlation IDs logged on both sides, metrics at the adapter
Pattern: The Isolating Adapter
Reactive services → Adapter service → Legacy system
The adapter:
Exposes a clean, asynchronous interface (events or a reactive API) to the new system.
Uses an anti-corruption layer to translate legacy formats and codes into domain terms.
Calls the legacy system on a dedicated, bounded thread pool, with a concurrency limit equal to what the legacy system can safely handle.
Applies timeouts and a circuit breaker, returning fallbacks or queuing work when the legacy system is down.
Publishes events for changes, captured via CDC or polling.
Code Example
Wrapping a blocking legacy call so it does not block the event loop:
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.reactor.circuitbreaker.operator.CircuitBreakerOperator;
import java.time.Duration;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
public Mono<Customer> findCustomer(String id) {
return Mono.fromCallable(() -> legacyCrm.lookup(id)) // blocking JDBC/SOAP call
.subscribeOn(Schedulers.boundedElastic()) // never on the event loop
.timeout(Duration.ofSeconds(2)) // fail fast
.transformDeferred(CircuitBreakerOperator.of(crmBreaker)) // stop calling when it is down
.onErrorResume(e -> customerCache.get(id)); // degrade to cached data
}
Migration Strategy
Strangler fig: route features one by one from the legacy system to new reactive services, keeping the adapter as the boundary.
Event-first integration: start by publishing legacy changes as events, so new services can build their own read models without calling the legacy system on every request.
Interview Tip
The key point is that one blocking dependency can undo the benefits of a reactive design. Interviewers look for isolation (bounded pools, bulkheads), protection (timeouts, breakers), translation (anti-corruption layer) and a migration path. A common mistake is calling legacy code directly from a reactive pipeline.