A pattern language for microservices

Pivotal 1,458 views 76 slides Jun 26, 2017
Slide 1
Slide 1 of 76
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76

About This Presentation

CHRIS RICHARDSON FOUNDER, EVENTUATE
When architecting an enterprise Java application, you need to choose between the traditional monolithic architecture consisting of a single large WAR file, or the more fashionable microservices architecture consisting of many smaller services. But rather than blin...


Slide Content

@crichardson
A pattern language for
microservices
Chris Richardson
Founder of Eventuate.io
Founder of the original CloudFoundry.com
Author of POJOs in Action
@crichardson
[email protected]
http://microservices.io
http://eventuate.io
http://plainoldobjects.com

@crichardson
Presentation goal
Why patterns and pattern
languages?
A pattern language for
microservices

@crichardson
About Chris

@crichardson
About Chris
Consultant and trainer
focusing on modern
application architectures
including microservices
(http://www.chrisrichardson.net/)

@crichardson
About Chris
Founder of Eventuate, Inc
Creating a platform that makes it
easy for application developers to
write microservices
(http://eventuate.io)

@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
Why a pattern language for microservices?
Core patterns
Deployment patterns
Communication patterns and more

@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
Popular silver bullets
Functional programming

@crichardson
Suck/Rock Dichotomy
Spring vs. Java EE
JavaScript vs. Java
Functional programming vs. Object-oriented
http://nealford.com/memeagora/2009/08/05/suck-rock-dichotomy.html
Containers vs. Virtual Machines

@crichardson
Gartner Hype Cycle
http://upload.wikimedia.org/wikipedia/commons/b/bf/Hype-Cycle-General.png
It’s
awesome
It’s not
awesome
Trade-offs
understood

@crichardson
How we make decisions
Decide
using
emotions
Rationalize with
our intellect
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
=
Great framework for discussing
and thinking about technology

@crichardson
The structure of a pattern
Resulting context
aka the situation
Name
Context
Problem
Related patterns
(conflicting) issues
etc to address
Forces
Solution

@crichardson
Resulting context
Benefits
Drawbacks
Issues to resolve

@crichardson
Related patterns
Alternative solutions
Solutions to problems
introduced by this pattern

Pattern language
A collection of related
patterns that solve problems
in a particular domain
Relationships
Pattern A results in a
context that has a problem
solved by Pattern B
Patterns A and B solve the
same problem
Pattern A is a
specialization of pattern B
http://en.wikipedia.org/wiki/A_Pattern_Language
Access to Water
Promenade
Local townhall
Intimacy gradient
Light on two sides

@crichardson
Meta-pattern
Problem: How to talk/reason about technology?
Solution: Use the pattern format
Benefit: More objective
Drawback: Less exciting
Context: Emotional software development culture
Related patterns: It’s awesome!

@crichardson
Work
in
progress
http://microservices.io/
Monolithic
architecture Microservice
architecture
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Deployment
Discovery
Data
Communication
Service-per-VM
Partitioning
Messaging
Remote Procedure
Invocation
Style
Core
Database per
Service
Event-driven
architecture
Event
sourcing
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific

@crichardson
Agenda
Why a pattern language for microservices?
Core patterns
Deployment patterns
Communication patterns and more

@crichardson

@crichardson
Let’s imagine you are
building an online store
Browser/
Client
SQL
Database
Review Service
Catalog
Service
Recommendation
Service
StoreFrontUI
Order Service
HTML
REST/JSON

@crichardson
Problem: what’s the
deployment architecture?

@crichardson
Forces
Businesses must innovate
faster
<z
Develop more complex,
higher-quality software faster

@crichardson
Forces
Developers must be productive
The code must be easy to understand and modify
Continuous deployment of applications
Developers must leverage emerging technologies
(frameworks, programming languages, etc)
Deploy multiple application instances for scalability and
availability

@crichardson
Tomcat
Pattern: Monolithic
architecture
Browser/
Client
WAR/EAR
MySQL
Database
Review Service
Catalog
Service
Recommendation
Service
StoreFrontUI
Order Service
HTML
REST/JSON

@crichardson
Examples everywhere

@crichardson
Simple to ….
Develop
Test
Deploy
Scale

@crichardson
Successful applications
have a habit of growing
<z
Big, complex, monolithic
applications

@crichardson
Agile development and deployment
becomes impossible

@crichardson
Intimidates developers

@crichardson
Obstacle to frequent
deployments
Need to redeploy everything to change one component
Interrupts long running background (e.g. Quartz) jobs
Increases risk of failure
Fear of change
Updates will happen less often - really long QA cycles
e.g. Makes A/B testing UI really difficult
Eggs in
one basket

@crichardson
Scaling the application can be
challenging
Memory intensive CPU intensive
IO intensive
Conflicting
Needs

@crichardson
Overloads your IDE and
container
Slows down development

@crichardson
Lots of coordination and
communication required
Requires lots of coordination
I want to update
the UI
But
the backend is not working
yet!

@crichardson
Requires long-term
commitment to a
technology stack

@crichardson
Pattern: Microservice
architecture

@crichardson
Apply functional
decomposition
X axis
- horizontal duplication
Z axis - data partitioning
Y axis -
functional
decomposition
Scale by splitting similar
things
Scale by
splitting
different things

@crichardson
Catalog
Microservice architecture
Catalog
Service
Recommendation
Service
Review
Service
Order
Service
Browse Products
UI
Checkout UI
Order management
UI
Account
management UI
Apply X-axis and Z-axis scaling
to each service independently

@crichardson
Goal of partitioning:
Most changes affect only a single
service
<z
Develop and deploy independently
in parallel with other changes

@crichardson
Goal of partitioning:
Separate components with
conflicting resource
requirements
<z
Scale more easily

@crichardson
http://highscalability.com/amazon-architecture
http://techblog.netflix.com/
http://www.addsimplicity.com/downloads/
eBaySDForum2006-11-29.pdf
http://queue.acm.org/detail.cfm?id=1394128
~600 services
100-150 services to build a page
Examples of microservices

@crichardson
http://bit.ly/msexample_yelp
http://bit.ly/msexample_soundcloud
http://bit.ly/msexample_uber
Examples of microservices

@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
Easier scaling
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

@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
Fortunately solutions exists

@crichardson
The benefits typically
outweigh the drawbacks
for
large, complex applications

@crichardson
Issues to address
How to deploy the services?
How do the services communicate?
How do clients of the application communicate with the
services?
How to partition the system into services?
How to deal with distributed data management problems?
….

@crichardson
Agenda
Why a pattern language for microservices?
Core patterns
Deployment patterns
Communication patterns and more

@crichardson
We have applied the
microservices pattern:
How to deploy the services?

@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 reliable
Deployment must be cost-effective

@crichardson

@crichardson
Pattern: Multiple service
instances per host
Host (Physical or VM)
Service-A
Instance-1
Service-B
Instance-2
Service-C
Instance-2
Process
WAR
OSGI bundle

Benefits and drawbacks
Benefits
Efficient resource utilization
Fast deployment
Drawbacks
Poor/Terrible isolation
Poor visibility (with WAR/OSGI
deployment)
Difficult to limit resource utilization
Risk of dependency version
conflicts
Poor encapsulation of
implementation technology

@crichardson
Pattern: Service instance per
host

@crichardson
Pattern: Service per VM host
Service
VM
image
VM
Service
VM
Service
VM
Service
packaged as
deployed as

@crichardson
Example
http://techblog.netflix.com/
~600 services
packer.io is a great tool

Benefits and drawbacks
Benefits
Great isolation
Great manageability
VM encapsulates
implementation technology
Leverage AWS
infrastructure for
Autoscaling/Load balancing

Drawbacks
Less efficient resource
utilization
Slow deployment

@crichardson
VM
VM
Pattern: Service per Container
host
Service
Container
image
Container
Service
Container
Service
Container
Service
packaged as
deployed as

@crichardson

@crichardson
Docker clustering solutions
https://www.dchq.io/landing/index.html

Benefits and drawbacks
Benefits
Great isolation
Great manageability
Container encapsulates
implementation technology
Efficient resource utilization
Fast deployment
Drawbacks
Immature infrastructure for
deploying containers

@crichardson
Agenda
Why a pattern language for microservices?
Core patterns
Deployment patterns
Communication patterns and more

@crichardson
Communication issues
System Client
Service A
Service B
Service C
The System
How do clients of the
system interact with the
services?
How do services
within the system
interact?

@crichardson
How do external clients
interact with the microsevices?

@crichardson
How do services communicate
with each other?

@crichardson
How does a client determine the
network location of a service?

@crichardson
What’s the database
architecture?

Database per Service
Orders Service
Customer
Service
Order
Database
Customer
Database
Sharded SQL
NoSQL DB

How to solve distributed data
management challenges?
How to implement
transactions that span
multiple services?
How to implement queries
that span multiple
services?

@crichardson
Summary: Patterns and pattern
languages are a great way to …
Think about technology
Discuss technology
Apply technology

@crichardson
Summary: The Microservices pattern
language is a great way to …
Think about microservices
Discuss microservices
Apply microservices (or not)

@crichardson
@crichardson [email protected]
http://eventuate.io
http://plainoldobjects.com http://microservices.io
Questions?
Tags