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
SCALABLE HIGHLYAVAILABLE DISTRIBUTED
SYSTEM WITH JBOSSAuthor Evgeniy Khist
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
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
WHAT IS DISTRIBUTED SYSTEM?A set of independent computers that can be viewed by its clients
as a single system
WHAT DO WE EXPECT FROM DISTRIBUTEDSYSTEMS?
Ability to handle growing amount of loadLittle effort required to increase capacityNo unplanned downtime
WHAT DIFFICULTIES DO DISTRIBUTEDSYSTEMS INTRODUCE?Multiple points of failureData consistency across the nodesComplexity of managing
DISTRIBUTED ARCHITECTUREDistributed system is heterogeneousDistributed system has multiple autonomous componentsComponent is a modular unit that can be used exclusively
DISTRIBUTED SYSTEM
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
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
MESSAGE BROKER
JMSJava Message Service is a Java API that allows applications to
create, send, receive, and read messages.
AsynchronousReliable - message is delivered once and onlyonce
MESSAGE QUEUEProducer puts message into the queue
Any available at this moment consumer capable of handling thismessage takes it from the queue
MESSAGE QUEUE
MESSAGE QUEUE
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
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
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
HORIZONTAL SCALABILITY
HORIZONTAL SCALABILITY
HORIZONTAL SCALABILITY
MESSAGE BROKER CLUSTERING
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
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
STATELESSNESSEasier to scaleReduces memory usageNo need for session data replication
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
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
CONSISTENCY
CONSISTENCYAlternatively, write-ahead transaction log (journal) can be used
In case of node failure transaction log can be replayed or otheractions can be taken
CONSISTENCY
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
SYNCHRONOUS JMS
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
CONSISTENCYCalls to 3rd party services is often done by HTTP or other
protocol not supporting ACID transactions
HTTP CALLS TO THIRD-PARTY SERVICE
HTTP CALLS TO THIRD-PARTY SERVICE
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
WRITE-AHEAD TRANSACTION LOG
WHY JBOSS?ClusteringDeployment APIDistributed caching (Infinispan)Distributed deploymentFailoverHibernate integrationRobust messaging subsystem (HornetQ)Load balancingManagement APILogging (SLF4J implementation)JBoss Modules
CONFIGURATION CONCEPTSstandalone.xml or domain.xml and host.xmlJBoss Web ConsoleJBoss Command Line Interface (CLI)
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.
JBOSS MODULESUnlike OSGi, JBoss Modules does not implement a container;
rather, it is a thin bootstrap wrapper for executing an applicationin a modular environment.
DEMONSTRATION
https://github.com/evgeniy-khist/blog/tree/master/Kiev-Ciklum-Java-Saturday-2013_11_23
More slides