2. Reactive
Programming
! Reactive Programming is the next frontier in
Java for high-efficiency applications
! Fundamentally non-blocking and often paired
with asynchronous behaviors
! Reactive has no opinion on async and many
flows are totally synchronous
! Key differentiator from async is Reactive (pull-
push) back pressure
4. Roadblocks
! There are still some barriers to using Reactive
everywhere*
! Cross-process back pressure (networking)
! Working on RSocket to solve this issue
! Simon Baslé, Up Next
! Data Access
! MongoDB, Apache Cassandra, Couchbase
and Redis
! No Relational Database Access
5. An API designed from the ground
up for reactive programming
https://r2dbc.io
6. Design Principals
! Utilize Reactive Streams Types and Patterns
! Be completely non-blocking, all the way to the
database
! Utilize wire-protocol features where
available
! Shrink the driver SPI to the minimal set of
operations that are implementation specific,
regardless of usability
! Enable multiple "humane" APIs to be built on top
of the driver
7. Driver SPI
! One of JDBC's biggest failings was that the
same API had to serve as both a humane API for
users as well as an inhumane API for alternative
clients like JPA, jOOQ, Jdbi, etc.
! This lead to both an API that users didn't like
using and that driver authors didn't like
implementing
! It also lead to drivers duplicating effort
implementing the same "humane" affordances
like ? binding
16. Great! But a Bit
Verbose
! The Driver SPI contains the minimal set of
operations that are implementation specific and
nothing more
! Definitely usable, but very verbose and prone to
errors
! Explicit transaction management is
analogous to try-catch-finally-try-
catch in JDBC
! What we need is a "humane" client API. In fact
we need many humane client APIs!
17. Simple Select
Flux<String> values = r2dbc.withHandle(handle ->
handle.select("SELECT value FROM test")
.mapRow(row -> row.get("value", String.class)))
18. Simple Prepared Insert
Flux<Integer> updatedRows = r2dbc.withHandle(handle ->
handle.createUpdate("INSERT INTO test VALUES($1, $2)")
.bind("$1", 100).bind("$2", 200).add()
.bind("$1", 300).bind("$2", 400).execute())
19. Transactional Prepared Insert
Flux<String> updatedRows = r2dbc.inTransaction(handle ->
handle.createUpdate("INSERT INTO test VALUES($1, $2)")
.bind("$1", 100).bind("$2", 200).add()
.bind("$1", 300).bind("$2", 400).execute())
20. Spring Data DatabaseClient
DatabaseClient client = DatabaseClient.create(connectionFactory);
Flux<Person> rows = client.execute()
.sql("SELECT * FROM person WHERE name = :name")
.bind("name", "John Doe")
.as(Person.class)
.fetch()
.all();
21. Spring Data Repository
interface CustomerRepository extends
ReactiveCrudRepository<Customer, Long> {
@Query("select * from … WHERE lastname = :lastname")
Flux<Customer> findByLastname(String lastname);
}
repository.findByLastname("Matthews")
.doOnEach(c -> System.out.println(c.firstname))
23. What Can You Do
Today?
! R2DBC 0.8.0.M8, .RC1, .RELEASE
! Driver implementations for H2, Microsoft SQL
Server, PostgreSQL, MySQL (jasync-sql,
r2dbc-mysql)
! Batching
! Extensive Type Conversion
! BLOB/CLOB
! Savepoints
! Transactions
! Leveraging Database-specific features
! ServiceLoader-based driver discovery
! Connection URLs
24. What Can You Do
Today?
! Specification Document
! r2dbc-spi
! Connection Pooling (reactor-pool)
! Client Implementations
! Spring Data R2DBC
! r2dbc-client
! Observability
! r2dbc-proxy
! Micrometer support
25. What About the
Alternatives?
! Wrap JDBC in a thread pool
! Unbounded queue leads to resource
exhaustion
! Bounded queue leads to blocking
! Other specifications
! In early stages and similar in design
! Typically a small number of implementations
! Collaboration likely as the market won't
support multiple specifications
26. Safe Harbor
Statement
The following is intended to outline the general direction of
Pivotal's offerings. It is intended for information purposes
only and may not be incorporated into any contract. Any
information regarding pre-release of Pivotal offerings,
future updates or other planned modifications is subject to
ongoing evaluation by Pivotal and is subject to change.
This information is provided without warranty or any kind,
express or implied, and is not a commitment to deliver any
material, code, or functionality, and should not be relied
upon in making purchasing decisions regarding Pivotal's
offerings. These purchasing decisions should only be
based on features currently available. The development,
release, and timing of any features or functionality
described for Pivotal's offerings in this presentation remain
at the sole discretion of Pivotal. Pivotal has no obligation
to update forward looking information in this presentation.
27. What Does the
Future Hold?
! Additions/improvements to SPI
! Stored procedures
! Auto-commit, fetch size
! Additional implementations
! Google Cloud Spanner
! SAP Hanna and DB2 are investigating
! Prefer database vendors to own drivers
long-term
! Additional clients
! JOOQ, Jdbi, MyBatis have initial support