SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
Reactive Applications with
Apache Pulsar and Spring Boot
Lari Hotari @lhotari
Senior Software Engineer, DataStax, Inc
Apache Pulsar committer
Presentation at SpringOne 2021
September 2, 2021
Who
2
Lari Hotari @lhotari
Software Engineer @DataStax, working on Luna Streaming powered by Apache Pulsar
Open-source contributor, Apache Pulsar committer
Journey with Spring:
○ Spring Framework user since 0.9 (2003)
○ Early Spring Framework contributor (2007, WebSphere DataSource support
for Spring Transaction Management)
○ Grails contributor (2009-2020)
Member of Groovy and Grails team (part of the Spring team) at Pivotal (2014-2015)
Grails team released Grails 3.0 built on Spring Boot in March 2015
○ Spring Boot contributor (heapdump actuator)
○ Project Reactor contributor (dns reverse lookup optimization & few others
in reactor-netty, 1 minor in reactor-core)
2004
2002
2005
2003
3
Pulsar & Reactive
Messaging
01
Sample use case &
Live coding
02
Scaling performance
of message
processing
03
Agenda
4
Pulsar & Reactive
Messaging
01
Sample use case &
Live coding
02
Scaling performance
of message
processing
03
Agenda
Apache Pulsar - Favourite properties
5
Many options for
scaling - not just about
partitions
02
Streaming, pub-sub
and queuing come
together
01
Cloud Native
Architecture
Layered storage
architecture
Stateless Brokers
First class support
for Kubernetes
03
Reactive Message handling - why?
6
Fault tolerance with
fallbacks, retries and
timeouts
Compatibility with
Reactive Streams to
achieve reactive from
end-to-end
Performance by
parallelism and
pipelining in
processing
Resilience with flow
control (backpressure)
Efficiency by optimal
resource usage
Simplification by
data orientation &
functional approach
Reactive Pulsar Adapter library
● https://github.com/lhotari/reactive-pulsar , License: ASL 2.0
● Wraps the Apache Pulsar Java Client async API with a simple and intuitive reactive API
● Goes beyond a wrapper
● Back-pressure support for provided interfaces
● Pulsar client resource lifecycle management
● Message producer caching
● In-order parallel processing at the application level
● Spring Boot starter for auto configuring a Pulsar Java client and a ReactivePulsarClient
7
Reactive Messaging Application building blocks
provided by the Reactive Pulsar Adapter library
8
Message Sender
Message Consumer
Message Listener Container
Message Reader
● Sender - for sending messages with a specific
configuration to a specific destination topic.
● Consumer - for guaranteed message delivery and handling.
The broker redelivers unacknowledged messages. Used for
both “always on” use cases and batch processing or
short-time message consuming or polling use cases.
● Reader - The application decides the position where to start
reading messages. Position can be earliest, latest, or an
absolute or time based position. Suitable also for
short-time message polling.
● Message Listener Container - integrates a consumer with
the Spring application lifecycle.
*) The abstractions of the Reactive Pulsar Adapter library are slightly different from the abstractions in Pulsar Java Client. The sender
is one example of a difference. The lifecycles of the abstractions are completely different. The ReactiveMessageSender,
ReactiveMessageReader and ReactiveMessageConsumer instances themselves are stateless.
“Nothing happens until you subscribe” - the key difference in the Reactive programming model.
Basics of Reactive APIs
9
- “Nothing happens until you subscribe”
- Assembly-time vs Runtime
- API calls return a reactive publisher type
- Flux<T> or Mono<T> when using Project Reactor
- Mono<Void> for calls that don’t return data
Reactive Pulsar Adapter
public interface ReactivePulsarClient {
<T> ReactiveMessageSenderBuilder<T> messageSender(Schema<T> schema);
<T> ReactiveMessageReaderBuilder<T> messageReader(Schema<T> schema);
<T> ReactiveMessageConsumerBuilder<T> messageConsumer(Schema<T> schema);
}
10
public interface ReactiveMessageReader<T> {
Mono<Message<T>> readMessage();
Flux<Message<T>> readMessages();
}
public interface ReactiveMessageSender<T> {
Mono<MessageId> sendMessage(Mono<MessageSpec<T>> messageSpec);
Flux<MessageId> sendMessages(Flux<MessageSpec<T>> messageSpecs);
}
public interface ReactiveMessageConsumer<T> {
<R> Mono<R> consumeMessage(
Function<Mono<Message<T>>, Mono<MessageResult<R>>> messageHandler);
<R> Flux<R> consumeMessages(
Function<Flux<Message<T>>, Flux<MessageResult<R>>> messageHandler);
}
Sample use cases - simplified IoT backend
11
Telemetry ingestion
from IoT devices
Telemetry processing
Streaming of telemetry values
to other applications
Sending alerts to
external application - webhook
interface
https://github.com/lhotari/reactive-pulsar-showcase for complete sample (work in progress)
12
Pulsar & Reactive
Messaging
01
Sample use case &
Live coding
02
Scaling performance
of message
processing
03
Agenda
Our goal for live coding
13
14
Pulsar & Reactive
Messaging
01
Sample use case &
Live coding
02
Scaling performance
of message
processing
03
Agenda
All significant improvements in
system scalability come from
parallelism.
15
Pipelining
16
“This idea is an extension of the idea of
parallelism. It is essentially handling the
activities involved in instruction execution
as an assembly line. As soon as the first
activity of an instruction is done you move
it to the second activity and start the first
activity of a new instruction. This results in
executing more instructions per unit time
compared to waiting for all activities of the
first instruction to complete before
starting the second instruction.”
https://www.d.umn.edu/~gshute/arch/great-ideas.html
Parallel Pipelining with Project Reactor:
Without ordering requirements
17
● When there are no ordering requirements, parallelism/concurrency can be achieved in two ways:
Using .parallel operator
(parallelism, for computations)
Flux
.range(1, 10)
.parallel(10)
.runOn(Schedulers.parallel())
.concatMap(i -> {
// CPU bound
…
// that returns a publisher
}
)
.sequential()
.subscribe()
Using .flatMap + .subscribeOn for inner publisher
(concurrency, for I/O tasks)
Flux
.range(1, 10)
.flatMap(
i -> {
// IO bound
…
// that returns a publisher
}.subscribeOn(Schedulers.parallel()),
10
)
.subscribe()
In-order parallel processing strategies
● System level: Multiple topic partitions
● Message is mapped to a specific partition by hashing the key
partition = hash(message key) % number_of_partitions
● Application level: Message consumer parallelism
● Micro-batching
● Messages are consumed in batches which is limited by time and number of entries.
● The processing can sort and group the entries for parallel processing.
● Stream splitting / routing / grouping
● Message is mapped to a specific processing group based on the hash of the message key
processing group = hash(message key) % number_of_processing_groups
● This is well suited for splitting the stream with Project Reactor’s .groupBy
● Benefit over micro-batching: no extra latency caused by batching
18
Parallel Pipelining with Project Reactor:
In-order processing requirements
19
When there is a requirement of in-order processing by key:
● .groupBy operator splits the stream by a key. The total
number of keys should be limited and relatively small
(hundreds).
● The concurrency level parameter for flatMap should be
set to the total number of groups to prevent the stream
processing from stalling (explained in Flux.groupBy
javadoc). In addition, the “prefetch” parameter of
.groupBy should be set to a value >= total number of
groups.
Flux
.range(1, 10)
// simulation of key: 0 (even) or 1 (odd)
.groupBy(i -> i % 2, Math.max(10, 32))
.flatMap(
groupedFlux ->
groupedFlux
.publishOn(Schedulers.parallel())
.concatMap(x -> {
// IO bound
…
// that returns a publisher
})
10,
1
)
.subscribe()
Parallel processing with ReactiveMessageConsumer
20
● An enabler is the the special signature of the
consumeMessages method on the
ReactiveMessageConsumer interface.
● The method accepts a function that takes
Flux<Message<T>> input and produces
Flux<MessageResult<R>>> output.
● MessageResult combines
acknowledgement and the result. The
implementation consumes the
Flux<MessageResult<R>>> , handles the
acknowledgements, and returns a Flux<R> .
● This enables guaranteed message delivery
combined with stream transformations.
public interface MessageResult<T> {
static <T> MessageResult<T> acknowledge(MessageId messageId, T value) {}
static <T> MessageResult<T> negativeAcknowledge(MessageId messageId, T
value) {}
static MessageResult<Void> acknowledge(MessageId messageId) {}
static MessageResult<Void> negativeAcknowledge(MessageId messageId) {}
static <V> MessageResult<Message<V>> acknowledgeAndReturn(Message<V>
message) {}
boolean isAcknowledgeMessage();
MessageId getMessageId();
T getValue();
}
public interface ReactiveMessageConsumer<T> {
<R> Flux<R> consumeMessages(
Function<Flux<Message<T>>, Flux<MessageResult<R>>>
messageHandler);
}
In-order parallel processing with Reactive Pulsar Adapter:
Implementation details
21
private static Integer resolveGroupKey(Message<?> message, int concurrency) {
byte[] keyBytes = null;
if (message.hasOrderingKey()) {
keyBytes = message.getOrderingKey();
} else if (message.hasKey()) {
keyBytes = message.getKeyBytes();
}
if (keyBytes == null || keyBytes.length == 0) {
// derive from the message id
keyBytes = message.getMessageId().toByteArray();
}
int keyHash = Murmur3_32Hash.getInstance().makeHash(keyBytes);
return keyHash % concurrency;
}
messageFlux
.groupBy(message -> resolveGroupKey(message, concurrency), Math.max(concurrency, 32))
.flatMap(
groupedFlux ->
groupedFlux
.publishOn(Schedulers.parallel())
.concatMap(message -> handleMessage(message)),
concurrency
);
actual implementation has been refactored:
https://github.com/lhotari/reactive-pulsar/blob/master/reactive-pulsar-adapter/src/main/java/com/github/lhotari/reactive/pulsar/internal/adapter/InKeyOrderMessageProcessors.java
References
22
Apache Pulsar: https://pulsar.apache.org/
Spring Reactive: https://spring.io/reactive
Reactive Pulsar adapter: https://github.com/lhotari/reactive-pulsar
Status: experimental version 0.0.7 available for use, API is subject to change until 1.0 is
released.
Reactive Pulsar showcase application: https://github.com/lhotari/reactive-pulsar-showcase
Status: work in progress, demonstrates the usage of the Reactive Pulsar Adapter.
For usage questions, please use apache-pulsar and reactive-pulsar tags on Stackoverflow.
Thank you !
23
We are hiring: https://www.datastax.com/company/careers

Más contenido relacionado

La actualidad más candente

hbaseconasia2017: HBase Practice At XiaoMi
hbaseconasia2017: HBase Practice At XiaoMihbaseconasia2017: HBase Practice At XiaoMi
hbaseconasia2017: HBase Practice At XiaoMiHBaseCon
 
Best practices and lessons learnt from Running Apache NiFi at Renault
Best practices and lessons learnt from Running Apache NiFi at RenaultBest practices and lessons learnt from Running Apache NiFi at Renault
Best practices and lessons learnt from Running Apache NiFi at RenaultDataWorks Summit
 
Serverless Kafka and Spark in a Multi-Cloud Lakehouse Architecture
Serverless Kafka and Spark in a Multi-Cloud Lakehouse ArchitectureServerless Kafka and Spark in a Multi-Cloud Lakehouse Architecture
Serverless Kafka and Spark in a Multi-Cloud Lakehouse ArchitectureKai Wähner
 
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)Jean-Paul Azar
 
Everything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterEverything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterAttila Szegedi
 
Cilium - BPF & XDP for containers
 Cilium - BPF & XDP for containers Cilium - BPF & XDP for containers
Cilium - BPF & XDP for containersDocker, Inc.
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningMichel Schildmeijer
 
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotExactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotFlink Forward
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootKashif Ali Siddiqui
 
Advanced Streaming Analytics with Apache Flink and Apache Kafka, Stephan Ewen
Advanced Streaming Analytics with Apache Flink and Apache Kafka, Stephan EwenAdvanced Streaming Analytics with Apache Flink and Apache Kafka, Stephan Ewen
Advanced Streaming Analytics with Apache Flink and Apache Kafka, Stephan Ewenconfluent
 
So You Want to Write a Connector?
So You Want to Write a Connector? So You Want to Write a Connector?
So You Want to Write a Connector? confluent
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaAraf Karsh Hamid
 
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, ConfluentTemporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, ConfluentHostedbyConfluent
 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllThomas Wuerthinger
 
Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...Claus Ibsen
 
Kafka 101 and Developer Best Practices
Kafka 101 and Developer Best PracticesKafka 101 and Developer Best Practices
Kafka 101 and Developer Best Practicesconfluent
 

La actualidad más candente (20)

hbaseconasia2017: HBase Practice At XiaoMi
hbaseconasia2017: HBase Practice At XiaoMihbaseconasia2017: HBase Practice At XiaoMi
hbaseconasia2017: HBase Practice At XiaoMi
 
Envoy and Kafka
Envoy and KafkaEnvoy and Kafka
Envoy and Kafka
 
Best practices and lessons learnt from Running Apache NiFi at Renault
Best practices and lessons learnt from Running Apache NiFi at RenaultBest practices and lessons learnt from Running Apache NiFi at Renault
Best practices and lessons learnt from Running Apache NiFi at Renault
 
Serverless Kafka and Spark in a Multi-Cloud Lakehouse Architecture
Serverless Kafka and Spark in a Multi-Cloud Lakehouse ArchitectureServerless Kafka and Spark in a Multi-Cloud Lakehouse Architecture
Serverless Kafka and Spark in a Multi-Cloud Lakehouse Architecture
 
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
 
Everything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterEverything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @Twitter
 
Cilium - BPF & XDP for containers
 Cilium - BPF & XDP for containers Cilium - BPF & XDP for containers
Cilium - BPF & XDP for containers
 
Apache Flink Deep Dive
Apache Flink Deep DiveApache Flink Deep Dive
Apache Flink Deep Dive
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuning
 
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotExactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring Boot
 
RabbitMQ & Kafka
RabbitMQ & KafkaRabbitMQ & Kafka
RabbitMQ & Kafka
 
Advanced Streaming Analytics with Apache Flink and Apache Kafka, Stephan Ewen
Advanced Streaming Analytics with Apache Flink and Apache Kafka, Stephan EwenAdvanced Streaming Analytics with Apache Flink and Apache Kafka, Stephan Ewen
Advanced Streaming Analytics with Apache Flink and Apache Kafka, Stephan Ewen
 
So You Want to Write a Connector?
So You Want to Write a Connector? So You Want to Write a Connector?
So You Want to Write a Connector?
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and Saga
 
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, ConfluentTemporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
 
Why Microservice
Why Microservice Why Microservice
Why Microservice
 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
 
Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...
 
Kafka 101 and Developer Best Practices
Kafka 101 and Developer Best PracticesKafka 101 and Developer Best Practices
Kafka 101 and Developer Best Practices
 

Similar a Reactive Applications with Apache Pulsar and Spring Boot

Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingAraf Karsh Hamid
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programmingAraf Karsh Hamid
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideMohanraj Thirumoorthy
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx javaCongTrung Vnit
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016Trayan Iliev
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaAli Muzaffar
 
The hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusThe hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusBol.com Techlab
 
The hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusThe hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusBol.com Techlab
 
Project Reactor Now and Tomorrow
Project Reactor Now and TomorrowProject Reactor Now and Tomorrow
Project Reactor Now and TomorrowVMware Tanzu
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Trayan Iliev
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionalsTrayan Iliev
 

Similar a Reactive Applications with Apache Pulsar and Spring Boot (20)

Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive Programming
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 
1844 1849
1844 18491844 1849
1844 1849
 
1844 1849
1844 18491844 1849
1844 1849
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
Map reduce prashant
Map reduce prashantMap reduce prashant
Map reduce prashant
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
KrakenD API Gateway
KrakenD API GatewayKrakenD API Gateway
KrakenD API Gateway
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
Java 8 streams
Java 8 streams Java 8 streams
Java 8 streams
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
The hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusThe hitchhiker’s guide to Prometheus
The hitchhiker’s guide to Prometheus
 
The hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusThe hitchhiker’s guide to Prometheus
The hitchhiker’s guide to Prometheus
 
Prometheus monitoring
Prometheus monitoringPrometheus monitoring
Prometheus monitoring
 
Project Reactor Now and Tomorrow
Project Reactor Now and TomorrowProject Reactor Now and Tomorrow
Project Reactor Now and Tomorrow
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018
 
Reactive Applications in Java
Reactive Applications in JavaReactive Applications in Java
Reactive Applications in Java
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionals
 

Más de VMware Tanzu

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItVMware Tanzu
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023VMware Tanzu
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleVMware Tanzu
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023VMware Tanzu
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductVMware Tanzu
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready AppsVMware Tanzu
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And BeyondVMware Tanzu
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfVMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023VMware Tanzu
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptxVMware Tanzu
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchVMware Tanzu
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishVMware Tanzu
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVMware Tanzu
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - FrenchVMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023VMware Tanzu
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootVMware Tanzu
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerVMware Tanzu
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeVMware Tanzu
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsVMware Tanzu
 

Más de VMware Tanzu (20)

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About It
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at Scale
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a Product
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
 

Último

Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 

Último (20)

Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 

Reactive Applications with Apache Pulsar and Spring Boot

  • 1. Reactive Applications with Apache Pulsar and Spring Boot Lari Hotari @lhotari Senior Software Engineer, DataStax, Inc Apache Pulsar committer Presentation at SpringOne 2021 September 2, 2021
  • 2. Who 2 Lari Hotari @lhotari Software Engineer @DataStax, working on Luna Streaming powered by Apache Pulsar Open-source contributor, Apache Pulsar committer Journey with Spring: ○ Spring Framework user since 0.9 (2003) ○ Early Spring Framework contributor (2007, WebSphere DataSource support for Spring Transaction Management) ○ Grails contributor (2009-2020) Member of Groovy and Grails team (part of the Spring team) at Pivotal (2014-2015) Grails team released Grails 3.0 built on Spring Boot in March 2015 ○ Spring Boot contributor (heapdump actuator) ○ Project Reactor contributor (dns reverse lookup optimization & few others in reactor-netty, 1 minor in reactor-core) 2004 2002 2005 2003
  • 3. 3 Pulsar & Reactive Messaging 01 Sample use case & Live coding 02 Scaling performance of message processing 03 Agenda
  • 4. 4 Pulsar & Reactive Messaging 01 Sample use case & Live coding 02 Scaling performance of message processing 03 Agenda
  • 5. Apache Pulsar - Favourite properties 5 Many options for scaling - not just about partitions 02 Streaming, pub-sub and queuing come together 01 Cloud Native Architecture Layered storage architecture Stateless Brokers First class support for Kubernetes 03
  • 6. Reactive Message handling - why? 6 Fault tolerance with fallbacks, retries and timeouts Compatibility with Reactive Streams to achieve reactive from end-to-end Performance by parallelism and pipelining in processing Resilience with flow control (backpressure) Efficiency by optimal resource usage Simplification by data orientation & functional approach
  • 7. Reactive Pulsar Adapter library ● https://github.com/lhotari/reactive-pulsar , License: ASL 2.0 ● Wraps the Apache Pulsar Java Client async API with a simple and intuitive reactive API ● Goes beyond a wrapper ● Back-pressure support for provided interfaces ● Pulsar client resource lifecycle management ● Message producer caching ● In-order parallel processing at the application level ● Spring Boot starter for auto configuring a Pulsar Java client and a ReactivePulsarClient 7
  • 8. Reactive Messaging Application building blocks provided by the Reactive Pulsar Adapter library 8 Message Sender Message Consumer Message Listener Container Message Reader ● Sender - for sending messages with a specific configuration to a specific destination topic. ● Consumer - for guaranteed message delivery and handling. The broker redelivers unacknowledged messages. Used for both “always on” use cases and batch processing or short-time message consuming or polling use cases. ● Reader - The application decides the position where to start reading messages. Position can be earliest, latest, or an absolute or time based position. Suitable also for short-time message polling. ● Message Listener Container - integrates a consumer with the Spring application lifecycle. *) The abstractions of the Reactive Pulsar Adapter library are slightly different from the abstractions in Pulsar Java Client. The sender is one example of a difference. The lifecycles of the abstractions are completely different. The ReactiveMessageSender, ReactiveMessageReader and ReactiveMessageConsumer instances themselves are stateless. “Nothing happens until you subscribe” - the key difference in the Reactive programming model.
  • 9. Basics of Reactive APIs 9 - “Nothing happens until you subscribe” - Assembly-time vs Runtime - API calls return a reactive publisher type - Flux<T> or Mono<T> when using Project Reactor - Mono<Void> for calls that don’t return data
  • 10. Reactive Pulsar Adapter public interface ReactivePulsarClient { <T> ReactiveMessageSenderBuilder<T> messageSender(Schema<T> schema); <T> ReactiveMessageReaderBuilder<T> messageReader(Schema<T> schema); <T> ReactiveMessageConsumerBuilder<T> messageConsumer(Schema<T> schema); } 10 public interface ReactiveMessageReader<T> { Mono<Message<T>> readMessage(); Flux<Message<T>> readMessages(); } public interface ReactiveMessageSender<T> { Mono<MessageId> sendMessage(Mono<MessageSpec<T>> messageSpec); Flux<MessageId> sendMessages(Flux<MessageSpec<T>> messageSpecs); } public interface ReactiveMessageConsumer<T> { <R> Mono<R> consumeMessage( Function<Mono<Message<T>>, Mono<MessageResult<R>>> messageHandler); <R> Flux<R> consumeMessages( Function<Flux<Message<T>>, Flux<MessageResult<R>>> messageHandler); }
  • 11. Sample use cases - simplified IoT backend 11 Telemetry ingestion from IoT devices Telemetry processing Streaming of telemetry values to other applications Sending alerts to external application - webhook interface https://github.com/lhotari/reactive-pulsar-showcase for complete sample (work in progress)
  • 12. 12 Pulsar & Reactive Messaging 01 Sample use case & Live coding 02 Scaling performance of message processing 03 Agenda
  • 13. Our goal for live coding 13
  • 14. 14 Pulsar & Reactive Messaging 01 Sample use case & Live coding 02 Scaling performance of message processing 03 Agenda
  • 15. All significant improvements in system scalability come from parallelism. 15
  • 16. Pipelining 16 “This idea is an extension of the idea of parallelism. It is essentially handling the activities involved in instruction execution as an assembly line. As soon as the first activity of an instruction is done you move it to the second activity and start the first activity of a new instruction. This results in executing more instructions per unit time compared to waiting for all activities of the first instruction to complete before starting the second instruction.” https://www.d.umn.edu/~gshute/arch/great-ideas.html
  • 17. Parallel Pipelining with Project Reactor: Without ordering requirements 17 ● When there are no ordering requirements, parallelism/concurrency can be achieved in two ways: Using .parallel operator (parallelism, for computations) Flux .range(1, 10) .parallel(10) .runOn(Schedulers.parallel()) .concatMap(i -> { // CPU bound … // that returns a publisher } ) .sequential() .subscribe() Using .flatMap + .subscribeOn for inner publisher (concurrency, for I/O tasks) Flux .range(1, 10) .flatMap( i -> { // IO bound … // that returns a publisher }.subscribeOn(Schedulers.parallel()), 10 ) .subscribe()
  • 18. In-order parallel processing strategies ● System level: Multiple topic partitions ● Message is mapped to a specific partition by hashing the key partition = hash(message key) % number_of_partitions ● Application level: Message consumer parallelism ● Micro-batching ● Messages are consumed in batches which is limited by time and number of entries. ● The processing can sort and group the entries for parallel processing. ● Stream splitting / routing / grouping ● Message is mapped to a specific processing group based on the hash of the message key processing group = hash(message key) % number_of_processing_groups ● This is well suited for splitting the stream with Project Reactor’s .groupBy ● Benefit over micro-batching: no extra latency caused by batching 18
  • 19. Parallel Pipelining with Project Reactor: In-order processing requirements 19 When there is a requirement of in-order processing by key: ● .groupBy operator splits the stream by a key. The total number of keys should be limited and relatively small (hundreds). ● The concurrency level parameter for flatMap should be set to the total number of groups to prevent the stream processing from stalling (explained in Flux.groupBy javadoc). In addition, the “prefetch” parameter of .groupBy should be set to a value >= total number of groups. Flux .range(1, 10) // simulation of key: 0 (even) or 1 (odd) .groupBy(i -> i % 2, Math.max(10, 32)) .flatMap( groupedFlux -> groupedFlux .publishOn(Schedulers.parallel()) .concatMap(x -> { // IO bound … // that returns a publisher }) 10, 1 ) .subscribe()
  • 20. Parallel processing with ReactiveMessageConsumer 20 ● An enabler is the the special signature of the consumeMessages method on the ReactiveMessageConsumer interface. ● The method accepts a function that takes Flux<Message<T>> input and produces Flux<MessageResult<R>>> output. ● MessageResult combines acknowledgement and the result. The implementation consumes the Flux<MessageResult<R>>> , handles the acknowledgements, and returns a Flux<R> . ● This enables guaranteed message delivery combined with stream transformations. public interface MessageResult<T> { static <T> MessageResult<T> acknowledge(MessageId messageId, T value) {} static <T> MessageResult<T> negativeAcknowledge(MessageId messageId, T value) {} static MessageResult<Void> acknowledge(MessageId messageId) {} static MessageResult<Void> negativeAcknowledge(MessageId messageId) {} static <V> MessageResult<Message<V>> acknowledgeAndReturn(Message<V> message) {} boolean isAcknowledgeMessage(); MessageId getMessageId(); T getValue(); } public interface ReactiveMessageConsumer<T> { <R> Flux<R> consumeMessages( Function<Flux<Message<T>>, Flux<MessageResult<R>>> messageHandler); }
  • 21. In-order parallel processing with Reactive Pulsar Adapter: Implementation details 21 private static Integer resolveGroupKey(Message<?> message, int concurrency) { byte[] keyBytes = null; if (message.hasOrderingKey()) { keyBytes = message.getOrderingKey(); } else if (message.hasKey()) { keyBytes = message.getKeyBytes(); } if (keyBytes == null || keyBytes.length == 0) { // derive from the message id keyBytes = message.getMessageId().toByteArray(); } int keyHash = Murmur3_32Hash.getInstance().makeHash(keyBytes); return keyHash % concurrency; } messageFlux .groupBy(message -> resolveGroupKey(message, concurrency), Math.max(concurrency, 32)) .flatMap( groupedFlux -> groupedFlux .publishOn(Schedulers.parallel()) .concatMap(message -> handleMessage(message)), concurrency ); actual implementation has been refactored: https://github.com/lhotari/reactive-pulsar/blob/master/reactive-pulsar-adapter/src/main/java/com/github/lhotari/reactive/pulsar/internal/adapter/InKeyOrderMessageProcessors.java
  • 22. References 22 Apache Pulsar: https://pulsar.apache.org/ Spring Reactive: https://spring.io/reactive Reactive Pulsar adapter: https://github.com/lhotari/reactive-pulsar Status: experimental version 0.0.7 available for use, API is subject to change until 1.0 is released. Reactive Pulsar showcase application: https://github.com/lhotari/reactive-pulsar-showcase Status: work in progress, demonstrates the usage of the Reactive Pulsar Adapter. For usage questions, please use apache-pulsar and reactive-pulsar tags on Stackoverflow.
  • 23. Thank you ! 23 We are hiring: https://www.datastax.com/company/careers