The new Hibernate Reactive 1.0 is the first stable version of the reactive API for the popular Hibernate ORM, supporting non-blocking database drivers and a reactive style of interaction with the database.
Hibernate Reactive is an ORM implementation designed to take advantage of non-blocking database clients. Operations are built upon reactive streams instead of synchronous invocations and represented using a chain of Java CompletionStage
interfaces.
The interactions with the database, using the traditional JDBC, JPA or Hibernate ORM approach, are synchronous and made with blocking I/O invocations. This is not the best solution for a reactive application, where it is privileged as an asynchronous and unblocking process.
Out of the box, Hibernate Reactive supports Vert.x clients for PostgreSQL, MySQL, DB2, SQL Server and CockroachDB. An Oracle client is still in the works. It is meant to be used in a reactive environment and is fully integrated with the Vert.x and Quarkus frameworks.
Databases traditionally are designed to be used with blocking calls, therefore it is not guaranteed that a reactive style could perform better in any situation. In a recent blog post, Sanne Grinovero, Hibernate team lead and Quarkus founding engineer at Red Hat, investigated when it might be worth switching to Hibernate Reactive when working with relational databases.
Grinovero used the TechEmpower suite on multiple queries to generate the data for latency response (in ms) under heavy load (requests per second) in the chart below.
He concludes:
So assume you have an SLA which requires you to deliver responses within 10ms; we can conclude that Hibernate ORM "classic" can perform within the SLA requirements as long as the load on this single machine doesn't exceed that limit of 20,000 Requests/second - that's pretty decent, but beyond that, the latency of responses starts to deteriorate quickly.
On the other hand, using Hibernate Reactive we seem able to deliver responses within the same SLA of 10ms even when pushing the load beyond about 35,000 Requests/second. That is clearly better - and by a significant margin.
Another benchmark demonstrates the performance improvements comparing the old beta version of Hibernate Reactive with the latest one.
The chart below represents the throughput per number of clients/threads.
First introduced in December 2020, Hibernate Reactive is still in its infancy and a few limitations are still present compared to "classic" Hibernate ORM, such as the unsupported annotations, Source
and CollectionId.
Meanwhile, its adoption could be straightforward for reactive applications since it uses the same paradigm.