Skip to content
Advertisement

Calling blocking endpoint on non-blocking asynchronous service

If my reactive endpoint needs to call an external, non-reactive endpoint which does blocking stuff, is my reactive endpoint still reactive?

I have 2 services running that levergaes Spring Boot MVC and Spring Webflux.

Service A Spring Webflux

Service B Spring MVC

Now my Service A which is reactive calling the Service B endpoint which is blocking. Will my service A be affected and be non-reactive?

If yes? How to tackle such scenario such that my reactive endpoint stays reactive?

Advertisement

Answer

If Service A is written as a reactive services using webflux it will always stay reactive, no matter who else it is calling.

Im going to assume we are talking http/https now using for instance webclient.

The thing about reactive is if service B is very slow to respond, your service A, will not have the calling thread wait for the response, instead service A’s thread will go and do other stuff while it is waiting for the response from service b, and when the response comes back any thread can pick up the response and continue.

A reactive service isn’t reactive if it only calls other reactive services. It’s always reactive. As in it reacts to events.

There are some caveats. For instance if you are talking to a database, here the database driver needs to be a specific driver that is following the R2DBC specification.

You see the traditional JDBC specification for how to write database drivers was designed to be inherently blocking. If you followed the spec and wrote a driver the driver would automatically have to be blocking. You had no choice.

So spring created a new spec (R2DBC) that is not inherently blocking, so you need a driver that is compliant to that spec. Otherwise your service will be affected by blocking behavior.

But the answer to your question is.

No, if we are talking http from one service to another.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement