Open nehanims opened 2 months ago
Non-blocking reactive endpoints offer several advantages, especially in scenarios where handling a large number of concurrent requests efficiently is crucial. Here’s a breakdown of the benefits and some examples of popular libraries and frameworks:
High Concurrency Handling:
Better Resource Utilization:
Scalability:
Improved Responsiveness:
Fault Tolerance and Resilience:
Java/Spring Ecosystem:
JavaScript/Node.js:
Python:
async
and await
syntax for non-blocking code..NET:
async
and await
, ASP.NET Core can be used to create non-blocking APIs.High-Throughput APIs: Services like social media platforms, real-time analytics dashboards, or any service expected to handle a large number of concurrent API requests.
Streaming Data Applications: Applications processing streams of data, such as video streaming services, live sports updates, or stock market tickers.
Microservices Architectures: Systems composed of multiple microservices, where inter-service communication needs to be efficient and resilient.
IoT Applications: Applications that need to handle data from numerous devices in real-time, such as smart home systems or industrial IoT solutions.
Event-Driven Systems: Systems that react to a series of events, such as user actions in a web application, or events from a messaging system like Kafka.
Cloud-Native Applications: Applications designed to scale elastically in cloud environments, where efficient resource utilization is crucial.
Official Spring reference for Kafka: https://docs.spring.io/spring-kafka/reference/kafka.html
Kafka Listener is Async compatible now
But, if looking for an alternative, use Kafka-reactor instead of spring Kafka (spring Kafka reactive support with completarle future came much after project reactor's reactive Kafka API with flux and mono so maybe it's more mature?) so be careful about which one you're using and stick with it even though I think there's some sort of mono in spring Kafka e.g. the Kafka listener can support returning a mono but it's not clear if the support is very well defined.
Here's the reference for Kafka reactor
https://www.baeldung.com/kotlin/apache-kafka https://kotlinlang.org/docs/async-programming.html https://www.baeldung.com/kotlin/coroutines-vs-rxkotlin
Difference between future and reactor flux/mono: Future is actually synchronous only(Future block waits on a thread to receive the result) whereas, Mono/Flux can be both asynchronous and synchronous. CompletableFuture is the equialent async version of Future.
So here's a problem to consider when dealing with handling asynchronous events in the front end. You don't want the event to disrupt the users workflow or confuse the user. So, be very careful about using reactive updates in the front end. The user should be aware that a change has happened and not just suddenly see a different UI than a second ago because of UI refresh from a non user initiated event:
Excellent talk by Netflix engineer Ray Phelps about how to to use rxjs+redux with react to handle reactive UI and the problem rxjs solves. Worth watching again and taking notes.
Read the reactive manifesto Look into reactive I/O for different programming languages