Under the Hood of
Reactive Data Access
Mark Paluch
@mp911de
1
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring Data Modules
2
JPA
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Spring Data Modules
3
JPA
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
JDBC
Fully-blocking API
Non-blocking API announced (JDK-8188051)
4
http://mail.openjdk.java.net/pipermail/jdbc-spec-discuss/ • JDK-8188051: http://hg.openjdk.java.net/jdk10/sandbox/jdk/rev/a31057bda7c5
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Relational Databases
Limited scalability
Resource synchronization
Transactions
5
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Query by time
6
Transport
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Synchronous Data Access
7
Data store
App
Data store
App
Data store
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Data Access
8
Data store
App
Data store Data store Data store
App
🎉
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Differences to imperative Data Access
Drivers require threading infrastructure
Timeout handling different
9
Reactive NoSql drivers
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive drivers
End-to-end nonblocking
Asynchronous request-response processing
Non-blocking pooling
Non-blocking connect
11
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Application Driver Application
12
Request Server selection
Queueing
Write Response decoding
Response buffering
Request completion Response
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
MongoDB
Reactive-over-async driver
Cursor lifecycle
Pluggable I/O
Pooled connections
13
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Query by time
14
Request
Response
(chunk)
Response
(complete)
Prefetch
(cont.d)
Query
Emit
elements
Result
processing
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
MongoDB Driver Fetching
15
OperatorMongoDB Subscriber
request(Long.MAX_VALUE)request(Long.MAX_VALUE)
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
MongoDB Driver Fetching
16
FilterMongoDB Subscriber
request(Long.MAX_VALUE)request(Long.MAX_VALUE)
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
MongoDB Driver Fetching
17
Operator
(filter)
MongoDB Subscriber
request(1)
Dropped element
request(Long.MAX_VALUE)
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Specific Features
Tailable Cursors (@Tailable)
MongoDB 3.6: Change Streams
18
Cursor size derived from demand
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Redis
Reactive driver (Lettuce 5)
Based on Netty and Project Reactor
Singleton connection
Pooled connections
19
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Command by time
20
Request
Command
Command
(subscription)
Response
(chunk)
Response
(complete)
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Specifics
Use ByteBuffer instead byte[]
@null handling: Emission of empty buffers
Suspend reading if no demand
21
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Apache Cassandra
Reactive bridge over async driver
Netty-based driver (Datastax)
Pooled connections
22
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Query by time
23
Request
Response
(chunk)
Response
(complete)
Query
Emit
elements
Result processing
Next page
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Outlook
Cassandra driver 4.0 in the works
Likely support for reactive execution model
Emit items as they are received
24
https://github.com/datastax/java-driver/tree/4.x • https://datastax-oss.atlassian.net/browse/JAVA-1505
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Couchbase
Reactive driver driver
Based on Netty and RxJava 1
Multiple connection schemes
25
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Couchbase Fetching
Key-Value, DCP
1. Request
2. Response
3. Emit results

Search, Query, View
1. Request
2. Response streaming
26
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Command by time
27
Request
Command
Command
(subscription)
Response
(chunk)
Response
(complete)
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Outlook
Couchbase driver likely to move to RxJava 2
• No tickets/decisions yet
28
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Resources
Slides – mp911.de/s1p-hood-slides
Example Code – mp911.de/s1p-hood-code
Spring Data Examples – Repository @ Github
Find us on Gitter!
29
Feedback welcome
Learn More. Stay Connected.
31
#springone@s1p
Disclaimer
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
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.
33

Under the Hood of Reactive Data Access (2/2)

  • 1.
    Under the Hoodof Reactive Data Access Mark Paluch @mp911de 1
  • 2.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Modules 2 JPA
  • 3.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Spring Data Modules 3 JPA
  • 4.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JDBC Fully-blocking API Non-blocking API announced (JDK-8188051) 4 http://mail.openjdk.java.net/pipermail/jdbc-spec-discuss/ • JDK-8188051: http://hg.openjdk.java.net/jdk10/sandbox/jdk/rev/a31057bda7c5
  • 5.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Relational Databases Limited scalability Resource synchronization Transactions 5
  • 6.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Query by time 6 Transport
  • 7.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Synchronous Data Access 7 Data store App Data store App Data store
  • 8.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Data Access 8 Data store App Data store Data store Data store App 🎉
  • 9.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Differences to imperative Data Access Drivers require threading infrastructure Timeout handling different 9
  • 10.
  • 11.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive drivers End-to-end nonblocking Asynchronous request-response processing Non-blocking pooling Non-blocking connect 11
  • 12.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Application Driver Application 12 Request Server selection Queueing Write Response decoding Response buffering Request completion Response
  • 13.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ MongoDB Reactive-over-async driver Cursor lifecycle Pluggable I/O Pooled connections 13
  • 14.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Query by time 14 Request Response (chunk) Response (complete) Prefetch (cont.d) Query Emit elements Result processing
  • 15.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ MongoDB Driver Fetching 15 OperatorMongoDB Subscriber request(Long.MAX_VALUE)request(Long.MAX_VALUE)
  • 16.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ MongoDB Driver Fetching 16 FilterMongoDB Subscriber request(Long.MAX_VALUE)request(Long.MAX_VALUE)
  • 17.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ MongoDB Driver Fetching 17 Operator (filter) MongoDB Subscriber request(1) Dropped element request(Long.MAX_VALUE)
  • 18.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Specific Features Tailable Cursors (@Tailable) MongoDB 3.6: Change Streams 18 Cursor size derived from demand
  • 19.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Redis Reactive driver (Lettuce 5) Based on Netty and Project Reactor Singleton connection Pooled connections 19
  • 20.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Command by time 20 Request Command Command (subscription) Response (chunk) Response (complete)
  • 21.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Specifics Use ByteBuffer instead byte[] @null handling: Emission of empty buffers Suspend reading if no demand 21
  • 22.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Apache Cassandra Reactive bridge over async driver Netty-based driver (Datastax) Pooled connections 22
  • 23.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Query by time 23 Request Response (chunk) Response (complete) Query Emit elements Result processing Next page
  • 24.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outlook Cassandra driver 4.0 in the works Likely support for reactive execution model Emit items as they are received 24 https://github.com/datastax/java-driver/tree/4.x • https://datastax-oss.atlassian.net/browse/JAVA-1505
  • 25.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Couchbase Reactive driver driver Based on Netty and RxJava 1 Multiple connection schemes 25
  • 26.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Couchbase Fetching Key-Value, DCP 1. Request 2. Response 3. Emit results
 Search, Query, View 1. Request 2. Response streaming 26
  • 27.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Command by time 27 Request Command Command (subscription) Response (chunk) Response (complete)
  • 28.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outlook Couchbase driver likely to move to RxJava 2 • No tickets/decisions yet 28
  • 29.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Resources Slides – mp911.de/s1p-hood-slides Example Code – mp911.de/s1p-hood-code Spring Data Examples – Repository @ Github Find us on Gitter! 29
  • 30.
  • 31.
    Learn More. StayConnected. 31 #springone@s1p
  • 32.
  • 33.
    Unless otherwise indicated,these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 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. 33