Top Banner
@crichardson Decompose that WAR! A pattern language for microservices Chris Richardson Author of POJOs in Action Founder of the original CloudFoundry.com @crichardson [email protected] http://plainoldobjects.com http://microservices.io
87

Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Jul 15, 2015

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Decompose that WAR! A pattern language for

microservicesChris Richardson

Author of POJOs in Action Founder of the original CloudFoundry.com

@crichardson [email protected] http://plainoldobjects.com http://microservices.io

Page 2: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Presentation goal

Why patterns and pattern languages?

A pattern language for microservices

Page 3: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

About Chris

Page 4: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

About Chris

Founder of a startup that’s creating a platform for developing

event-driven microservices

Page 5: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

For more information

https://github.com/cer/event-sourcing-examples

http://microservices.io

http://plainoldobjects.com/

https://twitter.com/crichardson

Page 6: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Agenda

Why a pattern language for microservices?

Core patterns

Deployment patterns

Communication patterns

Page 7: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

In 1986…

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

Page 8: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Yet almost 30 years later developers are still

passionately arguing over “silver bullets”

Page 9: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@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

Page 10: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@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

Page 11: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

How we make decisions

Decide using

emotions

Rationalize with our intellect

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

Page 12: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

We need a better way to discuss and think about technology

Page 13: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

What’s a pattern?

Reusable solution to a problem

occurring in a particular context

Page 14: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

The structure of a pattern

=

Great framework for discussing and thinking about technology

Page 15: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

The structure of a pattern

Resulting context

aka the situation

Name

Context

Problem

Related patterns

(conflicting) issues etc to address Forces

Solution

Page 16: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Resulting context

Benefits

Drawbacks

Issues to resolve

Page 17: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Related patterns

Alternative solutions

Solutions to problems introduced by this pattern

Page 18: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Pattern languageA 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

Page 19: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

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

Page 20: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

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

Style

MotivatingPattern

SolutionPattern

Solution A Solution B

General Specific

Work in

progress

Page 21: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Agenda

Why a pattern language for microservices?

Core patterns

Deployment patterns

Communication patterns

Page 22: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Page 23: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@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

Page 24: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Problem: what’s the deployment architecture?

Page 25: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

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

Page 26: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Tomcat

Pattern: Monolithic architecture

Browser/Client

WAR/EAR

MySQL Database

Review Service

Product Info Service

Recommendation Service

StoreFrontUI

Order Service

HTMLREST/JSON

develop test

deploy

Simple to

scale

Page 27: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Examples everywhere

Page 28: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

But when the application is large …

Page 29: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Intimidates developers

Page 30: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@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

Page 31: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Overloads your IDE and container

Slows down development

Page 32: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Lots of coordination and communication required

Obstacle to scaling development

I want to update the UI

But the backend is not working

yet!

Page 33: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Requires long-term commitment to a technology stack

Page 34: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Pattern: Microservice architecture

Page 35: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Apply functional decomposition

X axis - horizontal duplication

Z axis

- data

partit

ioning

Y axis - functional

decomposition

Scale b

y split

ting s

imilar

thing

s

Scale by splitting

different things

Page 36: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Product Info

Microservice architectureProduct 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

Page 37: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@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

Page 38: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

BenefitsSmaller, 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

Page 39: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

DrawbacksComplexity 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

Page 40: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

The benefits typically outweigh the drawbacks

for large, complex applications

Page 41: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

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

….

Page 42: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Agenda

Why a pattern language for microservices?

Core patterns

Deployment patterns

Communication patterns

Page 43: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

We have applied the microservices pattern:

How to deploy the services?

Page 44: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

ForcesServices 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

Page 45: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Page 46: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@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

Page 47: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Benefits and drawbacksBenefits

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

Page 48: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Pattern: Service instance per host

Page 49: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Pattern: Service per VM host

Service VM image

VM

Service

VM

Service

VM

Service

packaged as

deployed as

Page 50: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

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

packer.io is a great tool

Page 51: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Benefits and drawbacksBenefits

Great isolation

Great manageability

VM encapsulates implementation technology

Leverage AWS infrastructure for Autoscaling/Load balancing

Drawbacks

Less efficient resource utilization

Slow deployment

Page 52: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

VM

VM

Pattern: Service per Container host

Service Container image

Container

Service

Container

Service

Container

Service

packaged as

deployed as

Page 53: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Examples

Page 54: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Benefits and drawbacksBenefits

Great isolation

Great manageability

Container encapsulates implementation technology

Efficient resource utilization

Fast deployment

Drawbacks

Immature infrastructure for deploying containers

Page 55: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Agenda

Why a pattern language for microservices?

Core patterns

Deployment patterns

Communication patterns

Page 56: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Communication issues

System Client

Service A

Service B

Service C

The SystemHow do clients of the

system interact with the services?

How do services within the system

interact?

Page 57: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Page 58: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

How do clients of the system interact with the services?

Page 59: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Forces

Mismatch between the fine-grained microservices and needs of the clients

Different clients need different data

LAN vs. WAN vs. Mobile network performance

The number of service instances and their locations (host+port) is changes dynamically

Partitioning into services can change over time and should be hidden from clients

Page 60: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Directly connecting the front-end to the backend

Model

View ControllerProduct Info

service

Recommendation Service

Review service

REST

REST

Thrift

Model

View Controller

Browser/Native App

Traditional server-side web application

Chatty API

Web unfriendly protocols

What’s the host/port??

Page 61: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Pattern: API gateway

Model

View ControllerProduct Info

service

Recommendation Service

Review service

REST

REST

Thrift

API Gateway

Model

View Controller

Browser/Native App

Single entry point

Client specific APIs

Protocol translation

Traditional server-side web application

Page 62: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Example: Netflix API

http://techblog.netflix.com/2013/01/optimizing-netflix-api.html

Device specific end points

Page 63: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Benefits of the API gatewayInsulates the clients from the partitioning

Insulates the clients from the problem of discovery

Provides the optimal API for each client

Reduces the number of requests/roundtrips

Simplifies the client by moving logic for calling multiple services from the client to API gateway

Gateway translates between web-unfriendly protocols and HTTP/WebSockets

Page 64: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Drawbacks of the API gateway

Increased complexity - the API gateway is yet another highly available component that must be developed, deployed and managed

Increased response time due to the additional network hop through the API gateway

Page 65: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Page 66: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Benefits and drawbacks of messaging

Benefits

Decouples client from services

Message broker buffers messages

Supports a variety of communication patterns

Drawbacks

Additional complexity of message broker

Request/reply-style communication is more complex

Client needs to discover location of message broker

Page 67: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Benefits and drawbacks of RPC

Benefits

Simple and familiar

Request/reply is easy

No intermediate broker

Drawbacks

Only supports request/reply

Service must be available

Client needs to discover locations of service instances

Page 68: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Page 69: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@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

Page 70: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@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

registerquery

request

load balance

Page 71: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Example: Netflix Eureka and Ribbon

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

Page 72: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Benefits and drawbacksBenefits

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

Page 73: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@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

registerquery

requestrequest

load balance

Page 74: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Example

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

Internal ELB Internal

ELB

Public ELB

Page 75: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Benefits and drawbacksBenefits

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

Page 76: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

The problem of registration

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

How does registration happen?

Page 77: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Page 78: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Forces

Service instances must be

registered with the service registry on startup

unregistered on shutdown

Service instances that crash must be unregistered from the service registry

Service instances that are running but incapable of handling requests must be unregistered from the service registry

Page 79: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Pattern: Self registration

Service Registry

Service Instance A

10.4.3.1:8756

registerheart-beatunregister

Page 80: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

ExamplesNetflix Eureka Java client

API for registering/unregistering with Eureka server

Specify state: STARTING, UP, DOWN, OUT_OF_SERVICE

Register a periodically invoked health check callback

Zookeeper-based Java applications

Service = znode

Service instance = ephemeral child of znode

Page 81: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Benefits and drawbacksBenefits

Simple - no extra components

Service can implement a more sophisticated state model

Drawbacks

Couples the service to service registry

Must implement registration logic in multiple languages/frameworks

Service might lack the self-awareness to unregister itself

Page 82: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

Pattern: 3rd party registration

Service Registry

Service Instance A

10.4.3.1:8756

registerheart-beatunregister

Registrarhealthcheck

Page 83: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

ExamplesAWS Autoscaling groups

Automatically register/unregister EC2 instance with ELB

Registrator

Registers and unregisters Docker containers with service registry

Kubernetes/Marathon

Automatically register/unregister services

Netflix Eureka Prana

Sidecar application for non-Java clients

Registers/unregisters service with Eureka

Performs health checks

Page 84: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

Benefits and drawbacksBenefits

Simpler service

Registrar can perform health checks

Some cloud/container environments provide a Registrar

Drawbacks

Registrar is yet another component that must be setup/operated. Must be highly available

Page 85: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

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

Think about technology

Discuss technology

Apply technology

Page 86: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

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

Think about microservices

Discuss microservices

Apply microservices (or not)

Page 87: Decompose that WAR? A pattern language for microservices (@QCON @QCONSP)

@crichardson

@crichardson [email protected]

http://plainoldobjects.com http://microservices.io