Microservices: lessons from the trenches

124

Transcript of Microservices: lessons from the trenches

Page 1: Microservices: lessons from the trenches
Page 2: Microservices: lessons from the trenches

Microservices: lessons from the trenches

@MehdiKhalili

http://tiny.cc/microservices-lessons

Page 3: Microservices: lessons from the trenches

Mehdi Khalili@MehdiKhalili

Page 4: Microservices: lessons from the trenches

http://giphy.com/gifs/parkour-tJLFLygAbaxYk

Page 5: Microservices: lessons from the trenches

http://giphy.com/gifs/fail-parkour-dZeSENj3pXT6o

Page 6: Microservices: lessons from the trenches
Page 7: Microservices: lessons from the trenches

Microservices is awesome

Page 8: Microservices: lessons from the trenches

Microservices is challenging

Page 9: Microservices: lessons from the trenches

agenda

• Introduction

• Benefits

• Challenges and tips

• Resources

• Questions

Page 10: Microservices: lessons from the trenches

Introduction

Page 11: Microservices: lessons from the trenches

Monolith

Page 12: Microservices: lessons from the trenches

Monolith

one repo

Page 13: Microservices: lessons from the trenches

Monolith

one language

Page 14: Microservices: lessons from the trenches

Monolith

one database

Page 15: Microservices: lessons from the trenches

Monolith

one deployment

Page 16: Microservices: lessons from the trenches

Microservices

Page 17: Microservices: lessons from the trenches

Microservices

one repo

per service

Page 18: Microservices: lessons from the trenches

Microservices

one language

per service

Page 19: Microservices: lessons from the trenches

Microservices

one persistence engine

per service

Page 20: Microservices: lessons from the trenches

Microservices

one data storeper service

Page 21: Microservices: lessons from the trenches

Microservices

one deploymentper service

Page 22: Microservices: lessons from the trenches

BenefitsAKA the cool parts!

Page 23: Microservices: lessons from the trenches

Scalability

Page 24: Microservices: lessons from the trenches

Decentralized

Data Management

Page 25: Microservices: lessons from the trenches

Loose Coupling

Page 26: Microservices: lessons from the trenches

Fault Tolerance

Page 27: Microservices: lessons from the trenches

Scalable Development

Page 28: Microservices: lessons from the trenches

Lower

Cognitive Load

Page 29: Microservices: lessons from the trenches

Technical Diversification

Page 30: Microservices: lessons from the trenches

Autonomous Teams

Page 31: Microservices: lessons from the trenches

Continuous Delivery

Page 32: Microservices: lessons from the trenches

Evolutionary Design

Page 33: Microservices: lessons from the trenches

http://giphy.com/gifs/win-parkour-12GGmxlQU22fxS

Page 34: Microservices: lessons from the trenches

http://giphy.com/gifs/parkour-hardcore-SdtFpqUnHtlbq

Page 35: Microservices: lessons from the trenches

http://giphy.com/gifs/fail-parkour-jCi66sK0E770s

Page 36: Microservices: lessons from the trenches

Challenges

Page 37: Microservices: lessons from the trenches

Fault Tolerance

Page 38: Microservices: lessons from the trenches

30 services with 99.9% SLA

= 432 mins

= 21.6 hours

Page 39: Microservices: lessons from the trenches

99.9% SLA

30 services

one day of downtime a month

Page 40: Microservices: lessons from the trenches

tightly coupled services

Page 41: Microservices: lessons from the trenches

Netflix:

assumed broken components

Page 42: Microservices: lessons from the trenches

design for failure

Page 43: Microservices: lessons from the trenches

circuit breaker pattern

Page 44: Microservices: lessons from the trenches

circuit breaker

Page 45: Microservices: lessons from the trenches

http://martinfowler.com/bliki/images/circuitBreaker/state.png

Page 46: Microservices: lessons from the trenches

tightly coupled services

Page 47: Microservices: lessons from the trenches

loosely coupled services

Page 48: Microservices: lessons from the trenches

contain the failure

Page 49: Microservices: lessons from the trenches

fallback

and

graceful degradation

Page 50: Microservices: lessons from the trenches

https://github.com/Netflix/Hystrix

Page 51: Microservices: lessons from the trenches

hangfire.io

Hangfire

Page 52: Microservices: lessons from the trenches

be proactive

about failure

Page 53: Microservices: lessons from the trenches

monitoring endpoints

Page 54: Microservices: lessons from the trenches

synthetic monitoring

Page 55: Microservices: lessons from the trenches

extensive logging

Page 56: Microservices: lessons from the trenches

troubleshooting

Page 57: Microservices: lessons from the trenches

correlation id

Page 58: Microservices: lessons from the trenches

log aggregation

Page 59: Microservices: lessons from the trenches

Gif-y break

Page 60: Microservices: lessons from the trenches

http://www.buzzfeed.com/richardhjames/are-these-the-funniest-gifs-of-all-time

Page 61: Microservices: lessons from the trenches

http://www.buzzfeed.com/richardhjames/are-these-the-funniest-gifs-of-all-time

Page 62: Microservices: lessons from the trenches

http://www.buzzfeed.com/richardhjames/are-these-the-funniest-gifs-of-all-time

Page 63: Microservices: lessons from the trenches

http://www.buzzfeed.com/richardhjames/are-these-the-funniest-gifs-of-all-time

Page 64: Microservices: lessons from the trenches

http://www.buzzfeed.com/richardhjames/are-these-the-funniest-gifs-of-all-time

Page 65: Microservices: lessons from the trenches

http://giphy.com/gifs/fail-parkour-movement-7SqLFyxYHal6o

Page 66: Microservices: lessons from the trenches

http://giphy.com/gifs/fail-parkour-2BuleA8z0C4uY

Page 67: Microservices: lessons from the trenches

Decentralized Data Management

Page 68: Microservices: lessons from the trenches

Werner Vogels:

"No direct database access is

allowed from outside the service,

and there’s no data sharing

among the services."http://queue.acm.org/detail.cfm?id=1142065

Page 69: Microservices: lessons from the trenches

don’t take

inter-database dependency

Page 70: Microservices: lessons from the trenches

you will lose

loose coupling

Page 71: Microservices: lessons from the trenches

you will lose

tech diversification

Page 72: Microservices: lessons from the trenches

that includes BI too!

Page 73: Microservices: lessons from the trenches

use aggregator services

for cross-cutting logic

Page 74: Microservices: lessons from the trenches

don’t use

distributed transactions

Page 75: Microservices: lessons from the trenches

CAP theoremhttp://www.allthingsdistributed.com/2007/12/eventually_consistent.html

Page 76: Microservices: lessons from the trenches

eventual consistency

Page 77: Microservices: lessons from the trenches

compensating actions

Page 78: Microservices: lessons from the trenches

Loose Coupling

Page 79: Microservices: lessons from the trenches

consumer

provider

consumer

Page 80: Microservices: lessons from the trenches

loose coupling could lead to

violation of contract

Page 81: Microservices: lessons from the trenches

runtime failure

Page 82: Microservices: lessons from the trenches

consumer

provider

consumer

consumer driven contracts

contract

contract

Page 83: Microservices: lessons from the trenches

pacthttps://github.com/realestate-com-au/pact

Page 84: Microservices: lessons from the trenches

https://github.com/SEEK-Jobs/pact-net

pactNet

Page 85: Microservices: lessons from the trenches

consumer

provider

consumer

consumer driven contracts

mock

mock contract

contract

<- DSL ->

<- DSL ->

Page 86: Microservices: lessons from the trenches

consumer

provider

consumer

service libraries

service lib

service lib

Page 87: Microservices: lessons from the trenches

you need the big picture

Page 88: Microservices: lessons from the trenches

don’t draw diagrams

Page 89: Microservices: lessons from the trenches

use logging for

populating the big picture

Page 90: Microservices: lessons from the trenches

correlation id plus

transaction code

Page 91: Microservices: lessons from the trenches

document your services

Page 92: Microservices: lessons from the trenches

swagger.io

http://petstore.swagger.wordnik.com/

Page 93: Microservices: lessons from the trenches

swagger and curies for

self documenting services

Page 94: Microservices: lessons from the trenches

"_links": { "curies": [ { "name": "doc", "href": "http://domain/docs/{rel}” } ]}

Page 95: Microservices: lessons from the trenches

Continuous Delivery

Page 96: Microservices: lessons from the trenches

Netflix:

” you code it, you'll deploy it

and you'll be on pager-duty.”

Page 97: Microservices: lessons from the trenches

DevOps culture

Page 98: Microservices: lessons from the trenches

test

automation

Page 99: Microservices: lessons from the trenches

deployment

automation

Page 100: Microservices: lessons from the trenches

infrastructure

automation

Page 101: Microservices: lessons from the trenches

Size Matters

Page 102: Microservices: lessons from the trenches

It’s microservices;

not nanoservices

Page 103: Microservices: lessons from the trenches

Arnon Rotem-Gal-Oz:

“A nanoservice is a service whose

overhead outweighs its utility.”

Page 104: Microservices: lessons from the trenches

nanoservice

kill

me

now

monolith

Yaa

aay!

Size

pain

Page 105: Microservices: lessons from the trenches

organized around

Business Capabilities

Page 106: Microservices: lessons from the trenches

Ian Cartwright:

“There should be business and

architecture isomorphism”

Page 107: Microservices: lessons from the trenches

The Culture

Page 108: Microservices: lessons from the trenches

“Our release process has 43

steps”

Page 109: Microservices: lessons from the trenches

“We need a DevOps team”

Page 110: Microservices: lessons from the trenches

“Test automation might work for

others but our system is different.”

Page 111: Microservices: lessons from the trenches

“We need to stop obsessing

about quality and focus on

getting this out soon.”

Page 112: Microservices: lessons from the trenches

Conway’s Law:

“Organizations which design

systems are constrained to produce

systems which are copies of the

communication structures of these

organizations.”

Page 113: Microservices: lessons from the trenches

monolithic apps thrive

at monolithic organizations

Page 114: Microservices: lessons from the trenches

microservices thrive

at agile organizations

Page 115: Microservices: lessons from the trenches

fix your organization first

Page 116: Microservices: lessons from the trenches

Wrap up

Page 117: Microservices: lessons from the trenches

Microservices is

awesome

Page 118: Microservices: lessons from the trenches

Microservices is

NOT a silver bullet

Page 119: Microservices: lessons from the trenches

apply it to the extent

where benefits

outweigh the overheads

Page 120: Microservices: lessons from the trenches

takeaway

Culture, culture, culture!

Page 121: Microservices: lessons from the trenches

takeaway

Size matters

Page 122: Microservices: lessons from the trenches

takeaway

Fault Tolerance

Page 123: Microservices: lessons from the trenches

Resources

Page 124: Microservices: lessons from the trenches

Thanks

Q&A

@MehdiKhalili