Assume we have a 2 rest services:
// a rest controller
@GetMapping
private List<Employee> getAllEmployees() {
return employeeRepository.findAllEmployees();
}
// another controller
@GetMapping
private Flux<Employee> getAllEmployees() {
return employeeRepository.findAllEmployees(); // suppose reactive db driver here
}
a there any difference for client's web browser between this code?
Normal Rest Controller: Suppose server is going to return some 10000 records.In this case the server waits for the database to return all the data and this data is forwarded as response. So you recieve all the response in one shot in the mean time, browser will be continuosly loading with blank page and thats a bad experience in this modern era
Reactive Controller: In webflux spring Reactive Controller their is a concept of back pressure. In back pressure their is open connection between server and database, so whatever the records have been received will be continuously emitted as a response. Hence no blank screen and better user experience.
Note: The connection between browser will remain intact till the time all data is loaded in browser