SlideShare a Scribd company logo
1 of 49
Vert.x for Microservices Architecture
Idan Fridman
Idan.frid@gmail.com
www.idanfridman.com
Agenda
• The C10k problem
• Understanding the Reactor pattern
• The good (and the bad) of Vert.x and when we should use it.
• Vertx and Websockets
• RxJava And Vertx
• Vert.x into production
Traffic, Traffic Traffic...!
Lots of machines
http://www.internetlivestats.com/one-second/
One machine scenario
Simple use case: Response Request
Datasource
Conventional Technology Stack
Current Setup
Opening a new connection for every single request/response pair
Default HTTP connector is blocking and follows
a one thread per connection model
to serve 1000 concurrent users, it requires 1000
active threads
C10K Problem
Prevented servers from handling more than 10,000 concurrent connections.
The Apache problem is the more connections the worse the performance.
Let’s assume we execute 1000 “quick” transactions
then you’ll only have about a 1000 concurrent connections to the server
Change the length of each transaction to 10 seconds
now at 1000 transactions/sec - you’ll have 10K connections open
“Why like this?”
Webserver gets a connection
it starts a worker/thread
1. Memory limit
Each Thread takes min memory(default 1024k == 1mb)
2. Operating system limit
The operating system by default can't open 10k threads.
10 concurrent requests==10k threads==10k * 1MB==10GB
Reactor pattern
From wiki:
The reactor design pattern is an event handling pattern for handling service requests delivered concurrently to a service
handler by one or more inputs.
The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated
request handlers.
Reactor pattern(Revisited)
We already understand the The disadvantage of using a separate thread for each event listener
The reactor pattern is one implementation technique of event-driven architecture
it uses a single threaded event loop blocking on resource-emitting events and dispatches them to
corresponding handlers and callbacks.
Reactor pattern model
Reactor
A Reactor runs in a separate thread, and its job is to react to IO events by dispatching the work to the
appropriate handler.
It’s like a telephone operator in a company who answers calls from clients and transfers the line to the
appropriate contact.
Reactor pattern model
Handlers
A Handler performs the actual work to be done with an I/O event, similar to the actual officer in the
company the client wants to speak to.
A reactor responds to I/O events by dispatching the appropriate handler. Handlers perform non-blocking
actions.
Event-Loop
Standard reactor implementation:
single event loop thread which runs around in a loop delivering all events to all handlers as they arrive.
Who implementing this?
Don’t call us, we’ll call you
Main thread should works very quickly
No long jobs in the loop
Schedule a call asynchronously
Operations in event loop should just schedule all asynchronous operations with callbacks and go to next
request without awaiting any results.
We love the JVM - Let’s have vert.x
1. Microservices toolkit for the JVM
2. Asynchronous
3. Scalable
4. Concurrent services development model
5. Polyglot language development with first class support for JavaScript, Ruby, Groovy, Scala, and of
course Java.
Vertx is a toolkit not a framework or/container
(means you can use it within your existing application to give it the Vert.x super powers)
Vertx & Friends
Vertx main
server types
Httpserver
Websockets server
TCP server
Easy as that
Building Vertx with Verticles
Verticle is the building blocks of Vert.X which reminds an Actor-like approach for concurrency model and avoiding mutable
shared data
Each Verticle can communicate with another using EventBus(explain later)
Verticle types:
Standard Verticles
Worker Verticles
Verticle Types
Standard verticles
Assigned an event loop thread when they are created
All the code in your verticle instance is always executed on the same event loop
You can write all the code in your application as single threaded and let Vert.x worrying about the threading and scaling.
How to run blocking-code anyway?
Worker verticles
Executed not using an event loop, but using a thread from the Vert.x worker thread pool.
Worker verticles are designed for calling blocking code, as they won’t block any event loops.
*Unlike Nodejs where you need to use promises with vertx you can handle blocking-code out of the box
The Event Bus
Eventbus is build-in tunnel which providing a messaging mechanism to all Vertx components.
Different parts of your application able communicate with each other irrespective of what language they are
written in.
The event bus supports publish/subscribe, point to point, and request-response messaging.
Eventbus features:
registering handlers
unregistering handlers and
sending messages
publishing messages.
Eventbus - Event Driven built-In
Eventbus will be help you to scale up your Vert.x Cluster.
Eventbus and the Microservices way
Clustering
Discovery and group membership of Vert.x nodes in a cluster
Maintaining cluster with topic subscriber lists (so we know which nodes are interested in which event bus
addresses)
Distributed Map support
Distributed Locks
EventBus can be clustered:
When clustering different vert.x instances on the network they going to use the same single distributed
eventbus
Hazelcast
Vertx can use different cluster-managers. The default one is Hazelcast
Hazelcast is in-memory operational platform
Easy Discovery service
Adding JWT capabilities
Security is very important within microservices.
Vert.x Has Built-in JWT support.
You can issue JWT tokens and validate them within your Vert.x Endpoints
Websockets
Web technology that allows a full duplex socket-like connection between HTTP
servers and HTTP clients (typically browsers).
Once established:
“Push” messages
Data frames can be sent back and forth between the client and the server in full-
duplex mode
Native to Browsers
WebSocket connection remains open so there is no need to send
another request to the server
Websockets and Vertx
Vertx enable out of the box support using Websockets.
Vert.x supports WebSockets on both the client and server-side.
Websockets Handler
server.websocketHandler(websocket -> {
System.out.println("WebSocket is On!");
});
Handler will be called when connection established:
SockJS
Client side JavaScript library and protocol which provides a simple WebSocket-like interface
Make connections to SockJS servers irrespective of whether the actual browser or network will allow real
WebSockets.
Supporting various different transports between browser and server, and choosing one at run-time
according to browser and network capabilities.
Transparent
Eventbus using sockJS bridge
Client side allows you to send and publish messages to the event bus and register handlers to receive
messages
Router router = Router.router(vertx);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
sockJSHandler.bridge(options);
router.route("/eventbus/*").handler(sockJSHandler);
Reactive And Vertx
Natural couple
Open many workers in eventloop?
bad
Open too many workers won't makes you any different
Work asynchronously
Who said callback (hell)?
Vertx Supports the popular RxJava library that allows you to write observers that
react to sequences of events.
Scenario Example
1. Client calls to our app’s web service ->
2. our webservice need to request multiple micro-services->
3. uses a callbacks interface to pass the successful result to the
next web service call
4. define another success callback- >
5. and then moves on to the next web service request.
Orchestrator
A B C F
Client Request
Looks like that->
Also known as:
“The Callback Hell”
//The "Nested Callbacks" Way
public void fetchUserDetails() {
//first, request the users...
mService.requestUsers(new Callback<GithubUsersResponse>() {
@Override
public void success(final GithubUsersResponse githubUsersResponse,
final Response response) {
Timber.i(TAG, "Request Users request completed");
final List<GithubUserDetail> githubUserDetails = new ArrayList<GithubUserDetail>();
//next, loop over each item in the response
for (GithubUserDetail githubUserDetail : githubUsersResponse) {
//request a detail object for that user
mService.requestUserDetails(githubUserDetail.mLogin,
new Callback<GithubUserDetail>() {
@Override
public void success(GithubUserDetail githubUserDetail,
Response response) {
Log.i("User Detail request completed for user : " + githubUserDetail.mLogin);
githubUserDetails.add(githubUserDetail);
if (githubUserDetails.size() == githubUsersResponse.mGithubUsers.size()) {
//we've downloaded'em all - notify all who are interested!
Async our microservices call
(Using Reactor)
A library for composing asynchronous and
event-based programs by using observable sequences.
● Allow you to compose sequences together declaratively
● Abstracting away :
o low-level threading
o synchronization
o thread-safety
o concurrent data structures
o non-blocking I/O.
RxJava for the rescue
● RxJava is single jar lightweight library.
● Using the Observable abstraction and related higher-order functions.
(Support Java6+)
The following external libraries can work with RxJava:
● Camel RX provides an easy way to reuse any of the Apache Camel components, protocols, transports and data
formats with the RxJava API
● rxjava-http-tail allows you to follow logs over HTTP, like tail -f
● mod-rxvertx - Extension for VertX that provides support for Reactive Extensions (RX) using the RxJava library
Zipping Observables
(Without blocking)
public Observable<Boolean> registerRequest(..) {
return Observable.zip(
createNewRoomNode(),
createNewWaveNode(),
logRecordOnMysql(),
sendWelcomeMessage()
, (r1, r2, r3, r4) -> r1 && r2 && r3 && r4);
}
private Observable<Boolean> createNewRoomNode(..) {
...
return
}
private Observable<Boolean> createNewWaveNode(..) {
...
return
}
private Observable<Boolean> logRecordOnMysql(..) {
...
return
}
Vertx going to production
(Deployment)
Vertx can be deployed to AWS with Hazelcast
Discovery is taking placing using the same security groups
Vertx going to production
Enterprise ready solution which can be deployed on amazon
Combining powerful technology with complete production solution
Empower Spring configurations, env’s, defaults, libs with vertx technology
Spring Into Vertx
(Benefits)
DI
Have a deployment ready container
Configurations setup
Endpoints and JMX ready
Spring Data and more
Practical implementation
Spring into vert.x
● On starter Verticle initiate Spring context
● Pass Spring context to each verticle as param
● Gotchas: Make sure you always share the same spring context
Vertx Into Spring
Leverage Spring-MVC while expose controllers endpoints
Send Operational events via Eventbus(e.g send commands to connected
endpoints, websockets, etc..
Deploy Verticles inside Spring
My Vert.X Case-Study
Thank you:)
Idan Fridman
Idan.frid@gmail.com
www.idanfridman.com

More Related Content

What's hot

Real Time Test Data with Grafana
Real Time Test Data with GrafanaReal Time Test Data with Grafana
Real Time Test Data with GrafanaIoannis Papadakis
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingSUDIP GHOSH
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformVMware Tanzu
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentationVibhor Grover
 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8José Paumard
 
Expose your event-driven data to the outside world using webhooks powered by ...
Expose your event-driven data to the outside world using webhooks powered by ...Expose your event-driven data to the outside world using webhooks powered by ...
Expose your event-driven data to the outside world using webhooks powered by ...HostedbyConfluent
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVMSylvain Wallez
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsYura Nosenko
 
Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetesRishabh Indoria
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS NATS
 
REST-API overview / concepts
REST-API overview / conceptsREST-API overview / concepts
REST-API overview / conceptsPatrick Savalle
 
Performance Tuning RocksDB for Kafka Streams’ State Stores
Performance Tuning RocksDB for Kafka Streams’ State StoresPerformance Tuning RocksDB for Kafka Streams’ State Stores
Performance Tuning RocksDB for Kafka Streams’ State Storesconfluent
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013mumrah
 

What's hot (20)

Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Real Time Test Data with Grafana
Real Time Test Data with GrafanaReal Time Test Data with Grafana
Real Time Test Data with Grafana
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Svelte JS introduction
Svelte JS introductionSvelte JS introduction
Svelte JS introduction
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise Platform
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8
 
Expose your event-driven data to the outside world using webhooks powered by ...
Expose your event-driven data to the outside world using webhooks powered by ...Expose your event-driven data to the outside world using webhooks powered by ...
Expose your event-driven data to the outside world using webhooks powered by ...
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
JVM++: The Graal VM
JVM++: The Graal VMJVM++: The Graal VM
JVM++: The Graal VM
 
Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetes
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS
 
REST-API overview / concepts
REST-API overview / conceptsREST-API overview / concepts
REST-API overview / concepts
 
Performance Tuning RocksDB for Kafka Streams’ State Stores
Performance Tuning RocksDB for Kafka Streams’ State StoresPerformance Tuning RocksDB for Kafka Streams’ State Stores
Performance Tuning RocksDB for Kafka Streams’ State Stores
 
Intro to GraphQL
 Intro to GraphQL Intro to GraphQL
Intro to GraphQL
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
 

Similar to Vert.x for Microservices Architecture

WCF tutorial
WCF tutorialWCF tutorial
WCF tutorialAbhi Arya
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteTushar B Kute
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIPRIYADARSINISK
 
Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Deepak Gupta
 
Building Modern Distributed Applications in Go with Service Weaver
Building Modern Distributed Applications in Go with Service WeaverBuilding Modern Distributed Applications in Go with Service Weaver
Building Modern Distributed Applications in Go with Service WeaverShiju Varghese
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing Techglyphs
 
Advance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletAdvance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletPayal Dungarwal
 
Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swiftTim Burks
 
An In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use Cases
An In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use CasesAn In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use Cases
An In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use CasesTien Nguyen
 
Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)Agile Lietuva
 
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...MSDEVMTL
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtapVikas Jagtap
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 
Iot hub agent
Iot hub agentIot hub agent
Iot hub agentrtfmpliz1
 

Similar to Vert.x for Microservices Architecture (20)

WCF tutorial
WCF tutorialWCF tutorial
WCF tutorial
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, API
 
Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)
 
Building Modern Distributed Applications in Go with Service Weaver
Building Modern Distributed Applications in Go with Service WeaverBuilding Modern Distributed Applications in Go with Service Weaver
Building Modern Distributed Applications in Go with Service Weaver
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
Servlets
ServletsServlets
Servlets
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Advance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletAdvance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.Servlet
 
Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swift
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Ecom 1
Ecom 1Ecom 1
Ecom 1
 
Servlets
ServletsServlets
Servlets
 
An In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use Cases
An In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use CasesAn In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use Cases
An In-Depth Comparison of WebSocket and SignalR: Pros, Cons, and Use Cases
 
Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
 
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Iot hub agent
Iot hub agentIot hub agent
Iot hub agent
 

Recently uploaded

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
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
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Recently uploaded (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
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...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Vert.x for Microservices Architecture

  • 1. Vert.x for Microservices Architecture Idan Fridman Idan.frid@gmail.com www.idanfridman.com
  • 2. Agenda • The C10k problem • Understanding the Reactor pattern • The good (and the bad) of Vert.x and when we should use it. • Vertx and Websockets • RxJava And Vertx • Vert.x into production
  • 3. Traffic, Traffic Traffic...! Lots of machines http://www.internetlivestats.com/one-second/
  • 4. One machine scenario Simple use case: Response Request Datasource
  • 6. Current Setup Opening a new connection for every single request/response pair Default HTTP connector is blocking and follows a one thread per connection model to serve 1000 concurrent users, it requires 1000 active threads
  • 7. C10K Problem Prevented servers from handling more than 10,000 concurrent connections. The Apache problem is the more connections the worse the performance. Let’s assume we execute 1000 “quick” transactions then you’ll only have about a 1000 concurrent connections to the server Change the length of each transaction to 10 seconds now at 1000 transactions/sec - you’ll have 10K connections open
  • 8. “Why like this?” Webserver gets a connection it starts a worker/thread 1. Memory limit Each Thread takes min memory(default 1024k == 1mb) 2. Operating system limit The operating system by default can't open 10k threads. 10 concurrent requests==10k threads==10k * 1MB==10GB
  • 9. Reactor pattern From wiki: The reactor design pattern is an event handling pattern for handling service requests delivered concurrently to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.
  • 10. Reactor pattern(Revisited) We already understand the The disadvantage of using a separate thread for each event listener The reactor pattern is one implementation technique of event-driven architecture it uses a single threaded event loop blocking on resource-emitting events and dispatches them to corresponding handlers and callbacks.
  • 11. Reactor pattern model Reactor A Reactor runs in a separate thread, and its job is to react to IO events by dispatching the work to the appropriate handler. It’s like a telephone operator in a company who answers calls from clients and transfers the line to the appropriate contact.
  • 12. Reactor pattern model Handlers A Handler performs the actual work to be done with an I/O event, similar to the actual officer in the company the client wants to speak to. A reactor responds to I/O events by dispatching the appropriate handler. Handlers perform non-blocking actions.
  • 13. Event-Loop Standard reactor implementation: single event loop thread which runs around in a loop delivering all events to all handlers as they arrive.
  • 15. Don’t call us, we’ll call you Main thread should works very quickly No long jobs in the loop Schedule a call asynchronously Operations in event loop should just schedule all asynchronous operations with callbacks and go to next request without awaiting any results.
  • 16. We love the JVM - Let’s have vert.x 1. Microservices toolkit for the JVM 2. Asynchronous 3. Scalable 4. Concurrent services development model 5. Polyglot language development with first class support for JavaScript, Ruby, Groovy, Scala, and of course Java. Vertx is a toolkit not a framework or/container (means you can use it within your existing application to give it the Vert.x super powers)
  • 20. Building Vertx with Verticles Verticle is the building blocks of Vert.X which reminds an Actor-like approach for concurrency model and avoiding mutable shared data Each Verticle can communicate with another using EventBus(explain later) Verticle types: Standard Verticles Worker Verticles
  • 21. Verticle Types Standard verticles Assigned an event loop thread when they are created All the code in your verticle instance is always executed on the same event loop You can write all the code in your application as single threaded and let Vert.x worrying about the threading and scaling.
  • 22. How to run blocking-code anyway? Worker verticles Executed not using an event loop, but using a thread from the Vert.x worker thread pool. Worker verticles are designed for calling blocking code, as they won’t block any event loops. *Unlike Nodejs where you need to use promises with vertx you can handle blocking-code out of the box
  • 23. The Event Bus Eventbus is build-in tunnel which providing a messaging mechanism to all Vertx components. Different parts of your application able communicate with each other irrespective of what language they are written in. The event bus supports publish/subscribe, point to point, and request-response messaging. Eventbus features: registering handlers unregistering handlers and sending messages publishing messages.
  • 24. Eventbus - Event Driven built-In Eventbus will be help you to scale up your Vert.x Cluster.
  • 25. Eventbus and the Microservices way
  • 26. Clustering Discovery and group membership of Vert.x nodes in a cluster Maintaining cluster with topic subscriber lists (so we know which nodes are interested in which event bus addresses) Distributed Map support Distributed Locks EventBus can be clustered: When clustering different vert.x instances on the network they going to use the same single distributed eventbus
  • 27. Hazelcast Vertx can use different cluster-managers. The default one is Hazelcast Hazelcast is in-memory operational platform Easy Discovery service
  • 28. Adding JWT capabilities Security is very important within microservices. Vert.x Has Built-in JWT support. You can issue JWT tokens and validate them within your Vert.x Endpoints
  • 29. Websockets Web technology that allows a full duplex socket-like connection between HTTP servers and HTTP clients (typically browsers). Once established: “Push” messages Data frames can be sent back and forth between the client and the server in full- duplex mode Native to Browsers
  • 30. WebSocket connection remains open so there is no need to send another request to the server
  • 31. Websockets and Vertx Vertx enable out of the box support using Websockets. Vert.x supports WebSockets on both the client and server-side.
  • 32. Websockets Handler server.websocketHandler(websocket -> { System.out.println("WebSocket is On!"); }); Handler will be called when connection established:
  • 33. SockJS Client side JavaScript library and protocol which provides a simple WebSocket-like interface Make connections to SockJS servers irrespective of whether the actual browser or network will allow real WebSockets. Supporting various different transports between browser and server, and choosing one at run-time according to browser and network capabilities. Transparent
  • 34. Eventbus using sockJS bridge Client side allows you to send and publish messages to the event bus and register handlers to receive messages Router router = Router.router(vertx); SockJSHandler sockJSHandler = SockJSHandler.create(vertx); BridgeOptions options = new BridgeOptions(); sockJSHandler.bridge(options); router.route("/eventbus/*").handler(sockJSHandler);
  • 36. Open many workers in eventloop? bad Open too many workers won't makes you any different Work asynchronously Who said callback (hell)? Vertx Supports the popular RxJava library that allows you to write observers that react to sequences of events.
  • 37. Scenario Example 1. Client calls to our app’s web service -> 2. our webservice need to request multiple micro-services-> 3. uses a callbacks interface to pass the successful result to the next web service call 4. define another success callback- > 5. and then moves on to the next web service request. Orchestrator A B C F Client Request
  • 38. Looks like that-> Also known as: “The Callback Hell”
  • 39. //The "Nested Callbacks" Way public void fetchUserDetails() { //first, request the users... mService.requestUsers(new Callback<GithubUsersResponse>() { @Override public void success(final GithubUsersResponse githubUsersResponse, final Response response) { Timber.i(TAG, "Request Users request completed"); final List<GithubUserDetail> githubUserDetails = new ArrayList<GithubUserDetail>(); //next, loop over each item in the response for (GithubUserDetail githubUserDetail : githubUsersResponse) { //request a detail object for that user mService.requestUserDetails(githubUserDetail.mLogin, new Callback<GithubUserDetail>() { @Override public void success(GithubUserDetail githubUserDetail, Response response) { Log.i("User Detail request completed for user : " + githubUserDetail.mLogin); githubUserDetails.add(githubUserDetail); if (githubUserDetails.size() == githubUsersResponse.mGithubUsers.size()) { //we've downloaded'em all - notify all who are interested!
  • 40. Async our microservices call (Using Reactor) A library for composing asynchronous and event-based programs by using observable sequences. ● Allow you to compose sequences together declaratively ● Abstracting away : o low-level threading o synchronization o thread-safety o concurrent data structures o non-blocking I/O.
  • 41. RxJava for the rescue ● RxJava is single jar lightweight library. ● Using the Observable abstraction and related higher-order functions. (Support Java6+) The following external libraries can work with RxJava: ● Camel RX provides an easy way to reuse any of the Apache Camel components, protocols, transports and data formats with the RxJava API ● rxjava-http-tail allows you to follow logs over HTTP, like tail -f ● mod-rxvertx - Extension for VertX that provides support for Reactive Extensions (RX) using the RxJava library
  • 42. Zipping Observables (Without blocking) public Observable<Boolean> registerRequest(..) { return Observable.zip( createNewRoomNode(), createNewWaveNode(), logRecordOnMysql(), sendWelcomeMessage() , (r1, r2, r3, r4) -> r1 && r2 && r3 && r4); } private Observable<Boolean> createNewRoomNode(..) { ... return } private Observable<Boolean> createNewWaveNode(..) { ... return } private Observable<Boolean> logRecordOnMysql(..) { ... return }
  • 43. Vertx going to production (Deployment) Vertx can be deployed to AWS with Hazelcast Discovery is taking placing using the same security groups
  • 44. Vertx going to production Enterprise ready solution which can be deployed on amazon Combining powerful technology with complete production solution Empower Spring configurations, env’s, defaults, libs with vertx technology
  • 45. Spring Into Vertx (Benefits) DI Have a deployment ready container Configurations setup Endpoints and JMX ready Spring Data and more
  • 46. Practical implementation Spring into vert.x ● On starter Verticle initiate Spring context ● Pass Spring context to each verticle as param ● Gotchas: Make sure you always share the same spring context
  • 47. Vertx Into Spring Leverage Spring-MVC while expose controllers endpoints Send Operational events via Eventbus(e.g send commands to connected endpoints, websockets, etc.. Deploy Verticles inside Spring

Editor's Notes

  1. Give real example If you use regular CRUD application perhaps you wont use vert.x
  2. Give real example
  3. Give real example