SlideShare a Scribd company logo
1 of 42
Download to read offline
Micro Services for Java Architects
Given by Derek C. Ashmore
May 15, 2015
©2015 Derek C. Ashmore, All Rights Reserved 1
Who am I?
• Professional Geek
since 1987
• Java/J2EE/Java EE
since 1999
• Roles include:
• Developer
• Architect
• Project Manager
• DBA
• System Admin
©2015 Derek C. Ashmore, All Rights Reserved 2
Discussion Resources
• This slide deck
– http://www.slideshare.net/derekashmore
• Sample code on my Github
– https://github.com/Derek-Ashmore/
• Sample Java Microservice (Moneta)
– https://github.com/Derek-Ashmore/moneta
• Slide deck has hyper-links!
– Don’t bother writing down URLs
©2015 Derek C. Ashmore, All Rights Reserved 3
Agenda
The “What”
and “Why” of
microservices
Design
Considerations
and Patterns
Packaging
Options
The Fine Print
Summary /
Q&A
©2015 Derek C. Ashmore, All Rights Reserved 4
What are Microservices?
• No concrete definition
• Common microservice traits
– Single functional purpose
• Most/all changes only impact one service
• Not dependent on execution context
– “loosely coupled”
– Independent process/jvm
– Standard Interface (typically Web Service/REST)
– Analogy: Stereo system, Linux utilities
©2015 Derek C. Ashmore, All Rights Reserved 5
Traditional Java EE Application Architecture
• Like a layer cake
• Highly cohesive
• Defined
dependencies
• Deployed as one
unit (war/ear)
• Limited Scalability
• Code Size
©2015 Derek C. Ashmore, All Rights Reserved 6
What is a Monolith?
• Hard to change
– QA test cycles are long
– Change causes unintended
consequences
• Hard to onboard new
developers
• Married to your technical
stack
• Harder to diagnose
bottlenecks and memory
issues
©2015 Derek C. Ashmore, All Rights Reserved 7
Refactoring into Microservices
• Large benefits to
unified user
interface
• Databases
introduce
unwanted coupling
between services
©2015 Derek C. Ashmore, All Rights Reserved 8
Refactoring further
• Databases
physically
separated
• What to do with
common data
needs?
• Service call or
• Data copy
©2015 Derek C. Ashmore, All Rights Reserved 9
No Lock-in
• Platform agnostic
• Fewer dependency
conflicts
• Still have cross-cutting
concerns
• “Toll” for first app
• Still have support
concerns
• Others need to be
able to support your
work
10©2015 Derek C. Ashmore, All Rights Reserved
Easier Management /
Higher Throughput
• Easier to manage large
numbers of developers
– Concentrate on
intelligently drawing
service boundaries
– Manage/enforce service
contracts
• Each service team works
independently
• Team independence leads
to higher development
throughput
©2015 Derek C. Ashmore, All Rights Reserved 11
Isn’t this SOA?
• Yes – More or less
• No concrete definitions
• SOA == dumb endpoints and smart routes
– ESB routes using Mule, Camel, etc.
– Transformations en route
• MS == dumb routes and smart end-points
– Simple routes
• Usually REST or Soap calls via http(s)
• Persistent queue route at it’s most complex
• Analogy: Electrical supply for Stereo
©2015 Derek C. Ashmore, All Rights Reserved 12
Agenda
The “What”
and “Why” of
microservices
Design
Considerations
and Patterns
Packaging
Options
The Fine Print
Summary /
Q&A
©2015 Derek C. Ashmore, All Rights Reserved 13
Design considerations
• Service Boundaries (gerrymandering)
• Service call Failure / Unavailability
• Data Integrity
• Performance
©2015 Derek C. Ashmore, All Rights Reserved 14
Service Boundaries
• Core Services
– Services responsible for maintaining a specific business area data
– Usually named after Nouns
• Service is a system of record for a <blank>
– Student, Course, Classroom, etc.
• Process Services
– Services responsible for performing single complex tasks
– Usually represents an Action or Process
• Service is responsible for processing <blank>
– Student applications, Debt collection, etc.
– These services rely on core services
• Partitioning is an art
– Too few  same drawbacks as traditional architecture
– Too many  excessive network hops
©2015 Derek C. Ashmore, All Rights Reserved 15
Boundary Sanity Check
• Verbalize a mission statement in one sentence
in business terms
– Examples
• This service is the system of record for Student
information
• This service registers students for classes
• This service suspends students
• This service records student payments
• This service produces official transcripts
©2015 Derek C. Ashmore, All Rights Reserved 16
Context Independence Check
• Does your service have multiple consumers?
– Could it?
• Could your service execute as easily in batch as
online?
– If ‘No’, then you’re making context assumptions
• Warning Signs
– Spending time analyzing service call flow
• Your services likely make context assumptions
– Agonizing over which service should do a given
activity
• Maybe you need a new service
©2015 Derek C. Ashmore, All Rights Reserved 17
Microservices are not about size
©2015 Derek C. Ashmore, All Rights Reserved 18
….. Microservices are about having a single business purpose!
Designing for Failure
• Dependent services could be down
– Minimize human intervention
– Fail sooner rather than later
– Horizontal scaling / clustering is your first line of defense
– Coding patterns can help as a backup
• Common Patterns:
– Retry
– Circuit Breaker
– Dispatch via Messaging
©2015 Derek C. Ashmore, All Rights Reserved 19
Retry Pattern
©2015 Derek C. Ashmore, All Rights Reserved 20
• Best for asynchronous tasks
• Limit the number of tries
• Use sleep interval between tries
• Only addresses temporary outages
• Sample Retry Pattern implementation here.
• Tooling Support:
– Apache CXF supports Retry
– Spring Batch RetryTemplate
– Apache HttpClient (Example here)
Circuit Breaker
©2015 Derek C. Ashmore, All Rights Reserved 21
Circuit Breaker (continued)
• Objective: Error out sooner
– Conserves resources
– Automatically “recovers” after a time period
• Modeled after home circuit
• Works on thresholds
– Number of errors required to trip circuit
– Amount of time required to attempt retry
• Has Hysterix support
• Best embedded in interface clients / delegates
• More information here.
• Sample Circuit implementation here.
©2015 Derek C. Ashmore, All Rights Reserved 22
Dispatch via Messaging
©2015 Derek C. Ashmore, All Rights Reserved 23
• Place work instruction on persistent queue
• If receivers are down, work stacks in queue
• Work throttled by number of receivers
• Queue can be JMS or AMQP
• Tooling Support:
– JMS Api (easy API – many use natively)
– Spring JMSTemplate or RabbitTemplate (producer)
Designing for Performance
• More network traffic
– Make services course-grained
– User Interfaces need a general manager
– Horizontal or Vertical Scaling helps
• Common Patterns:
– Back-ends for Front-ends (a.k.a. API Gateway)
– Dispatch via Messaging
– Expiring Cache
©2015 Derek C. Ashmore, All Rights Reserved 24
Back-ends for Front-ends
©2015 Derek C. Ashmore, All Rights Reserved 25
Back-ends for Front-ends
(continued)
• Consolidates service calls for the browser
– Enhances performance
• Open web often not as performant as local LAN
• Also known as “API Gateway”
• Implications
– Don’t expose microservices directly to the
browser
©2015 Derek C. Ashmore, All Rights Reserved 26
Expiring Cache
©2015 Derek C. Ashmore, All Rights Reserved 27
Expiring Cache (continued)
• Look up data once and cache it
– Evict data from the cache after a defined time period
– Sometimes known as “Cache Aside”
– Reduces network calls for data
– Trades memory for speed
– More information here
• When to use
– Only use with static data
– Different clustered nodes “could” have different data for a short
time
• Tooling Support:
– I recommend Google Guava
– EHCache, Gemfire, and other tools available
©2015 Derek C. Ashmore, All Rights Reserved 28
Designing for Integrity
• Services are context independent
– Have no knowledge of how/when they are executed
• One service == One Transaction
– Two-phase commits/rollbacks are a much larger problem
• Common Patterns:
– Custom Rollback
• Write your own reversing transaction
©2015 Derek C. Ashmore, All Rights Reserved 29
Custom Rollback
©2015 Derek C. Ashmore, All Rights Reserved 30
Custom Rollback (continued)
• Reverses a transaction previously posted
• Only use this for multi-service transactions
– Keeping the transaction within one service is
preferred
• This pattern is completely custom
– No special product support available
• More information here
©2015 Derek C. Ashmore, All Rights Reserved 31
Agenda
The “What”
and “Why” of
microservices
Design
Considerations
and Patterns
Packaging
Options
The Fine Print
Summary /
Q&A
©2015 Derek C. Ashmore, All Rights Reserved 32
Packaging Support
• Microservices are deployed as a process
– For Java, embedded containers are easy
– Spring Boot
– Dropwizard
• Docker – standardizes the process deployment
and environment
©2015 Derek C. Ashmore, All Rights Reserved 33
Spring Boot
• Packages Java EE application into *one* deployment jar
– java –jar myApp.jar
• Support for health checks and other admin add ons via ‘Actuator’
add-on
• Supports either Jetty or Tomcat
• Best for ‘Spring-mvc’ apps
– For non-spring apps, it’s swimming upstream
• Required artifacts
– Maven
• spring-boot
• spring-boot-starter-jetty (tomcat is available)
• spring-boot-starter-actuator (optional – health checks, etc.)
– Application class with public static void main()
• Configuration coded (usually into the application class)
• Will read application.properties (app-specific properties)
©2015 Derek C. Ashmore, All Rights Reserved 34
Dropwizard
• Packages Java EE application into *one* deployment jar
– java –jar myApp.jar server myConfig.yaml
• Provides file configuration options (yaml format)
– Database connection pools
– Logging config
– Port and other container specs
• Provides easy metrics/healthcheck support
• Uses Jetty
• Required artifacts
– Application class (with main())
– Maven: dropwizard-core, maven-shade-plugin
©2015 Derek C. Ashmore, All Rights Reserved 35
Docker
• Is a “mini VM”
• runs a linux kernal
• Compare to
shipping container
• Standard
“connections” to
outside world
• Supported formally
by Oracle, Tomcat,
Jboss, and many
more
36©2015 Derek C. Ashmore, All Rights Reserved
Package Once, Run Anywhere!
Why Docker?
• Docker is Win-Win
– Easier for OPS and system administrators
• All software looks the same
• Standard interface for disk and network resources
– Containers can be “linked”
• Inherently automated
– Easier for developers
• Fewer environment difference issues
• Less to communicate to OPS / system administrators
• Easy to leverage work of others (docker-hub)
– If you haven’t tried Docker yet – you should!
©2015 Derek C. Ashmore, All Rights Reserved 37
Agenda
The “What”
and “Why” of
microservices
Design
Considerations
and Patterns
Packaging
Options
The Fine Print
Summary /
Q&A
©2015 Derek C. Ashmore, All Rights Reserved 38
Where’s the marketing fluff?
• Easier to manage
– Maybe
• You *must* be good at contract management
• You *must* be good at specifying precisely what a microservice
needs to do
• You *must* ensure that services make no assumptions on how
they get invoked
• Easier for developers to “understand” applications
– No – sorry
• It is easier to understand a particular ‘cog’ in the machine (e.g. the
function of one service
• It is *not* easier to understand how microservices fit together to
provide a particular piece of business functionality
©2015 Derek C. Ashmore, All Rights Reserved 39
Where’s the marketing fluff?
(continued)
• Increased Development Throughput
– Maybe
• Harder for business to ‘test’ a business function for a specific combination of
microservices
• Developers work on *one* service at a time.
• You *must* be good at error detection (unintended consequences)
• The more assumptions a service makes about its execution context, the more
unintended consequences (e.g. errors) you are likely to have on deployment
• Services become disposable and can be “replaced” instead of
“maintained / fixed”.
– Maybe
• It’s more easily replaced than when using traditional architectures
• Requires rigorous contract testing
– Can’t have the “replacement” act any differently than the original (except for the bug
being fixed, of course)
• Requires architecture support for cross-cutting concerns
– Can’t take a lot of time to implement / test
©2015 Derek C. Ashmore, All Rights Reserved 40
Further Reading
• Microservices reading list
– http://www.mattstine.com/microservices
• Microsoft’s Cloud Design Patterns
– https://msdn.microsoft.com/en-us/library/dn600223.aspx
• Moneta Java microservice example
– https://github.com/Derek-Ashmore/moneta
• This slide deck
– http://www.slideshare.net/derekashmore
©2015 Derek C. Ashmore, All Rights Reserved 41
Questions?
• Derek Ashmore:
– Blog: www.derekashmore.com
– LinkedIn: www.linkedin.com/in/derekashmore
– Twitter: https://twitter.com/Derek_Ashmore
– GitHub: https://github.com/Derek-Ashmore
– Book: http://dvtpress.com/
©2015 Derek C. Ashmore, All Rights Reserved 42
May 14-15, 2015
http://www.chicagocoderconference.com/

More Related Content

Viewers also liked

Microservices for java architects schamburg-2015-05-19
Microservices for java architects schamburg-2015-05-19Microservices for java architects schamburg-2015-05-19
Microservices for java architects schamburg-2015-05-19Derek Ashmore
 
Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)
Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)
Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)Derek Ashmore
 
Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10Derek Ashmore
 
Writing microservices in java java one-2015-10-28
Writing microservices in java java one-2015-10-28Writing microservices in java java one-2015-10-28
Writing microservices in java java one-2015-10-28Derek Ashmore
 
Microservices for architects los angeles-2016-07-16
Microservices for architects los angeles-2016-07-16Microservices for architects los angeles-2016-07-16
Microservices for architects los angeles-2016-07-16Derek Ashmore
 
Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Derek Ashmore
 
AWS Lambda Deployments: Best Practices and Common Mistakes O'Reilly Software...
AWS Lambda Deployments:  Best Practices and Common Mistakes O'Reilly Software...AWS Lambda Deployments:  Best Practices and Common Mistakes O'Reilly Software...
AWS Lambda Deployments: Best Practices and Common Mistakes O'Reilly Software...Derek Ashmore
 

Viewers also liked (7)

Microservices for java architects schamburg-2015-05-19
Microservices for java architects schamburg-2015-05-19Microservices for java architects schamburg-2015-05-19
Microservices for java architects schamburg-2015-05-19
 
Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)
Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)
Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)
 
Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10
 
Writing microservices in java java one-2015-10-28
Writing microservices in java java one-2015-10-28Writing microservices in java java one-2015-10-28
Writing microservices in java java one-2015-10-28
 
Microservices for architects los angeles-2016-07-16
Microservices for architects los angeles-2016-07-16Microservices for architects los angeles-2016-07-16
Microservices for architects los angeles-2016-07-16
 
Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15
 
AWS Lambda Deployments: Best Practices and Common Mistakes O'Reilly Software...
AWS Lambda Deployments:  Best Practices and Common Mistakes O'Reilly Software...AWS Lambda Deployments:  Best Practices and Common Mistakes O'Reilly Software...
AWS Lambda Deployments: Best Practices and Common Mistakes O'Reilly Software...
 

Similar to Microservices for java architects coders-conf-2015-05-15

Microservices for Architects - Atlanta 2018-03-28
Microservices for Architects - Atlanta 2018-03-28Microservices for Architects - Atlanta 2018-03-28
Microservices for Architects - Atlanta 2018-03-28Derek Ashmore
 
Refactoring Into Microservices 2016-11-08
Refactoring Into Microservices 2016-11-08Refactoring Into Microservices 2016-11-08
Refactoring Into Microservices 2016-11-08Derek Ashmore
 
Refactoring Into Microservices 2016-11-06
Refactoring Into Microservices 2016-11-06Refactoring Into Microservices 2016-11-06
Refactoring Into Microservices 2016-11-06Derek Ashmore
 
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26Derek Ashmore
 
Get Loose! Microservices and Loosely Coupled Architectures
Get Loose! Microservices and Loosely Coupled ArchitecturesGet Loose! Microservices and Loosely Coupled Architectures
Get Loose! Microservices and Loosely Coupled ArchitecturesDeborah Schalm
 
Get Loose! Microservices and Loosely Coupled Architectures
Get Loose! Microservices and Loosely Coupled Architectures Get Loose! Microservices and Loosely Coupled Architectures
Get Loose! Microservices and Loosely Coupled Architectures DevOps.com
 
Microservices - Scaling Development and Service
Microservices - Scaling Development and ServiceMicroservices - Scaling Development and Service
Microservices - Scaling Development and ServicePaulo Gaspar
 
Implementing DevOps Automation Best Practices and Common Mistakes
Implementing DevOps AutomationBest Practices and Common MistakesImplementing DevOps AutomationBest Practices and Common Mistakes
Implementing DevOps Automation Best Practices and Common MistakesDerek Ashmore
 
BMC Engage 2015 Breakout Session #420 - #ITSM_SUCCESS-Final_3.5 (1)
BMC Engage 2015 Breakout Session #420 - #ITSM_SUCCESS-Final_3.5 (1)BMC Engage 2015 Breakout Session #420 - #ITSM_SUCCESS-Final_3.5 (1)
BMC Engage 2015 Breakout Session #420 - #ITSM_SUCCESS-Final_3.5 (1)Phil Bautista
 
Microservices
MicroservicesMicroservices
MicroservicesPT.JUG
 
Service Architectures at Scale
Service Architectures at ScaleService Architectures at Scale
Service Architectures at ScaleRandy Shoup
 
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...Startupfest
 
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018Derek Ashmore
 
apidays LIVE Australia - The Evolution of APIs: Events and the AsyncAPI speci...
apidays LIVE Australia - The Evolution of APIs: Events and the AsyncAPI speci...apidays LIVE Australia - The Evolution of APIs: Events and the AsyncAPI speci...
apidays LIVE Australia - The Evolution of APIs: Events and the AsyncAPI speci...apidays
 
Service Architectures At Scale - QCon London 2015
Service Architectures At Scale - QCon London 2015Service Architectures At Scale - QCon London 2015
Service Architectures At Scale - QCon London 2015Randy Shoup
 
Cloud-native Data: Every Microservice Needs a Cache
Cloud-native Data: Every Microservice Needs a CacheCloud-native Data: Every Microservice Needs a Cache
Cloud-native Data: Every Microservice Needs a Cachecornelia davis
 
Quantifying Genuine User Experience in Virtual Desktop Ecosystems
Quantifying Genuine User Experience in Virtual Desktop EcosystemsQuantifying Genuine User Experience in Virtual Desktop Ecosystems
Quantifying Genuine User Experience in Virtual Desktop EcosystemsData Con LA
 
Introduction-to-Cloud-Computing.pdf
Introduction-to-Cloud-Computing.pdfIntroduction-to-Cloud-Computing.pdf
Introduction-to-Cloud-Computing.pdfprajwalalaladinni
 
Citrix Troubleshooting 101: How to Resolve and Prevent Business-Impacting Cit...
Citrix Troubleshooting 101: How to Resolve and Prevent Business-Impacting Cit...Citrix Troubleshooting 101: How to Resolve and Prevent Business-Impacting Cit...
Citrix Troubleshooting 101: How to Resolve and Prevent Business-Impacting Cit...eG Innovations
 

Similar to Microservices for java architects coders-conf-2015-05-15 (20)

Microservices for Architects - Atlanta 2018-03-28
Microservices for Architects - Atlanta 2018-03-28Microservices for Architects - Atlanta 2018-03-28
Microservices for Architects - Atlanta 2018-03-28
 
Refactoring Into Microservices 2016-11-08
Refactoring Into Microservices 2016-11-08Refactoring Into Microservices 2016-11-08
Refactoring Into Microservices 2016-11-08
 
Refactoring Into Microservices 2016-11-06
Refactoring Into Microservices 2016-11-06Refactoring Into Microservices 2016-11-06
Refactoring Into Microservices 2016-11-06
 
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
 
Get Loose! Microservices and Loosely Coupled Architectures
Get Loose! Microservices and Loosely Coupled ArchitecturesGet Loose! Microservices and Loosely Coupled Architectures
Get Loose! Microservices and Loosely Coupled Architectures
 
Get Loose! Microservices and Loosely Coupled Architectures
Get Loose! Microservices and Loosely Coupled Architectures Get Loose! Microservices and Loosely Coupled Architectures
Get Loose! Microservices and Loosely Coupled Architectures
 
Microservices - Scaling Development and Service
Microservices - Scaling Development and ServiceMicroservices - Scaling Development and Service
Microservices - Scaling Development and Service
 
Implementing DevOps Automation Best Practices and Common Mistakes
Implementing DevOps AutomationBest Practices and Common MistakesImplementing DevOps AutomationBest Practices and Common Mistakes
Implementing DevOps Automation Best Practices and Common Mistakes
 
BMC Engage 2015 Breakout Session #420 - #ITSM_SUCCESS-Final_3.5 (1)
BMC Engage 2015 Breakout Session #420 - #ITSM_SUCCESS-Final_3.5 (1)BMC Engage 2015 Breakout Session #420 - #ITSM_SUCCESS-Final_3.5 (1)
BMC Engage 2015 Breakout Session #420 - #ITSM_SUCCESS-Final_3.5 (1)
 
Microservices
MicroservicesMicroservices
Microservices
 
Service Architectures at Scale
Service Architectures at ScaleService Architectures at Scale
Service Architectures at Scale
 
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
 
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
 
apidays LIVE Australia - The Evolution of APIs: Events and the AsyncAPI speci...
apidays LIVE Australia - The Evolution of APIs: Events and the AsyncAPI speci...apidays LIVE Australia - The Evolution of APIs: Events and the AsyncAPI speci...
apidays LIVE Australia - The Evolution of APIs: Events and the AsyncAPI speci...
 
Service Architectures At Scale - QCon London 2015
Service Architectures At Scale - QCon London 2015Service Architectures At Scale - QCon London 2015
Service Architectures At Scale - QCon London 2015
 
Cloud-native Data: Every Microservice Needs a Cache
Cloud-native Data: Every Microservice Needs a CacheCloud-native Data: Every Microservice Needs a Cache
Cloud-native Data: Every Microservice Needs a Cache
 
WHISHWORKS-MuleSoft Hyderabad Meetup -April 2019
WHISHWORKS-MuleSoft Hyderabad Meetup -April 2019WHISHWORKS-MuleSoft Hyderabad Meetup -April 2019
WHISHWORKS-MuleSoft Hyderabad Meetup -April 2019
 
Quantifying Genuine User Experience in Virtual Desktop Ecosystems
Quantifying Genuine User Experience in Virtual Desktop EcosystemsQuantifying Genuine User Experience in Virtual Desktop Ecosystems
Quantifying Genuine User Experience in Virtual Desktop Ecosystems
 
Introduction-to-Cloud-Computing.pdf
Introduction-to-Cloud-Computing.pdfIntroduction-to-Cloud-Computing.pdf
Introduction-to-Cloud-Computing.pdf
 
Citrix Troubleshooting 101: How to Resolve and Prevent Business-Impacting Cit...
Citrix Troubleshooting 101: How to Resolve and Prevent Business-Impacting Cit...Citrix Troubleshooting 101: How to Resolve and Prevent Business-Impacting Cit...
Citrix Troubleshooting 101: How to Resolve and Prevent Business-Impacting Cit...
 

Recently uploaded

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Recently uploaded (20)

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

Microservices for java architects coders-conf-2015-05-15

  • 1. Micro Services for Java Architects Given by Derek C. Ashmore May 15, 2015 ©2015 Derek C. Ashmore, All Rights Reserved 1
  • 2. Who am I? • Professional Geek since 1987 • Java/J2EE/Java EE since 1999 • Roles include: • Developer • Architect • Project Manager • DBA • System Admin ©2015 Derek C. Ashmore, All Rights Reserved 2
  • 3. Discussion Resources • This slide deck – http://www.slideshare.net/derekashmore • Sample code on my Github – https://github.com/Derek-Ashmore/ • Sample Java Microservice (Moneta) – https://github.com/Derek-Ashmore/moneta • Slide deck has hyper-links! – Don’t bother writing down URLs ©2015 Derek C. Ashmore, All Rights Reserved 3
  • 4. Agenda The “What” and “Why” of microservices Design Considerations and Patterns Packaging Options The Fine Print Summary / Q&A ©2015 Derek C. Ashmore, All Rights Reserved 4
  • 5. What are Microservices? • No concrete definition • Common microservice traits – Single functional purpose • Most/all changes only impact one service • Not dependent on execution context – “loosely coupled” – Independent process/jvm – Standard Interface (typically Web Service/REST) – Analogy: Stereo system, Linux utilities ©2015 Derek C. Ashmore, All Rights Reserved 5
  • 6. Traditional Java EE Application Architecture • Like a layer cake • Highly cohesive • Defined dependencies • Deployed as one unit (war/ear) • Limited Scalability • Code Size ©2015 Derek C. Ashmore, All Rights Reserved 6
  • 7. What is a Monolith? • Hard to change – QA test cycles are long – Change causes unintended consequences • Hard to onboard new developers • Married to your technical stack • Harder to diagnose bottlenecks and memory issues ©2015 Derek C. Ashmore, All Rights Reserved 7
  • 8. Refactoring into Microservices • Large benefits to unified user interface • Databases introduce unwanted coupling between services ©2015 Derek C. Ashmore, All Rights Reserved 8
  • 9. Refactoring further • Databases physically separated • What to do with common data needs? • Service call or • Data copy ©2015 Derek C. Ashmore, All Rights Reserved 9
  • 10. No Lock-in • Platform agnostic • Fewer dependency conflicts • Still have cross-cutting concerns • “Toll” for first app • Still have support concerns • Others need to be able to support your work 10©2015 Derek C. Ashmore, All Rights Reserved
  • 11. Easier Management / Higher Throughput • Easier to manage large numbers of developers – Concentrate on intelligently drawing service boundaries – Manage/enforce service contracts • Each service team works independently • Team independence leads to higher development throughput ©2015 Derek C. Ashmore, All Rights Reserved 11
  • 12. Isn’t this SOA? • Yes – More or less • No concrete definitions • SOA == dumb endpoints and smart routes – ESB routes using Mule, Camel, etc. – Transformations en route • MS == dumb routes and smart end-points – Simple routes • Usually REST or Soap calls via http(s) • Persistent queue route at it’s most complex • Analogy: Electrical supply for Stereo ©2015 Derek C. Ashmore, All Rights Reserved 12
  • 13. Agenda The “What” and “Why” of microservices Design Considerations and Patterns Packaging Options The Fine Print Summary / Q&A ©2015 Derek C. Ashmore, All Rights Reserved 13
  • 14. Design considerations • Service Boundaries (gerrymandering) • Service call Failure / Unavailability • Data Integrity • Performance ©2015 Derek C. Ashmore, All Rights Reserved 14
  • 15. Service Boundaries • Core Services – Services responsible for maintaining a specific business area data – Usually named after Nouns • Service is a system of record for a <blank> – Student, Course, Classroom, etc. • Process Services – Services responsible for performing single complex tasks – Usually represents an Action or Process • Service is responsible for processing <blank> – Student applications, Debt collection, etc. – These services rely on core services • Partitioning is an art – Too few  same drawbacks as traditional architecture – Too many  excessive network hops ©2015 Derek C. Ashmore, All Rights Reserved 15
  • 16. Boundary Sanity Check • Verbalize a mission statement in one sentence in business terms – Examples • This service is the system of record for Student information • This service registers students for classes • This service suspends students • This service records student payments • This service produces official transcripts ©2015 Derek C. Ashmore, All Rights Reserved 16
  • 17. Context Independence Check • Does your service have multiple consumers? – Could it? • Could your service execute as easily in batch as online? – If ‘No’, then you’re making context assumptions • Warning Signs – Spending time analyzing service call flow • Your services likely make context assumptions – Agonizing over which service should do a given activity • Maybe you need a new service ©2015 Derek C. Ashmore, All Rights Reserved 17
  • 18. Microservices are not about size ©2015 Derek C. Ashmore, All Rights Reserved 18 ….. Microservices are about having a single business purpose!
  • 19. Designing for Failure • Dependent services could be down – Minimize human intervention – Fail sooner rather than later – Horizontal scaling / clustering is your first line of defense – Coding patterns can help as a backup • Common Patterns: – Retry – Circuit Breaker – Dispatch via Messaging ©2015 Derek C. Ashmore, All Rights Reserved 19
  • 20. Retry Pattern ©2015 Derek C. Ashmore, All Rights Reserved 20 • Best for asynchronous tasks • Limit the number of tries • Use sleep interval between tries • Only addresses temporary outages • Sample Retry Pattern implementation here. • Tooling Support: – Apache CXF supports Retry – Spring Batch RetryTemplate – Apache HttpClient (Example here)
  • 21. Circuit Breaker ©2015 Derek C. Ashmore, All Rights Reserved 21
  • 22. Circuit Breaker (continued) • Objective: Error out sooner – Conserves resources – Automatically “recovers” after a time period • Modeled after home circuit • Works on thresholds – Number of errors required to trip circuit – Amount of time required to attempt retry • Has Hysterix support • Best embedded in interface clients / delegates • More information here. • Sample Circuit implementation here. ©2015 Derek C. Ashmore, All Rights Reserved 22
  • 23. Dispatch via Messaging ©2015 Derek C. Ashmore, All Rights Reserved 23 • Place work instruction on persistent queue • If receivers are down, work stacks in queue • Work throttled by number of receivers • Queue can be JMS or AMQP • Tooling Support: – JMS Api (easy API – many use natively) – Spring JMSTemplate or RabbitTemplate (producer)
  • 24. Designing for Performance • More network traffic – Make services course-grained – User Interfaces need a general manager – Horizontal or Vertical Scaling helps • Common Patterns: – Back-ends for Front-ends (a.k.a. API Gateway) – Dispatch via Messaging – Expiring Cache ©2015 Derek C. Ashmore, All Rights Reserved 24
  • 25. Back-ends for Front-ends ©2015 Derek C. Ashmore, All Rights Reserved 25
  • 26. Back-ends for Front-ends (continued) • Consolidates service calls for the browser – Enhances performance • Open web often not as performant as local LAN • Also known as “API Gateway” • Implications – Don’t expose microservices directly to the browser ©2015 Derek C. Ashmore, All Rights Reserved 26
  • 27. Expiring Cache ©2015 Derek C. Ashmore, All Rights Reserved 27
  • 28. Expiring Cache (continued) • Look up data once and cache it – Evict data from the cache after a defined time period – Sometimes known as “Cache Aside” – Reduces network calls for data – Trades memory for speed – More information here • When to use – Only use with static data – Different clustered nodes “could” have different data for a short time • Tooling Support: – I recommend Google Guava – EHCache, Gemfire, and other tools available ©2015 Derek C. Ashmore, All Rights Reserved 28
  • 29. Designing for Integrity • Services are context independent – Have no knowledge of how/when they are executed • One service == One Transaction – Two-phase commits/rollbacks are a much larger problem • Common Patterns: – Custom Rollback • Write your own reversing transaction ©2015 Derek C. Ashmore, All Rights Reserved 29
  • 30. Custom Rollback ©2015 Derek C. Ashmore, All Rights Reserved 30
  • 31. Custom Rollback (continued) • Reverses a transaction previously posted • Only use this for multi-service transactions – Keeping the transaction within one service is preferred • This pattern is completely custom – No special product support available • More information here ©2015 Derek C. Ashmore, All Rights Reserved 31
  • 32. Agenda The “What” and “Why” of microservices Design Considerations and Patterns Packaging Options The Fine Print Summary / Q&A ©2015 Derek C. Ashmore, All Rights Reserved 32
  • 33. Packaging Support • Microservices are deployed as a process – For Java, embedded containers are easy – Spring Boot – Dropwizard • Docker – standardizes the process deployment and environment ©2015 Derek C. Ashmore, All Rights Reserved 33
  • 34. Spring Boot • Packages Java EE application into *one* deployment jar – java –jar myApp.jar • Support for health checks and other admin add ons via ‘Actuator’ add-on • Supports either Jetty or Tomcat • Best for ‘Spring-mvc’ apps – For non-spring apps, it’s swimming upstream • Required artifacts – Maven • spring-boot • spring-boot-starter-jetty (tomcat is available) • spring-boot-starter-actuator (optional – health checks, etc.) – Application class with public static void main() • Configuration coded (usually into the application class) • Will read application.properties (app-specific properties) ©2015 Derek C. Ashmore, All Rights Reserved 34
  • 35. Dropwizard • Packages Java EE application into *one* deployment jar – java –jar myApp.jar server myConfig.yaml • Provides file configuration options (yaml format) – Database connection pools – Logging config – Port and other container specs • Provides easy metrics/healthcheck support • Uses Jetty • Required artifacts – Application class (with main()) – Maven: dropwizard-core, maven-shade-plugin ©2015 Derek C. Ashmore, All Rights Reserved 35
  • 36. Docker • Is a “mini VM” • runs a linux kernal • Compare to shipping container • Standard “connections” to outside world • Supported formally by Oracle, Tomcat, Jboss, and many more 36©2015 Derek C. Ashmore, All Rights Reserved Package Once, Run Anywhere!
  • 37. Why Docker? • Docker is Win-Win – Easier for OPS and system administrators • All software looks the same • Standard interface for disk and network resources – Containers can be “linked” • Inherently automated – Easier for developers • Fewer environment difference issues • Less to communicate to OPS / system administrators • Easy to leverage work of others (docker-hub) – If you haven’t tried Docker yet – you should! ©2015 Derek C. Ashmore, All Rights Reserved 37
  • 38. Agenda The “What” and “Why” of microservices Design Considerations and Patterns Packaging Options The Fine Print Summary / Q&A ©2015 Derek C. Ashmore, All Rights Reserved 38
  • 39. Where’s the marketing fluff? • Easier to manage – Maybe • You *must* be good at contract management • You *must* be good at specifying precisely what a microservice needs to do • You *must* ensure that services make no assumptions on how they get invoked • Easier for developers to “understand” applications – No – sorry • It is easier to understand a particular ‘cog’ in the machine (e.g. the function of one service • It is *not* easier to understand how microservices fit together to provide a particular piece of business functionality ©2015 Derek C. Ashmore, All Rights Reserved 39
  • 40. Where’s the marketing fluff? (continued) • Increased Development Throughput – Maybe • Harder for business to ‘test’ a business function for a specific combination of microservices • Developers work on *one* service at a time. • You *must* be good at error detection (unintended consequences) • The more assumptions a service makes about its execution context, the more unintended consequences (e.g. errors) you are likely to have on deployment • Services become disposable and can be “replaced” instead of “maintained / fixed”. – Maybe • It’s more easily replaced than when using traditional architectures • Requires rigorous contract testing – Can’t have the “replacement” act any differently than the original (except for the bug being fixed, of course) • Requires architecture support for cross-cutting concerns – Can’t take a lot of time to implement / test ©2015 Derek C. Ashmore, All Rights Reserved 40
  • 41. Further Reading • Microservices reading list – http://www.mattstine.com/microservices • Microsoft’s Cloud Design Patterns – https://msdn.microsoft.com/en-us/library/dn600223.aspx • Moneta Java microservice example – https://github.com/Derek-Ashmore/moneta • This slide deck – http://www.slideshare.net/derekashmore ©2015 Derek C. Ashmore, All Rights Reserved 41
  • 42. Questions? • Derek Ashmore: – Blog: www.derekashmore.com – LinkedIn: www.linkedin.com/in/derekashmore – Twitter: https://twitter.com/Derek_Ashmore – GitHub: https://github.com/Derek-Ashmore – Book: http://dvtpress.com/ ©2015 Derek C. Ashmore, All Rights Reserved 42 May 14-15, 2015 http://www.chicagocoderconference.com/