[EN]How to choose right strategy for our reactive Java Microservices?
Hi, in this article I want to provide information on choosing the right preference for reactive Microservices(built with Java and Spring).
First of all what's reactive and non-reactive. Let's start this point.
Reactive microservices: We can call them microservices created with asynchronous or non-blocking i/o components.
Non-reactive microservices: Microservices created with synchronous and blocking i/o components.
At this point I want to explain I/O and Non-blocking I/O (NIO) terms.
IO: We can explain it simply like a thread responsible about a task. From start to end.
NIO: There is some difference about thread responsibilities. A thread responsible just read and write methods invoke. What's it mean? An operation start with thread and thread invoke read() methods and released, after complation task thread invoke write() methods and release. Therefore threads are not blocking.
I'll try to write an article about IO and NIO deeply later.
Let's return to reactive services. With Java and Spring framework there is 2 option for build reactive microservices;
Non-blocking Synchronous structure: High-performance synchronous APIs using NIO features.
Event-driven Asynchronous structure: Asynchronous structures that work with the processing of event messages through systems such as Kafka and Rabbit MQ etc.
So how we decide right architecture for developing reactive microservice?
Normally, asynchronous structure may be preferred as there are more scalable and powerful applications. But in some cases Non-blocking synchronous structures will be more efficient for us. For example;
- In general, the client expects a response in read operations. In such cases, Non-blocking synchronous system may be preferred.
- In structures suitable for synchronous operation, for example; Non-blocking synchronous system can be preferred in SPA (Single Page Web App) web and mobile applications.
- Using message driven in communications with different organizations can make the application complicated and difficult to develop.
Asynchronous structures can be used in the above-mentioned cases, but non-blocking synchronous structures can be preferred when user experience or development difficulties are considered.
Thanks for reading my first blog post, feel free to contact us to comment or criticize.