A Pattern Language For Microservices Chris Richardson
A Pattern Language For Microservices Chris Richardson
microservices
Chris Richardson
@crichardson
[email protected]
http://plainoldobjects.com
http://microservices.io
http://eventuate.io
@crichardson
Presentation goal
@crichardson
About Chris
@crichardson
About Chris
@crichardson
For more information
https://github.com/cer/event-sourcing-examples
http://microservices.io
http://plainoldobjects.com/
https://twitter.com/crichardson
http://eventuate.io/
@crichardson
Agenda
Core patterns
Deployment patterns
Communication patterns
@crichardson
In 1986…
http://en.wikipedia.org/wiki/Fred_Brooks
@crichardson
Yet almost 30 years later
developers are still
passionately arguing over
“silver bullets”
@crichardson
Suck/Rock Dichotomy
JavaScript vs. Java
http://nealford.com/memeagora/2009/08/05/suck-rock-dichotomy.html
@crichardson
Gartner Hype Cycle
Trade-offs
understood
http://upload.wikimedia.org/wikipedia/commons/b/bf/Hype-Cycle-General.png @crichardson
How we make decisions
Rationalize with
our intellect
Decide
using
emotions
http://en.wikipedia.org/wiki/Mahout
@crichardson
We need a better way
to discuss and think
about technology
@crichardson
What’s a pattern?
Reusable solution
to a problem
occurring
in a particular context
@crichardson
The structure of a pattern
=
Problem
(conflicting) issues
etc to address
Forces
Solution
Resulting context
Related patterns
@crichardson
Benefits
Issues to resolve
@crichardson
Alternative solutions
Related patterns
Solutions to problems
introduced by this pattern
@crichardson
Pattern language
A collection of related
patterns that solve problems Access to Water
in a particular domain
Relationships Promenade
Pattern A results in a
context that has a problem Local townhall
solved by Pattern B
Patterns A and B solve the Intimacy gradient
same problem
Pattern A is a Light on two sides
specialization of pattern B
http://en.wikipedia.org/wiki/A_Pattern_Language
Meta-pattern
in
Solution A Solution B Container
General Specific
progress
Deployment
Service-per-VM
Multiple Services
per host
Monolithic Microservice
architecture architecture
Partitioning
API gateway
Server-side
Communication Client-side discovery
discovery
Style
Remote Procedure
Messaging
Invocation
Service registry
Discovery
http://microservices.io/
@crichardson
Agenda
Core patterns
Deployment patterns
Communication patterns
@crichardson
@crichardson
Let’s imagine you are
building an online store
REST/JSON
Browser/
StoreFrontUI
Client HTML
Product Info
Service
Recommendation SQL
Service Database
Review Service
Order Service
@crichardson
Problem: what’s the
deployment architecture?
@crichardson
Forces
Do continuous deployment
@crichardson
Pattern: Monolithic
architecture
WAR/EAR
StoreFrontUI
HTML
Product Info
REST/JSON
Browser/ Service MySQL
Client Database
Recommendation
Service
@crichardson
But when the application is
large …
@crichardson
Intimidates developers
@crichardson
Obstacle to frequent
deployments
Need to redeploy everything to change one component
Interrupts long running background (e.g. Quartz) jobs
Eggs in
Increases risk of failure
one basket
Fear of change
@crichardson
Pattern: Microservice
architecture
@crichardson
Apply functional
decomposition
Y axis -
functional
decomposition
Scale by
splitting
sim ing
r
in in ion
ila
different things
th litt rtit
sp pa
gs g
by ata
ale - d
is
ax
Z
Sc
X axis
- horizontal duplication @crichardson
Microservice architecture
Product
ProductInfo
Info
Browse Products Service
UI
Recommendation
Checkout UI Service
Account
management UI Order
Service
http://highscalability.com/amazon-architecture
100-150 services to build a page
http://www.addsimplicity.com/downloads/
eBaySDForum2006-11-29.pdf
http://queue.acm.org/detail.cfm?id=1394128
@crichardson
Benefits
Smaller, simpler apps
Easier to understand and develop
Less jar/classpath hell - who needs OSGI?
Faster to build and deploy
Scales development: develop, deploy and scale each service independently
Improves fault isolation
Eliminates long-term commitment to a single technology stack
System level architecture vs. service level architecture
Easily and safely experiment with new technologies
@crichardson
Drawbacks
Complexity of developing a distributed system
Implementing inter-process communication
Handling partial failures
Implementing business transactions that span multiple databases
(without 2PC)
Complexity of testing a distributed system
Complexity of deploying and operating a distributed system
Managing the development and deployment of features that span
multiple services
@crichardson
Issues to address
How to deploy the services?
@crichardson
Agenda
Core patterns
Deployment patterns
Communication patterns
@crichardson
We have applied the
microservices pattern:
@crichardson
Forces
Services are written using a variety of languages, frameworks, and
framework versions
Each service consists of multiple service instances for throughput and
availability
Building and deploying a service must be fast
Service must be deployed and scaled independently
Service instances need to be isolated
Resources consumed by a service must be constrained
Deployment must be cost-effective
@crichardson
@crichardson
Pattern: Multiple service
instances per host
Host (Physical or VM)
Process
WAR
OSGI bundle
@crichardson
Benefits and drawbacks
Benefits Drawbacks
Efficient resource utilization Poor/Terrible isolation
Fast deployment Poor visibility (with WAR/OSGI
deployment)
Difficult to limit resource utilization
Risk of dependency version
conflicts
Poor encapsulation of
implementation technology
Pattern: Service instance per
host
@crichardson
Pattern: Service per VM host
VM
Service
deployed as
packaged as VM
Service
image VM
Service
VM
Service
@crichardson
Example
http://techblog.netflix.com/
~600 services
Leverage AWS
infrastructure for
Autoscaling/Load balancing
Pattern: Service per Container
host VM
Container
Service
deployed as
VM
Container
Service
@crichardson
Examples
@crichardson
Benefits and drawbacks
Benefits Drawbacks
Container encapsulates
implementation technology
Fast deployment
Agenda
Core patterns
Deployment patterns
Communication patterns
@crichardson
Communication issues
The System
How do clients of the
system interact with the How do services
services? within the system
Service A interact?
System Client
Service B
Service C
@crichardson
@crichardson
The problem of discovery
Dynamically
Dynamically changing
assigned
Client or API
gateway 10.4.3.1:8756
Service
Instance A
?
10.4.3.99:4545
Service Service
Client Instance B
10.4.3.20:333
Service
How to load Instance C
balance?
@crichardson
Pattern: Client-side discovery
load 10.4.3.1:8756
Service
balance Instance A
Registry-
Service aware request 10.4.3.99:4545
Client HTTP
Service
Client
Instance B
10.4.3.20:333
query Service
Instance C
register
Service
Registry
@crichardson
Example: Netflix Eureka and Ribbon
https://github.com/Netflix/eureka/wiki/Eureka-at-a-glance
https://github.com/Netflix/ribbon @crichardson
Benefits and drawbacks
Benefits Drawbacks
Flexible, application-specific Couples the client to the
load balancing Service Registry
Fewer network hops and Need implement client-side
moving parts compared to discovery and load balancing
Server-side discovery
logic in multiple languages/
frameworks
Service Registry is yet
another moving part to setup
and operate - highly available
Pattern: Server-side discovery
10.4.3.1:8756
Service
Instance A
load 10.4.3.99:4545
request balance
Service Router Service
Client request Instance B
10.4.3.20:333
query Service
Instance C
register
Service
Registry
@crichardson
Public
Example ELB
Internal
ELB Internal
ELB
http://docs.aws.amazon.com/ElasticLoadBalancing/latest/
DeveloperGuide/vpc-loadbalancer-types.html
@crichardson
Benefits and drawbacks
Benefits Drawbacks
Apply technology
@crichardson
Summary: The Microservices pattern
language is a great way to …
@crichardson
@crichardson [email protected]
Questions?
http://plainoldobjects.com http://microservices.io
http://bit.ly/trialeventuate @crichardson