Database driver

The database driver is a library that adapts the database wire protocol to language constructs such as method calls, callbacks, or potentially Reactive Streams. In the case of relational databases, drivers usually implement a language-level API such as DB-API for Python or JDBC for Java.

It is not a surprise that software written in a synchronous blocking manner uses the same approach for data access. Moreover, usually, communication with an external database through the driver is no different from communication with an external HTTP service. For example, the Apache Phoenix JDBC driver is based on the Avatica component of the Apache Calcite framework and uses JSON or Protocol Buffer over HTTP. Consequently, in theory, we may also apply reactive design to database communication protocols and gain pretty similar benefits, as with the reactive WebClient from the Spring WebFlux module. The following diagram shows that an HTTP request and database query are pretty similar from a network communications standpoint:

Diagram 7.12 Similar blocking IO behavior of the blocking HTTP request and the database request

Usually, the blocking nature of database drivers is dictated by the upper-level API, and not by the wire protocol. Consequently, it should not be tough to implement a reactive database driver that has an appropriate language-level API. The candidates for such an API are covered later in this chapter. At the same time, the NoSQL database driver has no established language-level API to implement, so it is free to implement its own API asynchronously or reactively. For example, MongoDB, Cassandra, and Couchbase decided to take this route, and they now provide either asynchronous or reactive drivers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.31.165