Skip to main content

On Spring Webflux and R2DBC


Recently I dabbled with Spring Webflux and Spring Data R2DBC for a while. I compiled a few notes for myself after the exercise.
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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

Popular posts from this blog

Sheep or wolf?

 If you are a good person, then you are most likely also not very smart. Smarter people around you will continue to take advantage of your goodness to get their work done.  So you are either a sheep or a wolf. If you are a sheep then wolves will keep on exploiting you, and if you are a wolf, you will have to keep on exploiting sheep; but if you are a smart wolf, the sheep won't even know that they are being used. Infact most sheep don't even know that they are sheep, or that wolves exist.  Even among wolves, survival is hardly easy. It is hard to find a sheep who is not already being taken advantage of by someone. Once you are a wolf, it is almost impossible to go back to working hard. So you are actually dependent on finding prey. Even though a wolf is usually smarter than its prey, it is actually weaker in the sense that it is purely dependent on the mercy of its prey to sustain it. It is far more prevalent to find wolves among the female population. Females have a natu...

The ascent

  I was nineteen, oh what an age!  Soon college would begin. I was ensconced in a chair on the rooftop. The late spring afternoon had a fierce glow, which we called 'loo' in the local vernacular. A kite encircled a distant carrion in the azure sky. The kite was intent on the present, and I was thinking about the future that beckoned. Doubts nagged my conscience. Uncertainties clouded my sky. My failures haunted my present. Will I ever be good enough? Suddenly I lost the train of my thoughts. For a few moments I could not comprehend what my eyes recorded. A single thought overran everything else: who was I? After I regained myself from this brief escape, the kite's repartee with the descending sun seemed far away. The hot cemented rooftop seemed aloof. The searing, barren air seemed powerless. I felt a stark confidence coming to my rescue like an old friend. A tremendous calm had filled my being. After a very long time, I felt lucid. I realized the immense capacity for joy t...

Is beauty truth and truth beauty?

In my Ayn Rand influenced adolescence, I used to mull over all idealistic musings that I came across. One of my favorites was John Keats ’s ‘beauty is truth, truth beauty’, which I almost internalized. When I was recently reading Walter Isaacson’s biography of Steve Jobs , I came across a notion which formed the basis of Jobs' personality- that beauty and perfection have a common origin - love. But if love causes beauty, then going by what Keats said, it must also reveal a truth. This article has been written to understand more of this hypothesis and its consequences. Jobs always considered himself more of an artist than an innovator. His ideas appealed more to intuition than to logic. This is one of the reasons why he always had a larger worldview and could leapfrog the others, because intuition may be considered as the condensed version of logic and feelings. Intuition is what we may call instinct: the impulse that is generated out of the sum-total of our mind. In c...