Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive SQL: why do we care?

Reactive SQL: why do we care?

Asynchronous and non-blocking programming allows us to make the most out of the available hardware, thus increasing density of deployment and reducing costs and waste of resources. The benefits are prominent in Microservices Architecture when combining different sources of data transiting over the network. In their toolbox, many Java developers are equipped with reactive HTTP clients, but is there a point without the same for SQL?

In this presentation, we will explore a few solutions for non-blocking database access. We will start with wrapping a JDBC driver, then use a Vert.x Reactive SQL Client. Eventually, we will introduce the Hibernate Reactive ORM. Based on each of their advantages and limitations, you will be able to make your choices between compatibility or efficiency, flexibility or productivity.

Thomas Segismont

June 23, 2022

More Decks by Thomas Segismont

Other Decks in Technology


  1. What we’ll discuss today ▸ Modern application design ▸ Vert.x

    SQL Clients ▸ Hibernate Reactive Agenda 2
  2. 4 CRUD A very different landscape Evolution of use cases

    From backoffice to “webscale” apps Event Driven Architecture
  3. A very different landscape 6 Virtual machine Bare metal Containers

    Evolution of deployment targets Maximize density
  4. Applications that involve a variety of network interactions ▸ RDBMS

    ▸ NoSQL ▸ External API (HTTP or gRPC) 7 Many applications colocated and sharing virtual resources ▸ vCPU ▸ (Relatively) small heaps The new normal A very different landscape
  5. Each request handled by the server is assigned a thread

    from the worker pool. 9 The need for Reactive Thread per request Request 1 Request 2 Request n
  6. Each event loop handles different requests. It must not be

    blocked. Timeout and failures are events. 10 The need for Reactive Event loop threads Event loop 1 Request 1 Request 2 Event loop 2
  7. Resource efficiency Keep the number of threads to a minimum,

    keep them busy. More than performance QoS: deal better with heavy load, failures and timeouts The need for Reactive 11 The need for Reactive Takeaways
  8. SQL: a good fit? 13 ▸ Document-oriented ▸ Key Value

    ▸ Column-oriented Alternative storage systems Born in the new era
  9. SQL: a good fit? 14 ▸ Proven, high performing ▸

    Many modern features (JSON, geospatial, K/V) ▸ Competencies ▸ Existing systems Relational DBs have arguments
  10. SQL: a good fit? 15 ▸ JDBC ▸ RxJDBC ▸

    Postgresql-async (PostgreSQL and MySQL) ▸ Vert.x SQL Clients ▸ R2DBC Talking to Relational DBs in Java
  11. Vert.x SQL Clients In a nutshell 17 All Vert.x SQL

    Clients implement a set of high-level API: Connection, Pool, Transaction, …etc A set of high level APIs JDBC wrapper “Native” (PostgreSQL, MySQL, MS SQL Server, IBM DB2) Oracle with JDBC Reactive Extensions Client implementations SQL Client Templates make it easier to execute queries and extract results using parameters and row mappers. Templates
  12. Offloads blocking JDBC method invocations to a worker thread 19

    Vert.x SQL Clients Vert.x JDBC Client Worker Event loop
  13. On the down side: ▸ Increased number of threads ▸

    Context switching ▸ Careful with provisioning Vert.x SQL Clients 21 On the up side: ▸ Works with any JDBC driver ▸ Vert.x SQL Client API ・ Collector queries ・ Templates Takeaways Vert.x JDBC Client
  14. Database protocol codec invoked on the event loops. Message passing

    instead of context switching. 23 Vert.x SQL Clients Vert.x “Native” clients Event loop 1 Request Event loop 2 Query 1 Query 2
  15. Pipelining requests allows to save network time. Supported by PostgreSQL

    and MySQL clients. 24 Vert.x SQL Clients Vert.x “Native” clients Source: https://foojay.io/today/optimizing-relational-database-access/
  16. Unix domain sockets simplify provisioning. Supported by PostgreSQL and MySQL

    clients. 25 Vert.x SQL Clients Vert.x “Native” clients /var/run/postgresql/.s.PGSQL.5432
  17. On the down side: ▸ Feature set depends on the

    client ▸ Limited number of supported databases Vert.x SQL Clients 27 On the up side: ▸ Vert.x SQL Client API ▸ No context switching ▸ Pipelining (PostgreSQL, MySQL) ▸ Domain Sockets (PostgreSQL, MySQL) Takeaways Vert.x “Native” Clients
  18. The Hibernate engine with adapters for Vert.x SQL Client instead

    of JDBC. API in two flavors: Mutiny, or CompletionStage. 29 Hibernate Reactive Hibernate Reactive Mutiny CompletionStage SQL Client reactive drivers PostgreSQL MySQL DB2 MS SQL ...
  19. On the down side: ▸ Not an excuse to not

    learn SQL ▸ Not for any use case Hibernate Reactive 31 On the up side: ▸ Annotated beans ecosystem ▸ Schema update ▸ HQL / JPQL Takeaways Hibernate Reactive
  20. linkedin.com/company/red-hat youtube.com/user/RedHatVideos facebook.com/redhatinc twitter.com/RedHat 35 Red Hat is the world’s

    leading provider of enterprise open source software solutions. Award-winning support, training, and consulting services make Red Hat a trusted adviser to the Fortune 500. Thank you