scalable highly available distributed system with jboss/wildfly
DESCRIPTION
JBoss Enterprise Application Platform and Wildfly are flexible and mature platforms with excited features like small memory footprint and lightning fast startup times. Learn how JBoss can help to build distributed system and achieve scalability and high availability independently of application frameworks and datastores. http://slides-evgeniykhist.rhcloud.com/scalable-highly-available-distributed-system-with-jboss/ http://developer-should-know.tumblr.com/TRANSCRIPT
![Page 1: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/1.jpg)
SCALABLE HIGHLYAVAILABLE DISTRIBUTED
SYSTEM WITH JBOSSAuthor Evgeniy Khist
![Page 2: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/2.jpg)
SCALABLE HIGHLY AVAILABLE DISTRIBUTEDSYSTEM WITH JBOSS
JBoss Enterprise Application Platform and Wildfly are flexible andmature platforms with excited features like small memory
footprint and lightning fast startup times
Learn how JBoss can help to build distributed system andachieve scalability and high availability independently of
application frameworks and datastores
![Page 3: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/3.jpg)
WHY DO WE NEED DISTRIBUTED SYSTEM?We can't guarantee that single server instance will be able tohandle growing amount of requests just updating hardware
![Page 4: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/4.jpg)
WHAT IS DISTRIBUTED SYSTEM?A set of independent computers that can be viewed by its clients
as a single system
![Page 5: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/5.jpg)
WHAT DO WE EXPECT FROM DISTRIBUTEDSYSTEMS?
Ability to handle growing amount of loadLittle effort required to increase capacityNo unplanned downtime
![Page 6: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/6.jpg)
WHAT DIFFICULTIES DO DISTRIBUTEDSYSTEMS INTRODUCE?Multiple points of failureData consistency across the nodesComplexity of managing
![Page 7: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/7.jpg)
DISTRIBUTED ARCHITECTUREDistributed system is heterogeneousDistributed system has multiple autonomous componentsComponent is a modular unit that can be used exclusively
![Page 8: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/8.jpg)
DISTRIBUTED SYSTEM
![Page 9: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/9.jpg)
APPLICATION INTEGRATION STYLESThere are four main approaches for integrating components of
distributed system
File transfer - application produces files of shared data forothers to consume, and consumes files that others haveproducedShared database - applications store the shared data in acommon databaseRPC (Remote Procedure Call) - application exposes some of itsprocedures so that they can be invoked remotely by otherapplications to run behavior and exchange dataMessaging - application is connected to a common messagingsystem, and exchange data and run behavior using messages
![Page 10: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/10.jpg)
MESSAGINGMessaging is a method of communication between software
components or applications
Messaging enables distributed communication that is looselycoupled
Requires an extra component in the architecture, the messagebroker
![Page 11: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/11.jpg)
MESSAGE BROKER
![Page 12: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/12.jpg)
JMSJava Message Service is a Java API that allows applications to
create, send, receive, and read messages.
AsynchronousReliable - message is delivered once and onlyonce
![Page 13: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/13.jpg)
MESSAGE QUEUEProducer puts message into the queue
Any available at this moment consumer capable of handling thismessage takes it from the queue
![Page 14: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/14.jpg)
MESSAGE QUEUE
![Page 15: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/15.jpg)
MESSAGE QUEUE
![Page 16: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/16.jpg)
SCALABILITYScalability is the ability of a system to expand to handle a growing
amount of work
For example, ability of a system to scale to handle larger numberof users
![Page 17: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/17.jpg)
TWO WAYS OF SCALING APPLICATIONSVertical Scalability - adding more resources within the sameapplication to increase capacity (adding CPUs to an existingserver, adding hard drive on an existing RAID storage)Horizontal Scalability - adding multiple application instancesand making them work as a single unit
![Page 18: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/18.jpg)
HORIZONTAL SCALABILITYIs typically achieved using clustering and load balancing
Cluster is homogenous and consists of multiple instances ofdistributed system component
Typically each cluster node runs on its own server instance
![Page 19: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/19.jpg)
HORIZONTAL SCALABILITY
![Page 20: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/20.jpg)
HORIZONTAL SCALABILITY
![Page 21: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/21.jpg)
HORIZONTAL SCALABILITY
![Page 22: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/22.jpg)
MESSAGE BROKER CLUSTERING
![Page 23: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/23.jpg)
FAULT-TOLERANCEFault-tolerance is ability of a system to continue operating
properly when some part of the system fails
Availability is the amount of time that a system is actuallyavailable relative to the amount of time it is expected to be
available
Fault-tolerant systems are typically based on the concept ofredundancy
Redundancy is the duplication of critical components of a systemfor increasing reliability of the system
![Page 24: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/24.jpg)
STATELESSNESSStateless means no client context being stored on the server
between requests, but passed with each request
But stateless service can talk to other services maintaining stateof business objects
![Page 25: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/25.jpg)
STATELESSNESSEasier to scaleReduces memory usageNo need for session data replication
![Page 26: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/26.jpg)
ASYNCHRONOUS REQUEST PROCESSINGAsynchronous communication using JMS on back-end
Request can be in one of states: SUBMITED, IN_PROGRESS,
DONE, FAILED
Request can change from one state to another during processingby different modules
![Page 27: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/27.jpg)
CONSISTENCYMessage consumption from one queue and sending to another
queue should be done in single transaction
If node fails after message consumption, but before sendingmessage to other destination, it will be returned to queue and can
be consumed again by any other node
![Page 28: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/28.jpg)
CONSISTENCY
![Page 29: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/29.jpg)
CONSISTENCYAlternatively, write-ahead transaction log (journal) can be used
In case of node failure transaction log can be replayed or otheractions can be taken
![Page 30: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/30.jpg)
CONSISTENCY
![Page 31: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/31.jpg)
ASYNCHRONOUS REQUEST PROCESSINGAJAX polling on front-end
After sending request to API request id will be sent in responseThis request id will be used for polling request statusLong-polling from async-servlets (Servlet 3.0) can be used forefficient pollingWhen status shows that request is completed, additionaldetails can be requested
![Page 32: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/32.jpg)
SYNCHRONOUS JMS
![Page 33: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/33.jpg)
JMS REQUEST-REPLY PATTERNJMS can be also used for synchronous communication
Using temporary queues for repliesTemporary queue address is sent in JMSReplyTo message property, so only sender knows about replyqueue
Using shared reply queue with message selectorFiltering by JMSCorrelationID, for example
Using exclusive reply queueNot cluster-safe until each node (even of the same module) has separate queue for replies
![Page 34: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/34.jpg)
CONSISTENCYCalls to 3rd party services is often done by HTTP or other
protocol not supporting ACID transactions
![Page 35: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/35.jpg)
HTTP CALLS TO THIRD-PARTY SERVICE
![Page 36: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/36.jpg)
HTTP CALLS TO THIRD-PARTY SERVICE
![Page 37: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/37.jpg)
CONSISTENCYTo solve this issue write-ahead transaction log (journal) can be used
Transaction log can be stored locally for each node
In case of node failure transaction log can be replayed
After failure node will request 3rd party service for transactionstatus and basing on response will repeat transaction
![Page 38: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/38.jpg)
WRITE-AHEAD TRANSACTION LOG
![Page 39: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/39.jpg)
WHY JBOSS?ClusteringDeployment APIDistributed caching (Infinispan)Distributed deploymentFailoverHibernate integrationRobust messaging subsystem (HornetQ)Load balancingManagement APILogging (SLF4J implementation)JBoss Modules
![Page 40: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/40.jpg)
CONFIGURATION CONCEPTSstandalone.xml or domain.xml and host.xmlJBoss Web ConsoleJBoss Command Line Interface (CLI)
![Page 41: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/41.jpg)
JBOSS MODULESJBoss Modules is a standalone implementation of a modular
(non-hierarchical) class loading and execution environment forJava. In other words, rather than a single class loader which loads
all JARs into a flat class path, each library becomes a modulewhich only links against the exact modules it depends on, and
nothing more. It implements a thread-safe, fast, and highlyconcurrent delegating class loader model, coupled to an
extensible module resolution system, which combine to form aunique, simple and powerful system for application execution
and distribution.
![Page 42: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/42.jpg)
JBOSS MODULESUnlike OSGi, JBoss Modules does not implement a container;
rather, it is a thin bootstrap wrapper for executing an applicationin a modular environment.
![Page 43: Scalable Highly Available Distributed System with JBoss/WildFly](https://reader034.vdocuments.us/reader034/viewer/2022051400/54c17bee4a7959ab318b4602/html5/thumbnails/43.jpg)
DEMONSTRATION
https://github.com/evgeniy-khist/blog/tree/master/Kiev-Ciklum-Java-Saturday-2013_11_23