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
JDBCQuery is a simple object. The interesting part is the
execute() method. Let’s go deeper, into
It’s in the method’s name:
Now, you may wonder where does this
ctx comes from. It comes from
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.