SlideShare a Scribd company logo
1 of 28
Orchestration DSL
Agenda One-minute Intro to squbs
The Orchestration Use Case
Describing Orchestration in a DSL
Errors & Timeouts
Integrations
https://github.com/paypal/squbs
Standardization for Large number
of Heterogeneous Services
Hooks for Logging &
Operationalization
Programming Patterns
Internet Scale Akka
Orchestration Use-Cases
Orchestrator
Worker
Worker
Worker
Service
Service
Service
Request/Response Message
Orchestration Use-Cases
• Blocking threads while waiting for
tasks
• Highly inefficient use of resources
• Prone to downstream failures and
connection stacking
Synchronous Systems
• Message-oriented
• Never blocking
• Optimal parallelism – with Akka
Asynchronous Systems
Common pattern coordinating workers & services
Synchronous Dispatch Model
Request Thread Pool
AcceptorThread
select
n concurrent requests
n concurrent threads
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Service Calls
Request Thread Pool
Blocked
Service
Client
AcceptorThread
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Blocked
Service
Client
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Blocked
Service
Client
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Blocked
Service
Client
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Service Orchestration
Request Thread Pool
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Request Thread Pool9
Blocked
Orchestrat
e
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Blocked
Orchestrat
e
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Blocked
Orchestrat
e
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Blocked
Orchestrat
e
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Orchestration Thread Pool
Blocked
Service
Client
Task
Blocked
Service
Client
Task
Blocked
Service
Client
Task
Blocked
Service
Client
Task
Problem
Summary
Synchronous, thread-holding
Threads blocked from useful
processing
Need for orchestrator to make parallel
service calls
Even more orchestration threads
Heavy resource usage & context switch
Akka Async, message passing middleware
Actors hold state but not threads
Low thread count, low context switch
Resilience & Supervision
Akka Actor Scheduling
12
Dispatcher
Low number of threads (1-2 per CPU)
Actor
Message Received
Run to completion
Multiple messages per dispatch
Actor Scheduled on Thread
Scheduling Actor ≠ Scheduling “task”
Asynchronous Orchestration Model
• Tasks represented by actors and/or services
• Tasks dependent on each others by results of previous task
• Each task can run independent of each other
• Tasks can run as early as the input to these tasks are available
• Tasks may or may not run parallel to other tasks, resource dependent
Before We Start
• Make sure you have the right dependency in your build.sbt
libraryDependencies += "org.squbs" %% "squbs-pattern" % "0.8.0"
Setting up the Orchestrator
class MyTaskOrchestrator(task1Actor: ActorRef, task2Actor: ActorRef,
task3Actor: ActorRef, task4Actor: ActorRef,
task5Actor: ActorRef)
extends Actor with Orchestrator {
expectOnce {
case input: Input => orchestrate(input, sender())
}
def orchestrate(input: Input, requester: ActorRef): Unit = {
// Goodies go here…
}
}
Input Dependencies
task1
task2
task3
task4
task5
Input
Output
val task1F = doTask1(input)
val task2F = doTask2(input)
val task3F = (task1F, task2F) >> doTask3
val task4F = task2F >> doTask4
val task5F = (task3F, task4F) >> doTask5
for { result <- task5F } {
requester ! result
context.stop(self)
}
Describing the Orchestration in an Actor
task1
task2
task3
task4
task5
Input
Output
Orchestrator Characteristics
• Single-use actor, terminates after ONE orchestration
• Keeps orchestration state in Actor as OFuture
• OFuture: Same API as Future, no ExecutionContext
• Runs callbacks on actor message handling thread
• Similar to Java 8 CompletableFuture synchronous API
• Spares users and actors from potential concurrent close-overs
• Future implicitly converts to OFuture in Orchestrator Actor
• Resolves final result from one or more OFutures using for-
comprehensions and sends back to requester
Orchestration Functions
• (in1: T, in2: U, … inN: W) => OFuture[X]
• Mentioned as doTask1, doTask2, etc. in the example
• Usually calls other actors
• May use ask to ask another actor
• Or better performance – tell and receive value with expectOnce
Orchestration Function Examples
def doTask1(input: Input): OFuture[Task1Output] = {
implicit val timeout = Timeout(5 seconds)
(task1Actor ? input).mapTo[Task1Output]
}
def doTask3(input1: Task1Output, input2: Task2Output):
OFuture[Task3Output] = {
val promise = OPromise[Task3Output]
task3Actor ! Task3Input(input1.s, input2.s)
expectOnce {
case o: Task3Output => promise.success(o)
case e: Task3Exception => promise.failure(e)
}
promise.future
}
Be Responsive, Do Timeout
…
val task4F = task2F >> doTask4
val task5F = (task3F, task4F) >> doTask5
for { result <- task5F } {
requester ! result
context.stop(self)
}
import context.dispatcher
context.system.scheduler.scheduleOnce(100 millis, self, Timeout)
expectOnce {
case Timeout =>
requester ! Timeout
context.stop(self)
}
And Handle Your Errors
…
expectOnce {
case Timeout =>
requester ! Timeout
context.stop(self)
}
task2F onFailure {
case e: Task2Exception =>
requester ! e
context.stop(self)
}
More Error Handling…
// Combining Futures
val myFailF =
for {
t1 <- task1F
e2 <- task4F.failed
} yield CombinedException(t1.s + e2.getMessage)
// Recovering Futures
val task3RecoveredF = task3SuccessF.recover {
case e: Task3Exception => Task3Output("It's OK")
}
Orchestration
Summary
High-performance asynchronous
orchestration
Responsive: Respond within SLA,
with or without results
Streamlined error handling
Reduced code complexity
Integrations/Usa
ge
Spray/Akka HTTP:
onComplete + ask
Akka Streams:
mapAsync + ask
Any actor:
ask or tell
As a sub-Orchestrator
when Orchestrator gets complex
Bootstrap & lifecycle control
for http, actors, and streams
Extension model for hooking into
operationalization
Data center aware clustering
Actor registry
Monitoring & console
Many more patterns
What’s more about it?
Q&A – Feedback Appreciated
Asynchronous Orchestration DSL on squbs

More Related Content

What's hot

Modernizing Infrastructures for Fast Data with Spark, Kafka, Cassandra, React...
Modernizing Infrastructures for Fast Data with Spark, Kafka, Cassandra, React...Modernizing Infrastructures for Fast Data with Spark, Kafka, Cassandra, React...
Modernizing Infrastructures for Fast Data with Spark, Kafka, Cassandra, React...Lightbend
 
Real-time streaming and data pipelines with Apache Kafka
Real-time streaming and data pipelines with Apache KafkaReal-time streaming and data pipelines with Apache Kafka
Real-time streaming and data pipelines with Apache KafkaJoe Stein
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsKonrad Malawski
 
Scaling Twitter with Cassandra
Scaling Twitter with CassandraScaling Twitter with Cassandra
Scaling Twitter with CassandraRyan King
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsKevin Webber
 
Spark stream - Kafka
Spark stream - Kafka Spark stream - Kafka
Spark stream - Kafka Dori Waldman
 
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Lightbend
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
Akka streams scala italy2015
Akka streams scala italy2015Akka streams scala italy2015
Akka streams scala italy2015mircodotta
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioGioia Ballin
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Konrad Malawski
 
Stream Processing using Apache Spark and Apache Kafka
Stream Processing using Apache Spark and Apache KafkaStream Processing using Apache Spark and Apache Kafka
Stream Processing using Apache Spark and Apache KafkaAbhinav Singh
 
Developing a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayDeveloping a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayJacob Park
 
Meet Up - Spark Stream Processing + Kafka
Meet Up - Spark Stream Processing + KafkaMeet Up - Spark Stream Processing + Kafka
Meet Up - Spark Stream Processing + KafkaKnoldus Inc.
 
Building Stateful Microservices With Akka
Building Stateful Microservices With AkkaBuilding Stateful Microservices With Akka
Building Stateful Microservices With AkkaYaroslav Tkachenko
 
Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...
Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...
Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...Databricks
 
Spark Streaming Recipes and "Exactly Once" Semantics Revised
Spark Streaming Recipes and "Exactly Once" Semantics RevisedSpark Streaming Recipes and "Exactly Once" Semantics Revised
Spark Streaming Recipes and "Exactly Once" Semantics RevisedMichael Spector
 
To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...
To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...
To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...Uri Cohen
 
Native container monitoring
Native container monitoringNative container monitoring
Native container monitoringRohit Jnagal
 

What's hot (20)

Modernizing Infrastructures for Fast Data with Spark, Kafka, Cassandra, React...
Modernizing Infrastructures for Fast Data with Spark, Kafka, Cassandra, React...Modernizing Infrastructures for Fast Data with Spark, Kafka, Cassandra, React...
Modernizing Infrastructures for Fast Data with Spark, Kafka, Cassandra, React...
 
Real-time streaming and data pipelines with Apache Kafka
Real-time streaming and data pipelines with Apache KafkaReal-time streaming and data pipelines with Apache Kafka
Real-time streaming and data pipelines with Apache Kafka
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
 
Scaling Twitter with Cassandra
Scaling Twitter with CassandraScaling Twitter with Cassandra
Scaling Twitter with Cassandra
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka Streams
 
Akka streams
Akka streamsAkka streams
Akka streams
 
Spark stream - Kafka
Spark stream - Kafka Spark stream - Kafka
Spark stream - Kafka
 
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Akka streams scala italy2015
Akka streams scala italy2015Akka streams scala italy2015
Akka streams scala italy2015
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenario
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
 
Stream Processing using Apache Spark and Apache Kafka
Stream Processing using Apache Spark and Apache KafkaStream Processing using Apache Spark and Apache Kafka
Stream Processing using Apache Spark and Apache Kafka
 
Developing a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayDeveloping a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and Spray
 
Meet Up - Spark Stream Processing + Kafka
Meet Up - Spark Stream Processing + KafkaMeet Up - Spark Stream Processing + Kafka
Meet Up - Spark Stream Processing + Kafka
 
Building Stateful Microservices With Akka
Building Stateful Microservices With AkkaBuilding Stateful Microservices With Akka
Building Stateful Microservices With Akka
 
Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...
Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...
Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...
 
Spark Streaming Recipes and "Exactly Once" Semantics Revised
Spark Streaming Recipes and "Exactly Once" Semantics RevisedSpark Streaming Recipes and "Exactly Once" Semantics Revised
Spark Streaming Recipes and "Exactly Once" Semantics Revised
 
To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...
To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...
To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...
 
Native container monitoring
Native container monitoringNative container monitoring
Native container monitoring
 

Similar to Asynchronous Orchestration DSL on squbs

Advanced patterns in asynchronous programming
Advanced patterns in asynchronous programmingAdvanced patterns in asynchronous programming
Advanced patterns in asynchronous programmingMichael Arenzon
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
Async and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLAsync and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLArie Leeuwesteijn
 
Activator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupActivator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupHenrik Engström
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaYardena Meymann
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Masahiro Nagano
 
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupThe dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupkrivachy
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: ServersidenessWebExpo
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleSharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleGeoff Ballinger
 
Julio Capote, Twitter
Julio Capote, TwitterJulio Capote, Twitter
Julio Capote, TwitterOntico
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterKonstantin Tsykulenko
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/MultitaskingSasha Kravchuk
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Jalpesh Vadgama
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)tarcieri
 
Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2JollyRogers5
 
Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Dhaval Dalal
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Paco de la Cruz
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3JavaEE Trainers
 

Similar to Asynchronous Orchestration DSL on squbs (20)

Advanced patterns in asynchronous programming
Advanced patterns in asynchronous programmingAdvanced patterns in asynchronous programming
Advanced patterns in asynchronous programming
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Async and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLAsync and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NL
 
Activator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupActivator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetup
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & Akka
 
Solr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene EuroconSolr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene Eurocon
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupThe dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetup
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: Serversideness
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleSharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's Finagle
 
Julio Capote, Twitter
Julio Capote, TwitterJulio Capote, Twitter
Julio Capote, Twitter
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka Cluster
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/Multitasking
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)
 
Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2
 
Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3
 

Recently uploaded

WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfryanfarris8
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2
 

Recently uploaded (20)

WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 

Asynchronous Orchestration DSL on squbs

  • 2. Agenda One-minute Intro to squbs The Orchestration Use Case Describing Orchestration in a DSL Errors & Timeouts Integrations
  • 3. https://github.com/paypal/squbs Standardization for Large number of Heterogeneous Services Hooks for Logging & Operationalization Programming Patterns Internet Scale Akka
  • 5. Orchestration Use-Cases • Blocking threads while waiting for tasks • Highly inefficient use of resources • Prone to downstream failures and connection stacking Synchronous Systems • Message-oriented • Never blocking • Optimal parallelism – with Akka Asynchronous Systems Common pattern coordinating workers & services
  • 6. Synchronous Dispatch Model Request Thread Pool AcceptorThread select n concurrent requests n concurrent threads Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves
  • 7. Service Calls Request Thread Pool Blocked Service Client AcceptorThread Worker Logic JAX-RS Resource Servlet Catalina/ Valves Blocked Service Client Worker Logic JAX-RS Resource Servlet Catalina/ Valves Blocked Service Client Worker Logic JAX-RS Resource Servlet Catalina/ Valves Blocked Service Client Worker Logic JAX-RS Resource Servlet Catalina/ Valves
  • 8. Service Orchestration Request Thread Pool Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves
  • 10. Problem Summary Synchronous, thread-holding Threads blocked from useful processing Need for orchestrator to make parallel service calls Even more orchestration threads Heavy resource usage & context switch
  • 11. Akka Async, message passing middleware Actors hold state but not threads Low thread count, low context switch Resilience & Supervision
  • 12. Akka Actor Scheduling 12 Dispatcher Low number of threads (1-2 per CPU) Actor Message Received Run to completion Multiple messages per dispatch Actor Scheduled on Thread Scheduling Actor ≠ Scheduling “task”
  • 13. Asynchronous Orchestration Model • Tasks represented by actors and/or services • Tasks dependent on each others by results of previous task • Each task can run independent of each other • Tasks can run as early as the input to these tasks are available • Tasks may or may not run parallel to other tasks, resource dependent
  • 14. Before We Start • Make sure you have the right dependency in your build.sbt libraryDependencies += "org.squbs" %% "squbs-pattern" % "0.8.0"
  • 15. Setting up the Orchestrator class MyTaskOrchestrator(task1Actor: ActorRef, task2Actor: ActorRef, task3Actor: ActorRef, task4Actor: ActorRef, task5Actor: ActorRef) extends Actor with Orchestrator { expectOnce { case input: Input => orchestrate(input, sender()) } def orchestrate(input: Input, requester: ActorRef): Unit = { // Goodies go here… } }
  • 17. val task1F = doTask1(input) val task2F = doTask2(input) val task3F = (task1F, task2F) >> doTask3 val task4F = task2F >> doTask4 val task5F = (task3F, task4F) >> doTask5 for { result <- task5F } { requester ! result context.stop(self) } Describing the Orchestration in an Actor task1 task2 task3 task4 task5 Input Output
  • 18. Orchestrator Characteristics • Single-use actor, terminates after ONE orchestration • Keeps orchestration state in Actor as OFuture • OFuture: Same API as Future, no ExecutionContext • Runs callbacks on actor message handling thread • Similar to Java 8 CompletableFuture synchronous API • Spares users and actors from potential concurrent close-overs • Future implicitly converts to OFuture in Orchestrator Actor • Resolves final result from one or more OFutures using for- comprehensions and sends back to requester
  • 19. Orchestration Functions • (in1: T, in2: U, … inN: W) => OFuture[X] • Mentioned as doTask1, doTask2, etc. in the example • Usually calls other actors • May use ask to ask another actor • Or better performance – tell and receive value with expectOnce
  • 20. Orchestration Function Examples def doTask1(input: Input): OFuture[Task1Output] = { implicit val timeout = Timeout(5 seconds) (task1Actor ? input).mapTo[Task1Output] } def doTask3(input1: Task1Output, input2: Task2Output): OFuture[Task3Output] = { val promise = OPromise[Task3Output] task3Actor ! Task3Input(input1.s, input2.s) expectOnce { case o: Task3Output => promise.success(o) case e: Task3Exception => promise.failure(e) } promise.future }
  • 21. Be Responsive, Do Timeout … val task4F = task2F >> doTask4 val task5F = (task3F, task4F) >> doTask5 for { result <- task5F } { requester ! result context.stop(self) } import context.dispatcher context.system.scheduler.scheduleOnce(100 millis, self, Timeout) expectOnce { case Timeout => requester ! Timeout context.stop(self) }
  • 22. And Handle Your Errors … expectOnce { case Timeout => requester ! Timeout context.stop(self) } task2F onFailure { case e: Task2Exception => requester ! e context.stop(self) }
  • 23. More Error Handling… // Combining Futures val myFailF = for { t1 <- task1F e2 <- task4F.failed } yield CombinedException(t1.s + e2.getMessage) // Recovering Futures val task3RecoveredF = task3SuccessF.recover { case e: Task3Exception => Task3Output("It's OK") }
  • 24. Orchestration Summary High-performance asynchronous orchestration Responsive: Respond within SLA, with or without results Streamlined error handling Reduced code complexity
  • 25. Integrations/Usa ge Spray/Akka HTTP: onComplete + ask Akka Streams: mapAsync + ask Any actor: ask or tell As a sub-Orchestrator when Orchestrator gets complex
  • 26. Bootstrap & lifecycle control for http, actors, and streams Extension model for hooking into operationalization Data center aware clustering Actor registry Monitoring & console Many more patterns What’s more about it?
  • 27. Q&A – Feedback Appreciated