Understanding Vert.x: working with SQL

Photo by Jack Anstey on Unsplash

Based on questions I regularly answer on StackOverflow, I feel that developers often misunderstand how Vert.x works with SQL databases.

Main concept that you need to understand, is that almost all RDBMS drivers work synchronously. Only exception I’m aware of currently is PostreSQL, which also explains why PostreSQL has a huge advantage in latest TechEmpowered benchmarks.

But Vert.x is asynchronous. When executing DB queries in Vert.x, you’re clearly passing a callback. So, it’s asynchronous then, no?

Well, not exactly. To understand a bit more, let’s look at method:

is a simple object. The interesting part is the method. Let’s go deeper, into :

It’s in the method’s name:

Now, you may wonder where does this comes from. It comes from :

Some conclusions

In the end, regular Vert.x JDBC client doesn’t have any magic in it.

It uses a simple data source under the hood: C3P0 by default, but you can also use Hikari if you like. You may want to set the pool size bigger though, as default is 15 connections.

Main goal of this implementation is simple — not to block the event loop (never block the event loop). And it’s actually pretty good for most use cases. Just don’t expect that it will do something magical with JDBC, like make it non-blocking.

Solutions Architect @Depop, author of “Hands-on Design Patterns with Kotlin” book and “Web Development with Kotlin” course

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store