A Pattern Language for Microservices

61
@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://learnmicroservices.io Copyright © 2017. Chris Richardson Consulting, Inc. All rights reserved

Transcript of A Pattern Language for Microservices

Page 1: A Pattern Language for Microservices

@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://learnmicroservices.io

Copyright © 2017. Chris Richardson Consulting, Inc. All rights reserved

Page 2: A Pattern Language for Microservices

@crichardson

Presentation goal

Overview of the microservice architecture pattern language

and how to use it to architect an

application

Page 3: A Pattern Language for Microservices

@crichardson

About Chris

Page 4: A Pattern Language for Microservices

@crichardson

About Chris

Consultant and trainer focusing on modern

application architectures including microservices

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

Page 5: A Pattern Language for Microservices

@crichardson

About Chris

Founder of a startup that is creating an open-source/SaaS platform

that simplifies the development of transactional microservices

(http://eventuate.io)

Page 6: A Pattern Language for Microservices

@crichardson

About Chris

http://learnmicroservices.io

Page 7: A Pattern Language for Microservices

@crichardson

The paper that never made it to PLoP 2001

Page 8: A Pattern Language for Microservices

@crichardson

Agenda

Why microservices?

Benefits of the microservice architecture

Microservices != silver bullet

The microservice pattern language

Applying the microservice pattern language

Page 9: A Pattern Language for Microservices

@crichardson

Modern software development: moving fast and not breaking things!

46x

440x

24x

5x lower

Amazon: ~0.001%

Netflix: 16 minutes

Page 10: A Pattern Language for Microservices

@crichardson

How to move fast and not break things?

Architecture:

Process:

Small, autonomous teams ????

DevOps/Continuous delivery/deployment

Organization:

Page 11: A Pattern Language for Microservices

@crichardson

The monolithic architecture

Tomcat

Browser

WAR

SQL database

HTML

REST/JSON

Client App

Simple to ….

Develop Test

Deploy Scale

Catalog Module

Reviews Module

Orders Module

StoreFront UI Module

Page 12: A Pattern Language for Microservices

@crichardson

But successful applications keep

growing ….

Page 13: A Pattern Language for Microservices

@crichardson

… and modularity breaks down…

http://www.laputan.org/mud/

“Shantytowns are squalid, sprawling slums.”

Page 14: A Pattern Language for Microservices

@crichardson

Monolithic hell

Agile development and deployment

becomes impossible

By John Martin, Public Domain, https://commons.wikimedia.org/w/index.php?curid=3353638

Page 15: A Pattern Language for Microservices

@crichardson

Monolithic hell:

Technology stack becomes increasingly obsolete BUT a rewrite is not feasible

Page 16: A Pattern Language for Microservices

The microservice architecture is an architectural style that

structures an application as a set of loosely coupled, services

organized around business capabilities

Page 17: A Pattern Language for Microservices

@crichardson

The Microservice architecture tackles complexity through

modularization

Improved scalability is secondary

*

Page 18: A Pattern Language for Microservices

@crichardson

Microservice architecture

Browser

Mobile Device

Content Router

API Gateway

Catalog Service

Review Service

Order Service

… Service

Catalog Database

Review Database

Order Database

… Database

HTTP /HTML

REST

REST

Browse & Search WebApp

Product Detail WebApp

….

Page 19: A Pattern Language for Microservices

@crichardson

Agenda

Why microservices?

Benefits of the microservice architecture

Microservices != silver bullet

The microservice pattern language

Applying the microservice pattern language

Page 20: A Pattern Language for Microservices

@crichardson

Microservices enable continuous delivery/deployment

Process: Continuous delivery/deployment

Organization:Small, agile, autonomous,

cross functional teams

Architecture: Microservice architecture

Enables

Enables Enables

SuccessfulSoftware

Development

Services =

testability and

deployability

Teams own services

Page 21: A Pattern Language for Microservices

@crichardson

Smaller, simpler applications

Easier to understand, develop and test

Less jar/classpath hell - who needs OSGI?

Faster to build, test and deploy

Reduced startup time - improves MTTR

Page 22: A Pattern Language for Microservices

Scales development: develop, deploy and scale each service independently

Small, autonomous teams

Clearly defined responsibilities

Catalog Service

Review Service

Order Service

… Service

Catalog Team

Review Team

Order Team

… Team

Responsible for

Page 23: A Pattern Language for Microservices

@crichardson

Easier to scale

Page 24: A Pattern Language for Microservices

@crichardson

Improves fault isolation

Page 25: A Pattern Language for Microservices

@crichardson

Easily evolve your technology stack

... and fail safely

Page 26: A Pattern Language for Microservices

@crichardson

Agenda

Why microservices?

Benefits of the microservice architecture

Microservices != silver bullet

The microservice pattern language

Applying the microservice pattern language

Page 27: A Pattern Language for Microservices

@crichardson

No silver bullets

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

Page 28: A Pattern Language for Microservices

@crichardson

Complexity

http://highscalability.com/blog/2014/4/8/microservices-not-a-free-lunch.html

Page 29: A Pattern Language for Microservices

@crichardson

Complexity of developing a distributed system

Page 30: A Pattern Language for Microservices

@crichardson

Multiple databases &

Transaction managementMust use event-driven eventual consistency

Page 31: A Pattern Language for Microservices

@crichardson

Complexity of testing a distributed system

Page 32: A Pattern Language for Microservices

@crichardson

Complexity of deploying and operating a distributed system

You need a lot of automation: VM/container

orchestration or PaaS

Page 33: A Pattern Language for Microservices

@crichardson

Developing and deploying features that span multiple services requires careful coordination

Page 34: A Pattern Language for Microservices

@crichardson

Agenda

Why microservices?

Benefits of the microservice architecture

Microservices != silver bullet

The microservice pattern language

Applying the microservice pattern language

Page 35: A Pattern Language for Microservices

@crichardson

Are microservices a good fit for my application?

Page 36: A Pattern Language for Microservices

@crichardson

When using microservices:How to decompose an application into services?

How to deploy an application’s services?How to handle cross cutting concerns?

Which communication mechanisms to use?

How do external clients communicate with the services?

How does a client discover the network location of a service instance?

How to prevent a network or service failure from cascading to other services?

How to maintain data consistency and implement queries?

How to make testing easier?

How to understand the behavior of an application and troubleshoot problems?

How to implement a UI screen or page that displays data from multiple services?

Page 37: A Pattern Language for Microservices

@crichardson

Microservice pattern language =

collection of patterns that solve these

architecture, design, development and operational problems

Page 38: A Pattern Language for Microservices

@crichardson

What’s a pattern?

Reusable solution to a problem

occurring in a particular context

Page 39: A Pattern Language for Microservices

@crichardson

The structure of a pattern encourages objectivity

Resulting context

aka the situation

Name

Context

Problem

Related patterns

(conflicting) issues etc to address Forces

Solution Benefits

Drawbacks

Issues to resolve

Alternatives

Solutions to issues

Page 40: A Pattern Language for Microservices

@crichardson

Microservice architecture pattern

Context Developing large, complex architecture

Problem What’s the runtime architecture?

Benefits Faster development Easy adopt new technologies

Drawbacks Complexity of a distributed system

Issues Decomposition Distributed system issues: IPC, discovery, …

Alternative patterns Monolithic architecture

Successor patterns Service Registry, API Gateway, …

Page 41: A Pattern Language for Microservices

@crichardson

Microservices pattern language: http://microservices.io

Page 42: A Pattern Language for Microservices

@crichardson

Microservices pattern language: layers

Page 43: A Pattern Language for Microservices

@crichardson

Agenda

Why microservices?

Benefits of the microservice architecture

Microservices != silver bullet

The microservice pattern language

Applying the microservice pattern language

Page 44: A Pattern Language for Microservices

@crichardson

The pattern language guides you when developing an architecture

What architectural decisions you must make

For each decision:

Available options

Trade-offs of each option

Page 45: A Pattern Language for Microservices

@crichardson

Predecessor - Successor ⇒

Sequence?

Page 46: A Pattern Language for Microservices

@crichardson

Key patterns

Page 47: A Pattern Language for Microservices

Problem: What’s the architecture?Forces

Maintainability

Deployability

Testability

Extensibility

Monolithic architecture

Microservice architecture

Single deployable/executable OR

Tightly coupled services

Multiple loosely coupled services

Page 48: A Pattern Language for Microservices

Problem: How to decompose an application into services?

Forces

Stability

Cohesive

Loosely coupled

Not too large

Decompose bybusiness capability

Decompose bysubdomain

Organize around business capabilities

Organize around DDD subdomains

Page 49: A Pattern Language for Microservices

Problem: how to ensure services are loosely coupled?

Forces:

Services must be loosely coupled

Evolving schema of shared database = coordination

… Ensures loose coupling

Page 50: A Pattern Language for Microservices

@crichardson

Problem: how to maintain data consistency?Context

• Each service has its own database

• Data is private to a service

Forces

Transactional data consistency must be maintained across multiple services

2PC is not an option

Page 51: A Pattern Language for Microservices

@crichardson

Problem: how to perform queries?

CQRS

Context

Each service has its own database

Forces

Queries must join data from multiple services

Data is private to a serviceMaintain query views by subscribing to events

API Composition

Page 52: A Pattern Language for Microservices

@crichardson

Problem: How do services communicate?

Messaging Remote ProcedureInvocation

Domain-specific

Forces

Services must communicate

Usually processes on different machines

Page 53: A Pattern Language for Microservices

@crichardson

The rest are generic technical architecture patterns

= Undifferentiated heavy lifting!

Page 54: A Pattern Language for Microservices

@crichardson

Problem: How to handle cross cutting concerns?

Microservice Chassis

Forces

Every service must implement logging; externalize configuration; health check endpoint; metrics; …

Page 55: A Pattern Language for Microservices

Problem: How to deploy an application’s services?

Multiple Services per host

Single Service per Host

Service-per-Container

Service-per-VM

Serverless deployment

Service deployment platform

Forces

Multiple languages

Isolated

Constrained

Monitor-able

Reliable

Efficient

Page 56: A Pattern Language for Microservices

@crichardson

Problem: How to discover a service instance’s network location?

Client-side discovery

Server-side discovery

Service registry

Self registration

3rd party registration

Forces

Client needs IP address of service instance

Dynamic IP addresses

Dynamically provisioned instances

Page 57: A Pattern Language for Microservices

@crichardson

Problem: How do external clients communicate with the services?

API gateway

Backend for front end

Page 58: A Pattern Language for Microservices

@crichardson

Problem: How to prevent a network or service failure from cascading?

Circuit Breaker

Page 59: A Pattern Language for Microservices

@crichardson

Problem: how to monitor the behavior of your application?

Exception tracking

Distributed tracing

Audit logging Application metrics

Log aggregation

Health check API

Page 60: A Pattern Language for Microservices

@crichardson

Summary

The monolithic architecture is a good choice for small/simple applications

Use the microservice architecture for large/complex applications

Microservice architecture != silver bullet

Use the microservice architecture pattern language to guide your decision making

Page 61: A Pattern Language for Microservices

@crichardson

@crichardson [email protected]

http://learnmicroservices.io

Thank you!