Microservices: lessons from the trenches

Preview:

Citation preview

Microservices: lessons from the trenches

@MehdiKhalili

http://tiny.cc/microservices-lessons

Mehdi Khalili@MehdiKhalili

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

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

Microservices is awesome

Microservices is challenging

agenda

• Introduction

• Benefits

• Challenges and tips

• Resources

• Questions

Introduction

Monolith

Monolith

one repo

Monolith

one language

Monolith

one database

Monolith

one deployment

Microservices

Microservices

one repo

per service

Microservices

one language

per service

Microservices

one persistence engine

per service

Microservices

one data storeper service

Microservices

one deploymentper service

BenefitsAKA the cool parts!

Scalability

Decentralized

Data Management

Loose Coupling

Fault Tolerance

Scalable Development

Lower

Cognitive Load

Technical Diversification

Autonomous Teams

Continuous Delivery

Evolutionary Design

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

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

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

Challenges

Fault Tolerance

30 services with 99.9% SLA

= 432 mins

= 21.6 hours

99.9% SLA

30 services

one day of downtime a month

tightly coupled services

Netflix:

assumed broken components

design for failure

circuit breaker pattern

circuit breaker

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

tightly coupled services

loosely coupled services

contain the failure

fallback

and

graceful degradation

https://github.com/Netflix/Hystrix

hangfire.io

Hangfire

be proactive

about failure

monitoring endpoints

synthetic monitoring

extensive logging

troubleshooting

correlation id

log aggregation

Gif-y break

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

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

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

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

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

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

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

Decentralized Data Management

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

don’t take

inter-database dependency

you will lose

loose coupling

you will lose

tech diversification

that includes BI too!

use aggregator services

for cross-cutting logic

don’t use

distributed transactions

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

eventual consistency

compensating actions

Loose Coupling

consumer

provider

consumer

loose coupling could lead to

violation of contract

runtime failure

consumer

provider

consumer

consumer driven contracts

contract

contract

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

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

pactNet

consumer

provider

consumer

consumer driven contracts

mock

mock contract

contract

<- DSL ->

<- DSL ->

consumer

provider

consumer

service libraries

service lib

service lib

you need the big picture

don’t draw diagrams

use logging for

populating the big picture

correlation id plus

transaction code

document your services

swagger.io

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

swagger and curies for

self documenting services

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

Continuous Delivery

Netflix:

” you code it, you'll deploy it

and you'll be on pager-duty.”

DevOps culture

test

automation

deployment

automation

infrastructure

automation

Size Matters

It’s microservices;

not nanoservices

Arnon Rotem-Gal-Oz:

“A nanoservice is a service whose

overhead outweighs its utility.”

nanoservice

kill

me

now

monolith

Yaa

aay!

Size

pain

organized around

Business Capabilities

Ian Cartwright:

“There should be business and

architecture isomorphism”

The Culture

“Our release process has 43

steps”

“We need a DevOps team”

“Test automation might work for

others but our system is different.”

“We need to stop obsessing

about quality and focus on

getting this out soon.”

Conway’s Law:

“Organizations which design

systems are constrained to produce

systems which are copies of the

communication structures of these

organizations.”

monolithic apps thrive

at monolithic organizations

microservices thrive

at agile organizations

fix your organization first

Wrap up

Microservices is

awesome

Microservices is

NOT a silver bullet

apply it to the extent

where benefits

outweigh the overheads

takeaway

Culture, culture, culture!

takeaway

Size matters

takeaway

Fault Tolerance

Resources

Thanks

Q&A

@MehdiKhalili

Recommended