Not too long ago, a reactive variant of the JDBC driver was released, known as Reactive Relational Database Connectivity (R2DBC for short). While R2DBC started as an experiment to enable integration of SQL databases into systems that use reactive programming models, it now specifies a full-fledged service-provider interface that can be used to retrieve data from a target data source.
In this session, we’ll take a look at the new MariaDB R2DBC connector and examine the advantages of fully reactive, non-blocking development with MariaDB. And, of course, we’ll dive in and get a first-hand look at what it’s like to use the new connector with some live coding!
2. Who is this guy?
Rob Hedgpeth
Developer Evangelist
robh@mariadb.com
@probablyrealrob
rhedgpeth
3. Agenda
● Reactive Programming
○ What is it?
○ Why is it important?
● R2DBC
○ What is it?
○ How can you use it?
● Demo
Non-blocking
Database Euphoria
8. What is a stream?
@mariadb
Variables
changes in data
Starting event
initiates stream of data
Error
disruption in data
Completion
all data is processed
Time
9. Reactive Streams
@mariadb
● An initiative started in 2013 by several companies (e.g. Netflix, Pivotal,
Lightbend and many others)
● A specification
○ API types
○ Technology Compatibility Kit (TCK)
● The goal was to provide a standard for asynchronous stream processing with
non-blocking back pressure.
14. Reactive Streams API
@mariadb
public interface Publisher<T> {
public void subscribe(Subscriber<? super T> s);
}
public interface Subscriber<T> {
public void onSubscribe(Subscription s);
public void onNext(T t);
public void onError(Throwable t);
public void onComplete();
}
public interface Subscription {
public void request(long n);
public void cancel();
}
public interface Processor<T, R> extends Subscriber<T>, Publisher<R> {
}
16. Reactive Programming
@mariadb
● The next frontier in Java (and the JVM) for high-efficiency applications
● Fundamentally non-blocking
○ Often paired with asynchronous behaviors
○ ...but is completely agnostic to sync/async
● The key takeaway - back pressure
Async != Reactive
21. Design principles*
@mariadb
1. Be completely non-blocking, all the way to the database
2. Utilize Reactive Streams Types and Patterns
3. Provide a minimal set of operations that are implementation specific
4. Enable “humane” APIs to be built on top of the driver
* Ben Hale, Creator of R2DBC
22. Goals
@mariadb
✓ Fit seamlessly into Reactive JVM platforms
✓ Offer vendor-neutral access to standard features
✓ Embrace vendor-specific features
✓ Keep the focus on SQL
✓ Keep it simple
○ Provide a foundation for tools and higher-level API’s
○ Compliance should be unambiguous and easy to identify
24. Why a service-provider interface (SPI)?
@mariadb
● One of JDBC’s biggest failings was that the same API had to serve as both
humane API for users as well as an inhumane API for alternative clients like JPA,
Jdbi, etc.
○ API that users didn’t like using
○ Driver authors didn’t like implementing
● It also lead to drivers duplicating effort
○ ? binding
○ URL parsing