Introduction

Eclipse Vert.x and reactive in just a few words

Eclipse Vert.x is a tool-kit for building reactive applications on the JVM. Reactive applications are both scalable as workloads grow, and resilient when failures arise. A reactive application is responsive as it keeps latency under control by making efficient usage of system resources, and by protecting itself from errors.

ServiceServiceServiceServiceServiceMessagingDatabase

Vert.x is backed by a large ecosystem of reactive modules with just anything you need when writing modern services: a comprehensive web stack, reactive database drivers, messaging, event streams, clustering, metrics, distributed tracing and more.

Vert.x is a tool-kit and not a framework that ships with black magic: what you write is actually what you get to execute, as simple as that.

So what makes Vert.x a great option for writing your next cloud-native or twelve-factor app?

In the beginning, there were threads…

The classic approach to concurrency is to use threads. Multiple threads can live within a single process, perform concurrent work, and share the same memory space.

Shared memoryThread 1Thread 2Thread 3Thread 4Request #1Request #2Request #3Request #4

Most application and service development frameworks are based on multi-threading. On the surface, the model of having 1 thread per connection is reassuring because developers can rely on traditional imperative style code.

This is fine, especially if you forget about those silly mistakes you can make with multi-threading and memory access …

Multi-threading is “simple” but limited

What happens as the workload grows beyond moderate workloads? (see the C10k problem)

The answer is simple: you start making your operating system kernel suffer because there is too much context switching work with in-flight requests.

ThreadsBlocking I/O(wasted CPU time)

Some of your threads will be blocked because they are waiting on I/O operations to complete, some will be ready to handle I/O results, and some will be in the middle of doing CPU-intensive tasks.

Modern kernels have very good schedulers, but you cannot expect them to deal with 50 000 threads as easily as they would do with 5 000. Also, threads aren’t cheap: creating a thread takes a few milliseconds, and a new thread eats about 1MB of memory.

Asynchronous programming: scalability and resource efficiency

Processing more concurrent connections with less threads is possible when you use asynchronous I/O. Instead of blocking a thread when an I/O operation occurs, we move on to another task which is ready to progress, and resume the initial task later when it is ready.

Vert.x multiplexes concurrent workloads using event loops.

TimeEvent-loop threadEvents

Code that runs on event loops should not perform blocking I/O or lengthy processing. But don’t worry if you have such code: Vert.x has worker threads and APIs to process events back on an event loop.

Pick the best asynchronous programming model for your problem domain

We know that asynchronous programming requires more efforts. At the core of Vert.x, we support callbacks and promises/futures, the latter being a simple and elegant model for chaining asynchronous operations.

Advanced reactive programming is possible with RxJava, and if you prefer something closer to traditional imperative programming, then we are happy to provide you with first-class support of Kotlin coroutines.

consume(message)DatabaseServiceMessage queueMessagepersist(data)send(text)#1#2#3asyncasyncasync

Vert.x supports many asynchronous programming models: choose what works best for each problem you need to solve!

Don’t let failures ruin responsiveness

Failures happen all the time. A database will go down, the network will go down, or some service you depend on will become unresponsive.

ServiceServiceServiceServiceServiceMessagingDatabaseFailureOkCascading failures

Vert.x offers tools to keep latency under control, including a simple and efficient circuit breaker.

A rich ecosystem

The Eclipse Vert.x stack contains modules for building modern, end-to-end reactive services. From efficient reactive database clients to event streaming, messaging and web stacks, the Eclipse Vert.x project has you covered:

ReactiverseCommunityEclipse Vert.xStackReactive databaseclientsMessaging andevent streamsWeb APIs and clientsMicro-services andcloud nativeSecurity andauthenticationIntegrationClustering(…)

Can’t find what you are looking for?

  • The Reactiverse is a larger community around the reactive ecosystems where you can find more client and modules.
  • The Vert.x Awesome repository provides links to even more interesting projects from the larger open-source community!