Why you should use Vertx in 2018

Posted at 12:34 9th Jan 2018

Updated at 09:52 25th Jul 2018

After moving from the Play Framework, we've had nothing but praise for Vertx. It's actually very easy to get started with. A huge benefit is that it supports more than one language. The current supported language list includes Java, JavaScript, Groovy, Ruby, Ceylon, Scala and Kotlin.

What is Vertx?

The homepage of Vertx says: Eclipse Vert.x is event driven and non blocking. This means your app can handle a lot of concurrency using a small number of kernel threads. Vert.x lets your app scale with minimal hardware. You can do a lot of things with Vertx, with the main thing being server and microservice building. There are other use-cases such as creating a message bus, networking, real-time feeds and more. The main gist of Vertx is that it's asynchronous and it's mostly event-driven.

How easy is it to get started with Vertx?

Super easy. Let's say you've got a Kotlin based Vertx REST API. Vertx will call those relevant methods in your class. Here's a live example of one of our API methods that handles retrieval of a user's friends:

class RelationsRouter() {

    // Create a router that handles a user's friends
    override fun create(): Router {
        router.route().handler(tokenHandler) // Checks if they have a correct auth_token
        router.route().handler(checkRecordoAccountHandler) // Checks if they have a Recordo account

        // Get the user's relations list
        router.get("/").handler { r ->
            val userRecordo = r.userRecordo()
            val rs = userRecordo.relations
            r.done(rs)
        }
        
        return router
    }

}

And that's it. Of course we have added some Kotlin magic in there but the gist of it is as shown above. The main thing to note is that handlers should not block. If they do block then Vertx will start complaining.

What makes Vertx so special?

There are a couple of things:

  1. Fast startup times. For us it takes about 5 to 8 seconds for both a cold start and a hot reload. Potentially milliseconds now as a result of a recent announcement.
  2. Developer productivity. Related to the above, if the application takes too long to load, then developer productivity suffers. However, with Vertx's simple and easy to follow API, we felt that productivity soared.
  3. Awesome libraries. Actually this may be one of our favourite parts about Vertx. Just look at this page and you'll find components, extensions and libraries for anything you could ever want to code. Truly developer nirvana. If that isn't enough, then you can also plugin any library from external repositories.
  4. Stable. We first trialed NodeJS but there was no type safety and no mature and stable libraries to support us. Then we trialled Play Framework, the boot up times and hot reload times were dreadful taking 60 seconds to 180 seconds per minor change, however the API changed very frequently. Vertx's API doesn't change very drastically from version to version.
  5. Database access. There's a connector for every type of database.
  6. Bring your own build tool. There are only a few commands to compile, build, start and keep Vertx running but they are well documented. We're pretty sure you can run those commands from any build tool.
  7. Lightning speed. It takes on average 44 to 110 milliseconds for a local device-to-device network call to complete, whereas on Play Framework it took around 300 to 600 milliseconds.
  8. Web ready. Add libraries which protect against CSP, XSRF and also provide JWT. Parse requested form parameters automatically, implement websockets, implement a service discovery mechanism, add cookies, headers, and loads more.
  9. Asynchronous by default. This may scare some developers but this is one of the best features as it increases speed and the ability to handle more clients.

To conclude, just use Vertx for your web projects/microservices from now on.

Please note: This was not a paid promotion in any way. We like it so much that it's worth shouting about.