ayan ahmedov
ayan ahmedov

Reputation: 391

reactive programming basics during blocking http call

As someone newly investigating reactive programming, I'm having a question seems not answered elsewhere:

How does a blocking call (i.e http request from frontend) really utilize this concept?

My understanting is this, and question is about correction if its mistaken:

  1. Frontend user clicks a button and thereof makes an ajax call.
  2. Then browser makes a regular http request
  3. Reactive backend then is in nature still a blocking server. Such that, http response in not provided back until the whole thing completes
  4. Reactive nature comes here in place, that instead of handling 1 request from frontend in 1 thread, it insteads uses less threads, by saving callbacks when to execute what. Making use of library APIs to manage that complexity somehow.
  5. At the end of the day, http call we made form frontend, is still, a blocking call. And what is different to thread-based concurrency is, we delegated blocking calls to other threads(actually, how come then there is less threads used?) such as DB calls, external Rest calls etc. And at the end, we blocking-wait till they all complete.

Are those assumptions correct?

Going further for lets yes basic understanding is correct, what makes this kind of approach more suitable from a thread-based approach?

Assume in my case, expected concurrent users aren't really that big, top 500 people at the same time.

Upvotes: 5

Views: 559

Answers (1)

injecteer
injecteer

Reputation: 20707

Your assumtions are correct in general. This is how almost any rather modern web-app be it vertx, micronaut or spring-boot+ works.

If the user expects the request to be synchronous (meaning he's waiting till it finishes) then the server has to execute it in a blocking manner, BUT without blocking itself, so that other users can also fire their requests in parallel.

Reactive on it's own is rather the way how you structure your code, i.e. in RxJava instead of callbacks (hell) you use methods chains, but it doesn't change the nature of request processing in general.

Upvotes: 2

Related Questions