A pattern language for microservices Chris Richardson Founder of - - PowerPoint PPT Presentation

a pattern language for microservices
SMART_READER_LITE
LIVE PREVIEW

A pattern language for microservices Chris Richardson Founder of - - PowerPoint PPT Presentation

A pattern language for microservices Chris Richardson Founder of the original CloudFoundry.com Author of POJOs in Action @crichardson chris@chrisrichardson.net http://plainoldobjects.com http://microservices.io http://eventuate.io


slide-1
SLIDE 1

@crichardson

A pattern language for microservices

Chris Richardson

Founder of the original CloudFoundry.com Author of POJOs in Action @crichardson chris@chrisrichardson.net http://plainoldobjects.com http://microservices.io http://eventuate.io

slide-2
SLIDE 2

@crichardson

Presentation goal

Why patterns and pattern languages? A pattern language for microservices

slide-3
SLIDE 3

@crichardson

About Chris

slide-4
SLIDE 4

@crichardson

About Chris

Consultant and trainer focusing

  • n microservices

(http://www.chrisrichardson.net/)

slide-5
SLIDE 5

@crichardson

About Chris

Founder of a startup that is creating a platform that makes it easy for application developers write microservices

(http://bit.ly/trialeventuate)

slide-6
SLIDE 6

@crichardson

For more information

https://github.com/cer/event-sourcing-examples http://microservices.io http://plainoldobjects.com/ https://twitter.com/crichardson http://eventuate.io/

slide-7
SLIDE 7

@crichardson

Agenda

Why a pattern language for microservices? Core patterns Deployment patterns Communication patterns

slide-8
SLIDE 8

@crichardson

In 1986…

http://en.wikipedia.org/wiki/Fred_Brooks

slide-9
SLIDE 9

@crichardson

Yet almost 30 years later developers are still passionately arguing over “silver bullets”

slide-10
SLIDE 10

@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

slide-11
SLIDE 11

@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

slide-12
SLIDE 12

@crichardson

How we make decisions

Decide using emotions Rationalize with

  • ur intellect

http://en.wikipedia.org/wiki/Mahout

slide-13
SLIDE 13

@crichardson

We need a better way to discuss and think about technology

slide-14
SLIDE 14

@crichardson

What’s a pattern?

Reusable solution to a problem

  • ccurring

in a particular context

slide-15
SLIDE 15

@crichardson

The structure of a pattern = Great framework for discussing and thinking about technology

slide-16
SLIDE 16

@crichardson

The structure of a pattern

Resulting context

aka the situation

Name Context Problem

Related patterns

(conflicting) issues etc to address

Forces Solution

slide-17
SLIDE 17

@crichardson

Resulting context

Benefits Drawbacks Issues to resolve

slide-18
SLIDE 18

@crichardson

Related patterns

Alternative solutions Solutions to problems introduced by this pattern

slide-19
SLIDE 19

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

slide-20
SLIDE 20

@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!

slide-21
SLIDE 21

@crichardson

Monolithic architecture Microservice architecture API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Deployment Discovery Core Communication Service-per-VM Partitioning Messaging Remote Procedure Invocation Style Motivating Pattern Solution Pattern Solution A Solution B General Specific

Work in progress

http://microservices.io/

slide-22
SLIDE 22

@crichardson

Agenda

Why a pattern language for microservices? Core patterns Deployment patterns Communication patterns

slide-23
SLIDE 23

@crichardson

slide-24
SLIDE 24

@crichardson

Let’s imagine you are building an online store

Browser/ Client SQL Database

Review Service Product Info Service

Recommendation Service

StoreFrontUI Order Service HTML REST/JSON

slide-25
SLIDE 25

@crichardson

Problem: what’s the deployment architecture?

slide-26
SLIDE 26

@crichardson

Forces

There is a team of developers that must be productive The application must be easy to understand and modify Do continuous deployment Run multiple instances for scalability and availability Use emerging technologies (frameworks, programming languages, etc)

slide-27
SLIDE 27

@crichardson

Tomcat

Pattern: Monolithic architecture

Browser/ Client

WAR/EAR

MySQL Database

Review Service Product Info Service

Recommendation Service

StoreFrontUI Order Service HTML REST/JSON

develop test deploy

Simple to

scale

slide-28
SLIDE 28

@crichardson

Examples everywhere

slide-29
SLIDE 29

@crichardson

But when the application is large …

slide-30
SLIDE 30

@crichardson

Intimidates developers

slide-31
SLIDE 31

@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

  • ne basket
slide-32
SLIDE 32

@crichardson

Overloads your IDE and container

Slows down development

slide-33
SLIDE 33

@crichardson

Lots of coordination and communication required

Obstacle to scaling development

I want to update the UI But the backend is not working yet!

slide-34
SLIDE 34

@crichardson

Requires long-term commitment to a technology stack

slide-35
SLIDE 35

@crichardson

Pattern: Microservice architecture

slide-36
SLIDE 36

@crichardson

Apply functional decomposition

X axis

  • horizontal duplication

Z a x i s

  • d

a t a p a r t i t i

  • n

i n g Y axis - functional decomposition S c a l e b y s p l i t t i n g s i m i l a r t h i n g s Scale by splitting different things

slide-37
SLIDE 37

@crichardson

Product Info

Microservice architecture

Product Info 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

slide-38
SLIDE 38

@crichardson

Examples

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

slide-39
SLIDE 39

@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

slide-40
SLIDE 40

@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

slide-41
SLIDE 41

@crichardson

The benefits typically

  • utweigh the drawbacks

for large, complex applications

slide-42
SLIDE 42

@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? Come to tomorrow’s talk at 9am ….

slide-43
SLIDE 43

@crichardson

Agenda

Why a pattern language for microservices? Core patterns Deployment patterns Communication patterns

slide-44
SLIDE 44

@crichardson

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

slide-45
SLIDE 45

@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

slide-46
SLIDE 46

@crichardson

slide-47
SLIDE 47

@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

slide-48
SLIDE 48

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

slide-49
SLIDE 49

@crichardson

Pattern: Service instance per host

slide-50
SLIDE 50

@crichardson

Pattern: Service per VM host

Service VM image VM Service VM Service VM Service

packaged as deployed as

slide-51
SLIDE 51

@crichardson

Example

http://techblog.netflix.com/ ~600 services

packer.io is a great tool

slide-52
SLIDE 52

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

slide-53
SLIDE 53

@crichardson

VM VM

Pattern: Service per Container host

Service Container image Container Service Container Service Container Service

packaged as deployed as

slide-54
SLIDE 54

@crichardson

Examples

slide-55
SLIDE 55

Benefits and drawbacks

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

slide-56
SLIDE 56

@crichardson

Agenda

Why a pattern language for microservices? Core patterns Deployment patterns Communication patterns

slide-57
SLIDE 57

@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?

slide-58
SLIDE 58

@crichardson

slide-59
SLIDE 59

@crichardson

The problem of discovery

Service Client Service Instance A Service Instance B Service Instance C

?

10.4.3.1:8756 10.4.3.99:4545 10.4.3.20:333

Client or API gateway Dynamically changing Service Instance A Service Instance B Service Instance C

10.4.3.1:8756 10.4.3.99:4545 10.4.3.20:333

How to load balance? Dynamically assigned

slide-60
SLIDE 60

@crichardson

Pattern: Client-side discovery

Service Client

Registry- aware HTTP Client

Service Registry Service Instance A Service Instance B Service Instance C

10.4.3.1:8756 10.4.3.99:4545 10.4.3.20:333

register query request load balance

slide-61
SLIDE 61

@crichardson

Example: Netflix Eureka and Ribbon

https://github.com/Netflix/eureka/wiki/Eureka-at-a-glance https://github.com/Netflix/ribbon

slide-62
SLIDE 62

Benefits and drawbacks

Benefits Flexible, application-specific load balancing Fewer network hops and moving parts compared to Server-side discovery
 Drawbacks Couples the client to the Service Registry Need implement client-side discovery and load balancing logic in multiple languages/ frameworks Service Registry is yet another moving part to setup and operate - highly available

slide-63
SLIDE 63

@crichardson

Pattern: Server-side discovery

Service Client

Router

Service Registry Service Instance A Service Instance B Service Instance C

10.4.3.1:8756 10.4.3.99:4545 10.4.3.20:333

register query request

request load balance

slide-64
SLIDE 64

@crichardson

Example

http://docs.aws.amazon.com/ElasticLoadBalancing/latest/ DeveloperGuide/vpc-loadbalancer-types.html

Internal ELB Internal ELB Public ELB

slide-65
SLIDE 65

Benefits and drawbacks

Benefits Simpler client code Built-in to some cloud/ container environments, e.g. AWS ELB, Kubernetes, Marathon Drawbacks Limited to (generic) load balancing algorithms provided by router More network hops Router and Service Registry is yet another moving part to setup and operate - highly available

slide-66
SLIDE 66

@crichardson

Summary: Patterns and pattern languages are a great way to …

Think about technology Discuss technology Apply technology

slide-67
SLIDE 67

@crichardson

Summary: The Microservices pattern language is a great way to …

Think about microservices Discuss microservices Apply microservices (or not)

slide-68
SLIDE 68

@crichardson

@crichardson chris@chrisrichardson.net http://bit.ly/trialeventuate http://plainoldobjects.com http://microservices.io

Questions?