Reputation: 99
I am new to reactive programming and one thing I wanted to know is, suppose we have an api which calls 3 other api's internally. In which the result of first api is fed into the second, while the output of second api is fed into third. Does it not reduces to a normal single thread based execution. If yes then why should we use reactive programming in such a scenario.
Upvotes: 2
Views: 673
Reputation: 59231
In this scenario, reactive programming won't change the law of physics or logic: you'll still need the result of the previous step to produce the next one. So it's likely that executing that logic with a blocking API or a reactive will take as much time.
But in the case of a blocking I/O API, processing this will indeed use a thread for the whole operation, even when the server is waiting for the remote API to respond. Hundreds of calls to your API will mean hundreds of threads and their associated resources, often sitting down nothing while waiting for remote resources.
If you're using a reactive API instead, your server will use fewer threads and will not keep using resources while waiting for those remote responses.
In summary, while not improving the speed of this use case, it will improve the scalability of your service and consume less resources (memory and CPU).
Upvotes: 4