64
Microservices: lessons from the trenches Team Lead at ThoughtWorks Mehdi Khalili twitter: @MehdiKhalili http://www.mehdi-khalili.com/presentations/microservices- lessons-dddmel/ http://www.mehdi-khalili.com/microservices-lessons/

Microservices lessons from trenches

Embed Size (px)

Citation preview

Page 1: Microservices lessons from trenches

Microservices: lessons from the trenches

Team Lead at ThoughtWorksMehdi Khalili

twitter: @MehdiKhalili

http://www.mehdi-khalili.com/presentations/microservices-lessons-dddmel/

http://www.mehdi-khalili.com/microservices-lessons/

Page 2: Microservices lessons from trenches
Page 3: Microservices lessons from trenches

Microservices isAWESOME!!

Page 4: Microservices lessons from trenches

Benefits of microservices

• Scalability• Loose Coupling• Fault Tolerance• Scalable Development• Technical Diversification• Continuous Delivery

Page 5: Microservices lessons from trenches

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

Page 6: Microservices lessons from trenches

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

Page 7: Microservices lessons from trenches

Challenges

• Fault Tolerance• Loose Coupling• Greenfield• Culture

Page 8: Microservices lessons from trenches

Fault Tolerance

Page 9: Microservices lessons from trenches

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

Page 10: Microservices lessons from trenches

30 services with 99.9% up-time 43m downtime per service a month1296m downtime a monthone day of downtime a month

Page 11: Microservices lessons from trenches

The Akamai story!

Page 12: Microservices lessons from trenches

contain the failure

Netflix: assumed broken components

Page 13: Microservices lessons from trenches

Reading

• caching• data duplication!• graceful degradation

Page 14: Microservices lessons from trenches

Actions and events

• guaranteed delivery• eventual consistency

Page 15: Microservices lessons from trenches

be proactive about failure

Page 16: Microservices lessons from trenches

The story of recycling app pool!

Page 17: Microservices lessons from trenches

• monitoring endpoints• synthetic monitoring

be proactive about failure

Page 18: Microservices lessons from trenches

troubleshooting

Page 19: Microservices lessons from trenches

The story of missing param!

Page 20: Microservices lessons from trenches

• extensive logging• correlation id• log aggregation

troubleshooting

Correlation Id Service From Timestamp Message

996a3975-4996

Registration::Create

nil 02 Aug 2014 19:55:15 AEST +10:00

bbbe64ab-c84c Cart::Get nil 02 Aug 2014 19:55:15 AEST +10:00

996a3975-4996

Accounting::Create

Registration::Create

02 Aug 2014 19:55:16 AEST +10:00

996a3975-4996

Avatar::Create Registration::Create

02 Aug 2014 19:55:16 AEST +10:00

NullReference

Page 21: Microservices lessons from trenches

• extensive logging• correlation id• log aggregation

troubleshooting

Correlation Id Service From Timestamp Message

996a3975-4996

Registration::Create

nil 02 Aug 2014 19:55:15 AEST +10:00

bbbe64ab-c84c Cart::Get nil 02 Aug 2014 19:55:15 AEST +10:00

996a3975-4996

Accounting::Create

Registration::Create

02 Aug 2014 19:55:16 AEST +10:00

996a3975-4996

Avatar::Create Registration::Create

02 Aug 2014 19:55:16 AEST +10:00

NullReference

Page 22: Microservices lessons from trenches

• extensive logging• correlation id• log aggregation

troubleshooting

Correlation Id Service From Timestamp Message

996a3975-4996

Registration::Create

nil 02 Aug 2014 19:55:15 AEST +10:00

bbbe64ab-c84c Cart::Get nil 02 Aug 2014 19:55:15 AEST +10:00

996a3975-4996

Accounting::Create

Registration::Create

02 Aug 2014 19:55:16 AEST +10:00

996a3975-4996

Avatar::Create Registration::Create

02 Aug 2014 19:55:16 AEST +10:00

NullReference

Page 23: Microservices lessons from trenches

Loose Coupling

Page 24: Microservices lessons from trenches

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

Page 25: Microservices lessons from trenches

you need the big picture

Page 26: Microservices lessons from trenches

The soft-delete story!

Page 27: Microservices lessons from trenches

you need the big picture

beautiful diagrams!

Page 28: Microservices lessons from trenches

you need the big picture

Correlation Id

Service From Timestamp Message

0a669422-5e44

Registration::Create

nil 02 Aug 2014 19:55:15 AEST +10:00

bbbe64ab-c84c

Accounting::Create

User::AddAccount 01 Aug 2014 05:10:01 AEST +10:00

996a3975-4996

Accounting::Create

Registration::Create

02 Aug 2014 19:55:16 AEST +10:00

e30e4e37-b1e1

Avatar::Create Registration::Create

02 Aug 2014 19:55:16 AEST +10:00

NullReference

Page 29: Microservices lessons from trenches

catch contract violation at build time not run-time

Page 30: Microservices lessons from trenches

consumer

provider

consumer

consumer driven contracts

catch contract violation at build time

Page 31: Microservices lessons from trenches

catch contract violation at build time

Page 32: Microservices lessons from trenches

consumer

provider

consumer

service libraries

service lib

service lib

catch contract violation at build time

Page 33: Microservices lessons from trenches

Greenfield Microservices

Page 34: Microservices lessons from trenches

http://giphy.com/gifs/zSmGb2eYIAx3y

Page 35: Microservices lessons from trenches

you need well defined service boundaries

greenfield leads tounknown boundaries

Page 36: Microservices lessons from trenches

The nano-services story!

Page 37: Microservices lessons from trenches

nanoservice

kill

me

now

monolithSize

pain

Page 38: Microservices lessons from trenches

always start with monolith

extract the bits that would benefit from

microservices

Page 39: Microservices lessons from trenches

every greenfield project is a

startup“a human institution designed

to create a new product or service under conditions of

extreme uncertainty”

Page 40: Microservices lessons from trenches

Minimum Viable Product

“that version of a new product which allows a team to collect

the maximum amount of validated learning about

customers with the least effort”

Page 41: Microservices lessons from trenches

microservices is hard toimplementand deployand monitor

Page 42: Microservices lessons from trenches

Microservices is NOT MVP

Page 43: Microservices lessons from trenches

never start withmicroservices

Page 44: Microservices lessons from trenches

The Culture

Page 45: Microservices lessons from trenches

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

Page 46: Microservices lessons from trenches

nothing can save you from cultural failure

Page 47: Microservices lessons from trenches

“our release process has 43 manual and approval steps”

“fixing the bug took me 5 minutes,releasing it to prod took 3 weeks!”

heavy processes

Page 48: Microservices lessons from trenches

“test automation might work for others but our system is different.”

“we have 30 developers and 85 testers!”

no automation

Page 49: Microservices lessons from trenches

“we need to stop obsessing about quality and focus on getting this

out soon.”

no respect for quality

Page 50: Microservices lessons from trenches

“we need a DevOps team!”

“shortcut” to happiness

Page 51: Microservices lessons from trenches

test automationdeployment automation

infrastructure automationDevOps culture

The Culture

Page 52: Microservices lessons from trenches

Netflix:” you code it, you'll deploy

it

and you'll be on pager-duty.”

Page 53: Microservices lessons from trenches

How do you sell microservices?

DO NOT

Page 54: Microservices lessons from trenches

takeaways

Page 55: Microservices lessons from trenches

Fault tolerance

• Contain the failure• Caching, data duplication and graceful

degradation• Guaranteed delivery and eventual consistency

• Be proactive about failure• Monitoring

• Use extensive logging

Page 56: Microservices lessons from trenches

Loose coupling

• You need the big picture• Self documenting application

• Build-time contract verification• Consumer Driven Contracts• Service Libraries

Page 57: Microservices lessons from trenches

Avoid greenfield microservices

• Start with monolith• Learn your domain model• Microservices is NOT MVP

Page 58: Microservices lessons from trenches

takeaway

• Culture, culture, culture!• Test automation• Deployment automation• Infrastructure automation• DevOps culture

Page 59: Microservices lessons from trenches

microservices isawesome

Page 60: Microservices lessons from trenches

benefits vs overheadsScalability Operations &

monitoringLoose coupling Contract violation

Fault tolerance Fault isolationScalable

developmentCommunication

overheadLower cognitive load Losing the big picture

Tech diversification Too many things to learn

Continuous delivery DevOps culture

Page 61: Microservices lessons from trenches

do it to the extent its benefits outweigh

overheads and challenges

Page 62: Microservices lessons from trenches

Next time you want to do microservices

• Do you actually need it?• Do you need it now?• Are the challenges worth the

benefits?• Does it fit your CULTURE?

Page 63: Microservices lessons from trenches

Resources

Page 64: Microservices lessons from trenches

Thank you

twitter: @MehdiKhalili

http://www.mehdi-khalili.com/presentations/microservices-lessons-dddmel/

http://www.mehdi-khalili.com/microservices-lessons/