a pattern language for microservices (@futurestack)

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

Upload: chris-richardson

Post on 15-Apr-2017

3.247 views

Category:

Software


0 download

TRANSCRIPT

Page 1: A Pattern Language for Microservices (@futurestack)

@crichardson

A pattern language for microservices

Chris Richardson

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

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

Page 2: A Pattern Language for Microservices (@futurestack)

@crichardson

Presentation goal

Why patterns and pattern languages?

A pattern language for microservices

Page 3: A Pattern Language for Microservices (@futurestack)

@crichardson

About Chris

Page 4: A Pattern Language for Microservices (@futurestack)

@crichardson

About Chris

Consultant and trainer focusing on microservices (http://www.chrisrichardson.net/)

Page 5: A Pattern Language for Microservices (@futurestack)

@crichardson

About Chris

Founder of a startup that is creating a platform that makes it easy for

application developers write microservices

(http://eventuate.io)

Page 6: A Pattern Language for Microservices (@futurestack)

@crichardson

For more information

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

http://microservices.io

http://plainoldobjects.com/

https://twitter.com/crichardson

http://eventuate.io/

Page 7: A Pattern Language for Microservices (@futurestack)

@crichardson

Agenda

Why a pattern language for microservices?

Core patterns

Deployment patterns

Communication patterns and more

Page 8: A Pattern Language for Microservices (@futurestack)

@crichardson

In 1986…

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

Page 9: A Pattern Language for Microservices (@futurestack)

@crichardson

Yet almost 30 years later developers are still

passionately arguing over “silver bullets”

Page 10: A Pattern Language for Microservices (@futurestack)

@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 11: A Pattern Language for Microservices (@futurestack)

@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 12: A Pattern Language for Microservices (@futurestack)

@crichardson

How we make decisions

Decide using

emotions

Rationalize with our intellect

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

Page 13: A Pattern Language for Microservices (@futurestack)

@crichardson

We need a better way to discuss and think about technology

Page 14: A Pattern Language for Microservices (@futurestack)

@crichardson

What’s a pattern?

Reusable solution to a problem

occurring in a particular context

Page 15: A Pattern Language for Microservices (@futurestack)

@crichardson

The structure of a pattern

=

Great framework for discussing and thinking about technology

Page 16: A Pattern Language for Microservices (@futurestack)

@crichardson

The structure of a pattern

Resulting context

aka the situation

Name

Context

Problem

Related patterns

(conflicting) issues etc to address Forces

Solution

Page 17: A Pattern Language for Microservices (@futurestack)

@crichardson

Resulting context

Benefits

Drawbacks

Issues to resolve

Page 18: A Pattern Language for Microservices (@futurestack)

@crichardson

Related patterns

Alternative solutions

Solutions to problems introduced by this pattern

Page 19: A Pattern Language for Microservices (@futurestack)

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 20: A Pattern Language for Microservices (@futurestack)

@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 21: A Pattern Language for Microservices (@futurestack)

@crichardson

Work in

progress

http://microservices.io/

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

Data

Communication

Service-per-VM

Partitioning

Messaging Remote ProcedureInvocation

Style

Core

Database per Service

Event-driven architecture

Event sourcing

MotivatingPattern

SolutionPattern

Solution A Solution B

General Specific

Page 22: A Pattern Language for Microservices (@futurestack)

@crichardson

Agenda

Why a pattern language for microservices?

Core patterns

Deployment patterns

Communication patterns and more

Page 23: A Pattern Language for Microservices (@futurestack)

@crichardson

Page 24: A Pattern Language for Microservices (@futurestack)

@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 25: A Pattern Language for Microservices (@futurestack)

@crichardson

Problem: what’s the deployment architecture?

Page 26: A Pattern Language for Microservices (@futurestack)

@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 27: A Pattern Language for Microservices (@futurestack)

@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 28: A Pattern Language for Microservices (@futurestack)

@crichardson

Examples everywhere

Page 29: A Pattern Language for Microservices (@futurestack)

@crichardson

But when the application is large …

Page 30: A Pattern Language for Microservices (@futurestack)

@crichardson

Intimidates developers

Page 31: A Pattern Language for Microservices (@futurestack)

@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 32: A Pattern Language for Microservices (@futurestack)

@crichardson

Overloads your IDE and container

Slows down development

Page 33: A Pattern Language for Microservices (@futurestack)

@crichardson

Lots of coordination and communication required

Requires lots of coordinationI want to update

the UI

But the backend is not working

yet!

Page 34: A Pattern Language for Microservices (@futurestack)

@crichardson

Requires long-term commitment to a technology stack

Page 35: A Pattern Language for Microservices (@futurestack)

@crichardson

Pattern: Microservice architecture

Page 36: A Pattern Language for Microservices (@futurestack)

@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 37: A Pattern Language for Microservices (@futurestack)

@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 38: A Pattern Language for Microservices (@futurestack)

@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 39: A Pattern Language for Microservices (@futurestack)

@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 40: A Pattern Language for Microservices (@futurestack)

@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 41: A Pattern Language for Microservices (@futurestack)

@crichardson

The benefits typically outweigh the drawbacks

for large, complex applications

Page 42: A Pattern Language for Microservices (@futurestack)

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

….

Page 43: A Pattern Language for Microservices (@futurestack)

@crichardson

Agenda

Why a pattern language for microservices?

Core patterns

Deployment patterns

Communication patterns and more

Page 44: A Pattern Language for Microservices (@futurestack)

@crichardson

We have applied the microservices pattern:

How to deploy the services?

Page 45: A Pattern Language for Microservices (@futurestack)

@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 46: A Pattern Language for Microservices (@futurestack)

@crichardson

Page 47: A Pattern Language for Microservices (@futurestack)

@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 48: A Pattern Language for Microservices (@futurestack)

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 49: A Pattern Language for Microservices (@futurestack)

@crichardson

Pattern: Service instance per host

Page 50: A Pattern Language for Microservices (@futurestack)

@crichardson

Pattern: Service per VM host

Service VM image

VM

Service

VM

Service

VM

Service

packaged as

deployed as

Page 51: A Pattern Language for Microservices (@futurestack)

@crichardson

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

packer.io is a great tool

Page 52: A Pattern Language for Microservices (@futurestack)

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 53: A Pattern Language for Microservices (@futurestack)

@crichardson

VM

VM

Pattern: Service per Container host

Service Container image

Container

Service

Container

Service

Container

Service

packaged as

deployed as

Page 54: A Pattern Language for Microservices (@futurestack)

@crichardson

Examples

Page 55: A Pattern Language for Microservices (@futurestack)

Benefits and drawbacksBenefits

Great isolation

Great manageability

Container encapsulates implementation technology

Efficient resource utilization

Fast deployment

Drawbacks

Immature infrastructure for deploying containers

Page 56: A Pattern Language for Microservices (@futurestack)

@crichardson

Agenda

Why a pattern language for microservices?

Core patterns

Deployment patterns

Communication patterns and more

Page 57: A Pattern Language for Microservices (@futurestack)

@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 58: A Pattern Language for Microservices (@futurestack)

@crichardson

How do external clients interact with the microsevices?

Page 59: A Pattern Language for Microservices (@futurestack)

@crichardson

How do services communicate with each other?

Page 60: A Pattern Language for Microservices (@futurestack)

@crichardson

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

Page 61: A Pattern Language for Microservices (@futurestack)

@crichardson

What’s the database architecture?

Page 62: A Pattern Language for Microservices (@futurestack)

Database per Service

Orders Service Customer Service

Order Database

Customer Database

Sharded SQL

NoSQL DB

Page 63: A Pattern Language for Microservices (@futurestack)

How to solve distributed data management challenges?

How to implement transactions that span multiple services?

How to implement queries that span multiple services?

Page 64: A Pattern Language for Microservices (@futurestack)

@crichardson

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

Think about technology

Discuss technology

Apply technology

Page 65: A Pattern Language for Microservices (@futurestack)

@crichardson

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

Think about microservices

Discuss microservices

Apply microservices (or not)

Page 66: A Pattern Language for Microservices (@futurestack)

@crichardson

@crichardson [email protected]

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

Questions?