Skip to content

Use case of Flux and Mono

I am new to world of Flux and Monos, and recently, while using the findAll() method, I realized that this method is capable of returning partial responses , i.e via the Flux , and I need to do append a block() if i need all the records from the CosmosDB.

I was wondering what could possibly be the real world use case or purpose of having a Flux with partial records ?



The whole idea of reactive programming is to change the method of processing items from pull to push.

This mean that you can process received items one by one.

Imagine situation, when your items are arriving with 3 sec delay in flux and processing time, is 2 sec in your application for a received item. If the flux will contain like 20 items then you wait for 60 sec for whole data (20 items) and then you need to wait another 40 sec for items to be processed.

With reactive approach, you can consume them one by one and as a result, your processing is completed after 60 sec.

The life example for partial results processing could be some API that has limitations – can return max 2000 records (Salesforce is the platform with this limitation). So in case you want to pull all those records – ex. 50 000 – you need to call rest API 25 times. This service can have network latency + query time so it would be useful to process that partially.


block() is not the right way to work with Reactor API

see: How to get String from Mono<String> in reactive java