SlideShare a Scribd company logo
1 of 50
Download to read offline
© 2017 Autodesk
John Scattergood
Senior Principal Engineer
JavaOne 2017
Reactive Microservices
with JRuby and Docker
§ Engineer at Autodesk
§ Enjoy coding in Java, Ruby,
Groovy and JavaScript
§ Run JRuby apps in production
that serve millions of requests/day
§ First time JavaOne Speaker
@johnscattergood
About Me
Reactive Systems
Our System
Market Updates
Stock Updates
Alerts/Rules
Notifications
SMS
DB Autoscaler
Cluster
Scale
§ Price Alerts (eCommerce)
§ APM and Infrastructure Monitoring (IT)
§ Fraud Detection (Credit)
§ Devices, Transponders, etc. (IOT)
Other Domains
Tools
§ Dynamic
§ Object-oriented w/ first class functions
§ Expressive
§ Flexible
§ Easy to learn
Ruby
Ruby is simple in appearance, but is very complex inside just like our human body
- Yukihiro “Matz” Matsumoto
Ruby Creator
@memo = { 1 => 1, 2 => 2 }
def fib(n)
@memo[n] ||= fib(n - 1) + fib(n - 2)
end
fib(100)
=> 573147844013817084101
Fibonnaci
§ Fully compatible implementation of Ruby
§ Includes benefits of JVM
§ High Performance
§ True multi-threading
§ Java libraries and interoperability
§ Standard monitoring tools
JRuby
require 'java'
java_import 'java.util.concurrent.ConcurrentHashMap'
map = ConcurrentHashMap.new
map['A'] = 123
map.put_if_absent('B', 456)
puts map
=> {"A"=>123, "B"=>456}
Java to Ruby
§ Asynchronous HTTP via Netty
§ Reactive Streams Support
§ Promises and Streams library
§ Works great with JRuby
§ Plugin Modules
§ Guice
§ Dropwizard Metrics
§ Etc.
Ratpack
RatpackServer.start do |server|
server.handlers do |chain|
chain.get do |ctx|
ctx.render(’Hello World!')
end
end
end
Starting a Server
§ Push-Pull based “stream” processing:
§ Non-blocking
§ Asynchronous
§ Potentially Unbounded
§ Non-blocking backpressure
§ JDK 9: java.util.concurrent.Flow
Reactive Streams
Promise
.value(@metric_registry)
.map(MetricRegistryJsonMapper.new(@alloc, MetricFilter::ALL))
.map { |buf| buf.to_string(Charset.default_charset) }
.map { |string| JSON.parse(string) }
.flat_map { |metric| send_event(metric) }
.then { |resp| Common::Log.debug "#{resp.status.code}" }
Example
§ Cluster management with Docker Engine
§ Task Scheduling and Scaling
§ Service Discovery
§ Load Balancing
§ Automatic Restart/Recovery
§ Rolling updates
Docker Swarm Mode
§ Cluster service that offers a REST API for scaling up and
down tasks
§ Automatically detects managed services in swarm
§ Supports
§ Preset scale increments/decrements
§ Cooldowns to avoid mistakes
Orbiter
Making a reactive system
Making a reactive system
Making a reactive system
Making a reactive system
Making a reactive system
Our System
HTTP POST
Market Updates
Stock Updates
Alerts/Rules
Notifications
SMS
DB Autoscaler
Cluster
Orbiter
HTTP POST
REST = Synchronous
Synchronous ≠ Reactive
How is this reactive?
§ Message Passing via HTTP POST
§ Service should limit blocking as much as possible
§ Return a Receipt for long processes
§ Communicate Backpressure via Status Codes (429)
§ Client decides how to handle messages if service is
unavailable
§ Buffering
§ Dropping
Reactive REST
§ HTTP is really nice because…
§ DNS and/or Service Discovery
§ Load Balancing
§ Transparent Scaling
§ Dynamic Routing and Proxies
Nothing wrong with Queues, but…
Challenge: Handling Uneven Load
§ Backpressure
§ Make the caller wait
§ Buffering
§ Accept the requests and send batches downstream
§ Caching
§ Accept the requests and send most recent downstream
Strategies
chain.post(stock') do |ctx|
http_client = ctx.get(HttpClient.java_class)
alert_service_client =
AlertServiceClient.new(ENV[’SA_ALERT_SERVICE_URL'],
http_client)
ctx.request.body
.map { |b| JSON.parse(b.text) }
.flat_map { |event| alert_service_client.send_event(event) }
.then { ctx.render('OK') }
end
Backpressure
Backpressure Demo
Buffering
chain.post(’stock') do |ctx|
buffer = ctx.get(EventBuffer.java_class)
ctx.request.body
.map { |b| JSON.parse(b.text) }
.flat_map { |event| buffer.add(event) }
.then do |buffered|
if buffered
ctx.render('OK')
else
Common::Log.debug 'backpressure!!!'
ctx.response.status(429).send
end
end
end
def add(event)
Promise.async do |d|
d.success(@buffer.offer(event, 1, TimeUnit::SECONDS))
end
end
def run
Execution.fork.start do |_|
get_events
.map { |events| reduce_events(events) }
.flat_map { |events| send_events(events) }
.defer(Duration.of_seconds(@backoff_duration))
.then do |responses|
responses.each { |response| handle_response(response) }
end
end
end
Buffering (contd)
Buffer Demo
Caching
chain.post(’stock') do |ctx|
cache = ctx.get(EventCache.java_class)
ctx.request.body
.map { |b| JSON.parse(b.text) }
.flat_map { |event| cache.add(event) }
.then do |cached|
if cached
ctx.render('OK')
else
Common::Log.debug 'backpressure!!!'
ctx.response.status(429).send
end
end
end
def add(event)
Promise.async do |d|
@cache.put(event['ticker'], event['price'])
@updates.put(event['ticker'], true)
d.success(true)
end
end
def run
Execution.fork.start do |_|
start = Time.now
get_events
.map { |keys| hydrate_events(keys) }
.flat_map { |events| send_events(events) }
.defer(Duration.of_seconds(@backoff_duration))
.then do |responses|
responses.each { |response| handle_response(response) }
end
end
end
Caching (contd)
Cache Demo
def backpressure(backoff)
if backoff
@metric_registry.meter('backpressure.service.alert').mark
@backoff_duration = [30, 1 + @backoff_duration * 2].min
puts "increasing back off to #{@backoff_duration} secs"
else
@backoff_duration = [@backoff_duration / 2, 1].max
if @backoff_duration > 1
puts "decreasing back off to #{@backoff_duration} secs"
else
@backoff_duration = 0
end
end
end
Backpressure
Cluster
Machine Machine Machine
Swarm Manager
orbiter
stock alert alertalert notif notif
scale db
Cluster
Machine Machine Machine
Swarm Manager
orbiter
stock alert alertalert notif notif
scale
Ingress traffic
Routed to Service
db
Cluster
Machine Machine Machine
Swarm Manager
orbiter
stock alert alertalert notif notif
scale
Ingress traffic
Routed to Service
db
Cluster
Machine Machine Machine
Swarm Manager
orbiter
stock
alert alertalert notif notif
scale
alert
Ingress traffic
Routed to Service
db
Monitoring Our Services
Scaling
def adjust_scale(metric_name, metric_value)
service = metric_name.split('.').last
Promise
.value(metric_value)
.next_op_if(
->(v) { v['m1_rate'] < 0.01 && v['m5_rate'] < 0.01 },
->(_) { scale_down(service) }
)
.next_op_if(
->(v) { v['m1_rate'] > 1 },
->(_) { scale_up(service) }
)
end
Scaling Up and Down
alert:
image: stockalert
command: bundle exec jruby ./alert_service/run.rb
networks:
- stockalert
deploy:
mode: replicated
replicas: 1
labels: [orbiter=true,orbiter.up=2,orbiter.cooldown=300]
…
Docker Scaling Configuration
Watch it in Action!
Scaling Up
Monitoring Effects of Scaling
Watch it in Action!
Scaling Down
Demo
HTTP POST
Market Updates
Stock Updates
Alerts/Rules
Notifications
SMS
DB Autoscaler
Cluster
Orbiter
HTTP POST
§ Joe Kutner, Deploying JRuby 9k
§ Joe Kutner, “Reactive Ruby: Building Real-time Apps with
JRuby and Ratpack”, http://blog.heroku.com
§ Dan Woods, Learning Ratpack
§ Jonas Bonér, Reactive Microservices Architecture
§ GitHub Project:
https://github.com/jscattergood/JavaOne_2017_CON3214
Further Reading
Autodesk and the Autodesk logo are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders.
Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document.
© 2017 Autodesk. All rights reserved.

More Related Content

What's hot

Fighting Spam With A Perimeter Mail System 20071108 Sasag
Fighting Spam With A Perimeter Mail System 20071108 SasagFighting Spam With A Perimeter Mail System 20071108 Sasag
Fighting Spam With A Perimeter Mail System 20071108 Sasaggarrett honeycutt
 
초보자를 위한 분산 캐시 이야기
초보자를 위한 분산 캐시 이야기초보자를 위한 분산 캐시 이야기
초보자를 위한 분산 캐시 이야기OnGameServer
 
A Comprehensive Guide for DNS Cluster Configurations
A Comprehensive Guide for DNS Cluster ConfigurationsA Comprehensive Guide for DNS Cluster Configurations
A Comprehensive Guide for DNS Cluster ConfigurationsHTS Hosting
 
Beyond Best Practice: Grid Computing in the Modern World
Beyond Best Practice: Grid Computing in the Modern World Beyond Best Practice: Grid Computing in the Modern World
Beyond Best Practice: Grid Computing in the Modern World ThotWave
 
Production MongoDB in the Cloud
Production MongoDB in the CloudProduction MongoDB in the Cloud
Production MongoDB in the Cloudbridgetkromhout
 
Feed Burner Scalability
Feed Burner ScalabilityFeed Burner Scalability
Feed Burner Scalabilitydidip
 
Resilient design 101 (BuildStuff LT 2017)
Resilient design 101 (BuildStuff LT 2017)Resilient design 101 (BuildStuff LT 2017)
Resilient design 101 (BuildStuff LT 2017)Avishai Ish-Shalom
 
Resilient Design 101 (JeeConf 2017)
Resilient Design 101 (JeeConf 2017)Resilient Design 101 (JeeConf 2017)
Resilient Design 101 (JeeConf 2017)Avishai Ish-Shalom
 
Continuent webinar 02-19-2015
Continuent webinar 02-19-2015Continuent webinar 02-19-2015
Continuent webinar 02-19-2015Continuent
 
GC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconGC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconPeter Lawrey
 
Low latency for high throughput
Low latency for high throughputLow latency for high throughput
Low latency for high throughputPeter Lawrey
 
Low level java programming
Low level java programmingLow level java programming
Low level java programmingPeter Lawrey
 
Troubleshooting Apache Cloudstack
Troubleshooting Apache CloudstackTroubleshooting Apache Cloudstack
Troubleshooting Apache CloudstackRadhika Puthiyetath
 
Automating the Entire PostgreSQL Lifecycle
Automating the Entire PostgreSQL Lifecycle Automating the Entire PostgreSQL Lifecycle
Automating the Entire PostgreSQL Lifecycle anynines GmbH
 

What's hot (20)

Fail over fail_back
Fail over fail_backFail over fail_back
Fail over fail_back
 
Scaling the Rails
Scaling the RailsScaling the Rails
Scaling the Rails
 
Fighting Spam With A Perimeter Mail System 20071108 Sasag
Fighting Spam With A Perimeter Mail System 20071108 SasagFighting Spam With A Perimeter Mail System 20071108 Sasag
Fighting Spam With A Perimeter Mail System 20071108 Sasag
 
초보자를 위한 분산 캐시 이야기
초보자를 위한 분산 캐시 이야기초보자를 위한 분산 캐시 이야기
초보자를 위한 분산 캐시 이야기
 
92 grand prix_2013
92 grand prix_201392 grand prix_2013
92 grand prix_2013
 
A Comprehensive Guide for DNS Cluster Configurations
A Comprehensive Guide for DNS Cluster ConfigurationsA Comprehensive Guide for DNS Cluster Configurations
A Comprehensive Guide for DNS Cluster Configurations
 
Beyond Best Practice: Grid Computing in the Modern World
Beyond Best Practice: Grid Computing in the Modern World Beyond Best Practice: Grid Computing in the Modern World
Beyond Best Practice: Grid Computing in the Modern World
 
Production MongoDB in the Cloud
Production MongoDB in the CloudProduction MongoDB in the Cloud
Production MongoDB in the Cloud
 
Feed Burner Scalability
Feed Burner ScalabilityFeed Burner Scalability
Feed Burner Scalability
 
Resilient design 101 (BuildStuff LT 2017)
Resilient design 101 (BuildStuff LT 2017)Resilient design 101 (BuildStuff LT 2017)
Resilient design 101 (BuildStuff LT 2017)
 
Resilient Design 101 (JeeConf 2017)
Resilient Design 101 (JeeConf 2017)Resilient Design 101 (JeeConf 2017)
Resilient Design 101 (JeeConf 2017)
 
Continuent webinar 02-19-2015
Continuent webinar 02-19-2015Continuent webinar 02-19-2015
Continuent webinar 02-19-2015
 
GC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconGC free coding in @Java presented @Geecon
GC free coding in @Java presented @Geecon
 
Sql saturday dc vm ware
Sql saturday dc vm wareSql saturday dc vm ware
Sql saturday dc vm ware
 
ESX performance problems 10 steps
ESX performance problems 10 stepsESX performance problems 10 steps
ESX performance problems 10 steps
 
Low latency for high throughput
Low latency for high throughputLow latency for high throughput
Low latency for high throughput
 
Low level java programming
Low level java programmingLow level java programming
Low level java programming
 
Adminblast 2013
Adminblast 2013Adminblast 2013
Adminblast 2013
 
Troubleshooting Apache Cloudstack
Troubleshooting Apache CloudstackTroubleshooting Apache Cloudstack
Troubleshooting Apache Cloudstack
 
Automating the Entire PostgreSQL Lifecycle
Automating the Entire PostgreSQL Lifecycle Automating the Entire PostgreSQL Lifecycle
Automating the Entire PostgreSQL Lifecycle
 

Similar to Reactive Microservices with JRuby and Docker

How lagom helps to build real world microservice systems
How lagom helps to build real world microservice systemsHow lagom helps to build real world microservice systems
How lagom helps to build real world microservice systemsMarkus Eisele
 
Microservices Manchester: How Lagom Helps to Build Real World Microservice Sy...
Microservices Manchester: How Lagom Helps to Build Real World Microservice Sy...Microservices Manchester: How Lagom Helps to Build Real World Microservice Sy...
Microservices Manchester: How Lagom Helps to Build Real World Microservice Sy...OpenCredo
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
Reactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesReactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesStéphane Maldini
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016Frank Lyaruu
 
Container orchestration from theory to practice
Container orchestration from theory to practiceContainer orchestration from theory to practice
Container orchestration from theory to practiceDocker, Inc.
 
Microservice Come in Systems
Microservice Come in SystemsMicroservice Come in Systems
Microservice Come in SystemsMarkus Eisele
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersoazabir
 
Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey J On The Beach
 
Deploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkDeploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkJulien SIMON
 
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...Cloud Native Day Tel Aviv
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akkanartamonov
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorStéphane Maldini
 
Serverless Multi Region Cache Replication
Serverless Multi Region Cache ReplicationServerless Multi Region Cache Replication
Serverless Multi Region Cache ReplicationSanghyun Lee
 
DevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on KubernetesDevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on KubernetesDinakar Guniguntala
 
Introduction to LAVA Workload Scheduler
Introduction to LAVA Workload SchedulerIntroduction to LAVA Workload Scheduler
Introduction to LAVA Workload SchedulerNopparat Nopkuat
 

Similar to Reactive Microservices with JRuby and Docker (20)

Load testing with Blitz
Load testing with BlitzLoad testing with Blitz
Load testing with Blitz
 
How lagom helps to build real world microservice systems
How lagom helps to build real world microservice systemsHow lagom helps to build real world microservice systems
How lagom helps to build real world microservice systems
 
Microservices Manchester: How Lagom Helps to Build Real World Microservice Sy...
Microservices Manchester: How Lagom Helps to Build Real World Microservice Sy...Microservices Manchester: How Lagom Helps to Build Real World Microservice Sy...
Microservices Manchester: How Lagom Helps to Build Real World Microservice Sy...
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Reactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesReactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServices
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
 
Container orchestration from theory to practice
Container orchestration from theory to practiceContainer orchestration from theory to practice
Container orchestration from theory to practice
 
Microservice Come in Systems
Microservice Come in SystemsMicroservice Come in Systems
Microservice Come in Systems
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey
 
Deploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkDeploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalk
 
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
 
Akka (BeJUG)
Akka (BeJUG)Akka (BeJUG)
Akka (BeJUG)
 
les07.pdf
les07.pdfles07.pdf
les07.pdf
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
 
Serverless Multi Region Cache Replication
Serverless Multi Region Cache ReplicationServerless Multi Region Cache Replication
Serverless Multi Region Cache Replication
 
DevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on KubernetesDevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on Kubernetes
 
Introduction to LAVA Workload Scheduler
Introduction to LAVA Workload SchedulerIntroduction to LAVA Workload Scheduler
Introduction to LAVA Workload Scheduler
 

Recently uploaded

OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...OnePlan Solutions
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Business Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business AnalysisBusiness Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business AnalysisDEEPRAJ PATHAK
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
Santander Stream Processing with Apache Flink
Santander Stream Processing with Apache FlinkSantander Stream Processing with Apache Flink
Santander Stream Processing with Apache Flinkconfluent
 
logical backup of Oracle Datapump-detailed.pptx
logical backup of Oracle Datapump-detailed.pptxlogical backup of Oracle Datapump-detailed.pptx
logical backup of Oracle Datapump-detailed.pptxRemote DBA Services
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
oracle 23c new features for developer and dba
oracle 23c new features for developer and dbaoracle 23c new features for developer and dba
oracle 23c new features for developer and dbaRemote DBA Services
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
What is Mendix and the concept of low-code development.docx
What is Mendix and the concept of low-code development.docxWhat is Mendix and the concept of low-code development.docx
What is Mendix and the concept of low-code development.docxTechnogeeks
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsDEEPRAJ PATHAK
 
OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024OpenMetadata
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxAS Design & AST.
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...kalichargn70th171
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 

Recently uploaded (20)

OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
Transform your Corporate Strategy Office - Harness OnePlan’s Strategic Portfo...
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Business Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business AnalysisBusiness Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business Analysis
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
Santander Stream Processing with Apache Flink
Santander Stream Processing with Apache FlinkSantander Stream Processing with Apache Flink
Santander Stream Processing with Apache Flink
 
logical backup of Oracle Datapump-detailed.pptx
logical backup of Oracle Datapump-detailed.pptxlogical backup of Oracle Datapump-detailed.pptx
logical backup of Oracle Datapump-detailed.pptx
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
oracle 23c new features for developer and dba
oracle 23c new features for developer and dbaoracle 23c new features for developer and dba
oracle 23c new features for developer and dba
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
What is Mendix and the concept of low-code development.docx
What is Mendix and the concept of low-code development.docxWhat is Mendix and the concept of low-code development.docx
What is Mendix and the concept of low-code development.docx
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software Projects
 
OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptx
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 

Reactive Microservices with JRuby and Docker

  • 1. © 2017 Autodesk John Scattergood Senior Principal Engineer JavaOne 2017 Reactive Microservices with JRuby and Docker
  • 2. § Engineer at Autodesk § Enjoy coding in Java, Ruby, Groovy and JavaScript § Run JRuby apps in production that serve millions of requests/day § First time JavaOne Speaker @johnscattergood About Me
  • 4. Our System Market Updates Stock Updates Alerts/Rules Notifications SMS DB Autoscaler Cluster Scale
  • 5. § Price Alerts (eCommerce) § APM and Infrastructure Monitoring (IT) § Fraud Detection (Credit) § Devices, Transponders, etc. (IOT) Other Domains
  • 7. § Dynamic § Object-oriented w/ first class functions § Expressive § Flexible § Easy to learn Ruby Ruby is simple in appearance, but is very complex inside just like our human body - Yukihiro “Matz” Matsumoto Ruby Creator
  • 8. @memo = { 1 => 1, 2 => 2 } def fib(n) @memo[n] ||= fib(n - 1) + fib(n - 2) end fib(100) => 573147844013817084101 Fibonnaci
  • 9. § Fully compatible implementation of Ruby § Includes benefits of JVM § High Performance § True multi-threading § Java libraries and interoperability § Standard monitoring tools JRuby
  • 10. require 'java' java_import 'java.util.concurrent.ConcurrentHashMap' map = ConcurrentHashMap.new map['A'] = 123 map.put_if_absent('B', 456) puts map => {"A"=>123, "B"=>456} Java to Ruby
  • 11. § Asynchronous HTTP via Netty § Reactive Streams Support § Promises and Streams library § Works great with JRuby § Plugin Modules § Guice § Dropwizard Metrics § Etc. Ratpack
  • 12. RatpackServer.start do |server| server.handlers do |chain| chain.get do |ctx| ctx.render(’Hello World!') end end end Starting a Server
  • 13. § Push-Pull based “stream” processing: § Non-blocking § Asynchronous § Potentially Unbounded § Non-blocking backpressure § JDK 9: java.util.concurrent.Flow Reactive Streams
  • 14. Promise .value(@metric_registry) .map(MetricRegistryJsonMapper.new(@alloc, MetricFilter::ALL)) .map { |buf| buf.to_string(Charset.default_charset) } .map { |string| JSON.parse(string) } .flat_map { |metric| send_event(metric) } .then { |resp| Common::Log.debug "#{resp.status.code}" } Example
  • 15. § Cluster management with Docker Engine § Task Scheduling and Scaling § Service Discovery § Load Balancing § Automatic Restart/Recovery § Rolling updates Docker Swarm Mode
  • 16. § Cluster service that offers a REST API for scaling up and down tasks § Automatically detects managed services in swarm § Supports § Preset scale increments/decrements § Cooldowns to avoid mistakes Orbiter
  • 22. Our System HTTP POST Market Updates Stock Updates Alerts/Rules Notifications SMS DB Autoscaler Cluster Orbiter HTTP POST
  • 23. REST = Synchronous Synchronous ≠ Reactive How is this reactive?
  • 24. § Message Passing via HTTP POST § Service should limit blocking as much as possible § Return a Receipt for long processes § Communicate Backpressure via Status Codes (429) § Client decides how to handle messages if service is unavailable § Buffering § Dropping Reactive REST
  • 25. § HTTP is really nice because… § DNS and/or Service Discovery § Load Balancing § Transparent Scaling § Dynamic Routing and Proxies Nothing wrong with Queues, but…
  • 27. § Backpressure § Make the caller wait § Buffering § Accept the requests and send batches downstream § Caching § Accept the requests and send most recent downstream Strategies
  • 28. chain.post(stock') do |ctx| http_client = ctx.get(HttpClient.java_class) alert_service_client = AlertServiceClient.new(ENV[’SA_ALERT_SERVICE_URL'], http_client) ctx.request.body .map { |b| JSON.parse(b.text) } .flat_map { |event| alert_service_client.send_event(event) } .then { ctx.render('OK') } end Backpressure
  • 30. Buffering chain.post(’stock') do |ctx| buffer = ctx.get(EventBuffer.java_class) ctx.request.body .map { |b| JSON.parse(b.text) } .flat_map { |event| buffer.add(event) } .then do |buffered| if buffered ctx.render('OK') else Common::Log.debug 'backpressure!!!' ctx.response.status(429).send end end end
  • 31. def add(event) Promise.async do |d| d.success(@buffer.offer(event, 1, TimeUnit::SECONDS)) end end def run Execution.fork.start do |_| get_events .map { |events| reduce_events(events) } .flat_map { |events| send_events(events) } .defer(Duration.of_seconds(@backoff_duration)) .then do |responses| responses.each { |response| handle_response(response) } end end end Buffering (contd)
  • 33. Caching chain.post(’stock') do |ctx| cache = ctx.get(EventCache.java_class) ctx.request.body .map { |b| JSON.parse(b.text) } .flat_map { |event| cache.add(event) } .then do |cached| if cached ctx.render('OK') else Common::Log.debug 'backpressure!!!' ctx.response.status(429).send end end end
  • 34. def add(event) Promise.async do |d| @cache.put(event['ticker'], event['price']) @updates.put(event['ticker'], true) d.success(true) end end def run Execution.fork.start do |_| start = Time.now get_events .map { |keys| hydrate_events(keys) } .flat_map { |events| send_events(events) } .defer(Duration.of_seconds(@backoff_duration)) .then do |responses| responses.each { |response| handle_response(response) } end end end Caching (contd)
  • 36. def backpressure(backoff) if backoff @metric_registry.meter('backpressure.service.alert').mark @backoff_duration = [30, 1 + @backoff_duration * 2].min puts "increasing back off to #{@backoff_duration} secs" else @backoff_duration = [@backoff_duration / 2, 1].max if @backoff_duration > 1 puts "decreasing back off to #{@backoff_duration} secs" else @backoff_duration = 0 end end end Backpressure
  • 37. Cluster Machine Machine Machine Swarm Manager orbiter stock alert alertalert notif notif scale db
  • 38. Cluster Machine Machine Machine Swarm Manager orbiter stock alert alertalert notif notif scale Ingress traffic Routed to Service db
  • 39. Cluster Machine Machine Machine Swarm Manager orbiter stock alert alertalert notif notif scale Ingress traffic Routed to Service db
  • 40. Cluster Machine Machine Machine Swarm Manager orbiter stock alert alertalert notif notif scale alert Ingress traffic Routed to Service db
  • 43. def adjust_scale(metric_name, metric_value) service = metric_name.split('.').last Promise .value(metric_value) .next_op_if( ->(v) { v['m1_rate'] < 0.01 && v['m5_rate'] < 0.01 }, ->(_) { scale_down(service) } ) .next_op_if( ->(v) { v['m1_rate'] > 1 }, ->(_) { scale_up(service) } ) end Scaling Up and Down
  • 44. alert: image: stockalert command: bundle exec jruby ./alert_service/run.rb networks: - stockalert deploy: mode: replicated replicas: 1 labels: [orbiter=true,orbiter.up=2,orbiter.cooldown=300] … Docker Scaling Configuration
  • 45. Watch it in Action! Scaling Up
  • 47. Watch it in Action! Scaling Down
  • 48. Demo HTTP POST Market Updates Stock Updates Alerts/Rules Notifications SMS DB Autoscaler Cluster Orbiter HTTP POST
  • 49. § Joe Kutner, Deploying JRuby 9k § Joe Kutner, “Reactive Ruby: Building Real-time Apps with JRuby and Ratpack”, http://blog.heroku.com § Dan Woods, Learning Ratpack § Jonas Bonér, Reactive Microservices Architecture § GitHub Project: https://github.com/jscattergood/JavaOne_2017_CON3214 Further Reading
  • 50. Autodesk and the Autodesk logo are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document. © 2017 Autodesk. All rights reserved.