Recently I dabbled with Spring Webflux and Spring Data R2DBC for a while. I compiled a few notes for myself after the exercise.
- R2DBC (the reactive driver for RDBMSs) is still in its nascent stage. It does not support a lot of features that we take for granted in other drivers.
- For a truly reactive application I think it is important to not let any flow 'cache' data. Instead every function should take reactive inputs and give reactive outputs.
- We should take care that there are no breaks in the chain of input and output of a reactive function. One of the core insights I learnt in this implementation is that the client which is calling the webservice is the ultimate subscriber to the reactive flows in our code. The client supplies data in a reactive request object which is then mapped to in our code via various transformations to other reactive types, and finally returned as a reactive type to our client, who again pulls (or subscribes to) this data from the server back to it. So while these transformations are occurring in our code, there shouldn't be any new reactive types created that are left unsubscribed. This was a frequent issue that is hard to debug as your client will just keep on waiting and you won't know where your chain broke from the logs.
- Spring Webflux is not a very mature framework as of now. I struggled for a while to figure out the ways to implement filters and context propagation. Compared to Vertx, Spring should make it more understandable how they want the context to be used. In Vertx, it was quite straightforward to use the context to store things like session ids.
- Debugging is a pain in the Webflux reactive world. The data is hidden, and you cannot see the values of your variables. It is important therefore to log as much as possible.
- Also the functional way of writing code in Webflux is much advanced and useful than the annotations way. So always use the functional handlers/routers etc to get better grip on your flow.
- Webflux does indeed bring clarity to code. By removing traditional exception handling, and adding fluent calls it makes code easier to understand. Although the chances of errors also increase because of the opaqueness of reactive types, I think performance should be the ultimate factor in deciding whether or not to use Webflux.
Comments
Post a Comment