Reactive Systems are an architectural style for building applications that can remain responsive under high load and failures, enhancing overall system resilience. The system components interact with each other using asynchronous message-passing, enabling loose coupling, flexibility, and scalability. In tech interviews, questions on reactive systems assess a candidate’s understanding of system design principles, asynchronous programming, as well as their ability to design highly responsive, resilient, and scalable systems. The topic also delves into the Reactive Manifesto, an essential guideline for building reactive systems.
Reactive Systems Fundamentals
- 1.
What are the defining characteristics of a Reactive System according to the Reactive Manifesto?
Answer:The Reactive Manifesto lays out key characteristics that define reactive systems.
Core Characteristics
-
Responsiveness: React to events and failures in a timely manner. Ensure application and network latency is minimal.
-
Resilience: Due to potential failures in distributed operations, reactive systems should remain responsive and consistent. They should recover and maintain operations in less than optimal times.
-
Elasticity: Able to manage varying volumes of traffic by scaling resources accordingly.
-
Message-Driven: Communication among system components is achieved through asynchronous message passing rather than more resource-intensive and less flexible mechanisms such as shared memory or method calls.
Additional Characteristics
-
Back-Pressure: Systems should apply back-pressure to prevent resource exhaustion by striving to keep the speed of message production and message processing in balance.
-
Resource Efficiency: They should use resources in a way that ensures the most efficient possible outcome. This means recognizing that resources are limiting and shared and managing them accordingly.
Code Example: Back-Pressure in Akka Streams
Here is the Java code:
final Source<Integer, NotUsed> source = Source.range(1, 100); final Flow<Integer, Integer, NotUsed> flow = Flow.of(Integer.class).map(i -> i * 2); final Sink<Integer, CompletionStage<Done>> sink = Sink.foreach(System.out::println); source.via(flow).to(sink).withAttributes(Attributes.createLogLevels(Logging.DebugLevel(), Logging.InfoLevel())) .run(materializer);Here is the Scala code:
val source = Source(1 to 100) val flow = Flow[Int].map(_ * 2) val sink = Sink.foreach[Int](println) source.via(flow).to(sink).withAttributes(ActorAttributes.dispatcher("my-dispatcher")).run() -
- 2.
How is back-pressure implemented in Reactive Systems to manage data flow?
Answer: - 3.
Contrast Elasticity with Scalability with specific examples as they pertain to Reactive Systems.
Answer: - 4.
Describe a strategy a Reactive System might use to maintain responsiveness during a component failure.
Answer: - 5.
How does message-driven architecture contribute to the resilience of Reactive Systems?
Answer: - 6.
Identify a resiliency strategy in Reactive Systems and explain how it minimizes the impact of failures.
Answer:
Design Principles of Reactive Systems
- 7.
Why are non-blocking I/O operations a necessity in Reactive Programming, and what problems do they solve?
Answer: - 8.
In what ways can Domain-Driven Design (DDD) principles enhance the design of a Reactive System?
Answer: - 9.
Provide an example of a system that is reactive without fulfilling all the Reactive Manifesto traits. Why does it qualify?
Answer: - 10.
Describe how a Reactive System would differently address a transient failure versus a network partition.
Answer: - 11.
Discuss a particular transport layer technology you would recommend for Reactive Systems’ asynchronous communication and why.
Answer: - 12.
Explain the role of Reactive Systems in processing continuous data streams, providing industry use cases.
Answer:
Implementing Reactive Systems
- 13.
What is Event Sourcing, and how does it benefit Reactive Systems?
Answer: - 14.
Differentiate between hot and cold reactive streams with examples of use cases.
Answer: - 15.
Compare synchronous request-response communication with reactive message-driven communication in terms of scalability.
Answer: