Surviving in a microservices environment

123
Surviving In A Microservices Environment Steve Pember CTO, ThirdChannel Gr8Conf US, 2017 @svpember

Transcript of Surviving in a microservices environment

Page 1: Surviving in a microservices environment

Surviving In A Microservices Environment

Steve Pember CTO, ThirdChannel

Gr8Conf US, 2017

@svpember

Page 2: Surviving in a microservices environment

@svpember

Microservice Blog Posts & Presentations• Microservices: Yay!

• Microservices: Boo!

• Smashing The Monolith (and here’s how we did it)

• Microservices + Technology X

• Microservices + Methodology Y

Page 3: Surviving in a microservices environment

Microservices have many lessons to offer

Page 4: Surviving in a microservices environment

What even are Microservices?

Page 5: Surviving in a microservices environment
Page 6: Surviving in a microservices environment

@svpember

Why Choose Microservices?• Reduce Coupling!

• Right Tool for the Job

• Continuous Delivery

• Smaller codebases are easier to reason about

• Easy to replace old services

• Efficient Scaling

• Can move quickly (once you’re up and running)

Page 7: Surviving in a microservices environment
Page 8: Surviving in a microservices environment
Page 9: Surviving in a microservices environment

Help?

Page 10: Surviving in a microservices environment

@svpember

Microservice Topics• Infrastructure

• Architecture

• Team Communication

• Miscellaneous Advice

Page 11: Surviving in a microservices environment

@svpember

Microservice Topics• Infrastructure

Page 12: Surviving in a microservices environment

@svpember

Infrastructure• How do we manage the logs?

Page 13: Surviving in a microservices environment

Centralized Logs are your #1 Priority

Page 14: Surviving in a microservices environment

@svpember

Page 15: Surviving in a microservices environment

@svpember

Page 16: Surviving in a microservices environment

@svpember

Page 17: Surviving in a microservices environment

@svpember

Page 18: Surviving in a microservices environment

@svpember

Page 19: Surviving in a microservices environment

@svpember

Infrastructure• How do we manage the logs?

• How about metrics / telemetry?

Page 20: Surviving in a microservices environment

You’d best be monitoring your platform.

Page 21: Surviving in a microservices environment
Page 22: Surviving in a microservices environment

–Johnny Appleseed

“Type a quote here.”

Page 23: Surviving in a microservices environment
Page 24: Surviving in a microservices environment

@svpember

Infrastructure• How do we manage the logs?

• How about metrics / telemetry?

• How do we deploy our code?

Page 25: Surviving in a microservices environment
Page 26: Surviving in a microservices environment

@svpember

Page 27: Surviving in a microservices environment

@svpember

Infrastructure• How do we manage the logs?

• How about metrics / telemetry?

• How do we deploy our code?

• How/where are our builds done?

Page 28: Surviving in a microservices environment

@svpember

Page 29: Surviving in a microservices environment

@svpember

Page 30: Surviving in a microservices environment

@svpember

Page 31: Surviving in a microservices environment

@svpember

Infrastructure• How do we manage the logs?

• How about metrics / telemetry?

• How do we deploy our code?

• How/where are our builds done?

• Do we have any coding conventions?

Page 32: Surviving in a microservices environment

Check Style? Coverage?

Page 33: Surviving in a microservices environment

@svpember

Page 34: Surviving in a microservices environment

@svpember

Page 35: Surviving in a microservices environment

@svpember

Page 36: Surviving in a microservices environment

@svpember

Page 37: Surviving in a microservices environment

@svpember

Infrastructure• How do we manage the logs?

• How about metrics / telemetry?

• How do we deploy our code?

• How/where are our builds done?

• Do we have any coding conventions?

• Can I generate a Service template?

Page 38: Surviving in a microservices environment

wget https://github.com/thirdchannel/base-template/archive/release.zip

(This is not a real url, but you get the idea)

Page 39: Surviving in a microservices environment

@svpember

Infrastructure• How do we manage the logs?

• How about metrics / telemetry?

• How do we deploy our code?

• How/where are our builds done?

• Do we have any coding conventions?

• Can I generate a Service template?

• How do we share code?

Page 40: Surviving in a microservices environment

Whoops! Gotcha!

Page 41: Surviving in a microservices environment
Page 42: Surviving in a microservices environment

@svpember

Sharing Code• It’s OK to reimplement functionality within each service

• Setup your own internal Artifactory!

• DO share infrastructure libraries (e.g. communications)

• NEVER share Domain or business logic libraries

Page 43: Surviving in a microservices environment

@svpember

Infrastructure• How do we manage the logs?

• How about metrics / telemetry?

• How do we deploy our code?

• How/where are our builds done?

• Do we have any coding conventions?

• Can I generate a Service template?

• How do we share code?

• How do we manage our (multiple) environments?

Page 44: Surviving in a microservices environment

@svpember

Page 45: Surviving in a microservices environment

Test & Develop in Isolation

Page 46: Surviving in a microservices environment

@svpember

Infrastructure• How do we manage the logs?

• How about metrics / telemetry?

• How do we deploy our code?

• How/where are our builds done?

• Do we have any coding conventions?

• Can I generate a Service template?

• How do we share code?

• How do we manage our (multiple) environments?

• Do our Devs get time to work on Infrastructure?

Page 47: Surviving in a microservices environment

@svpember

Microservice Topics• Infrastructure

• Architecture

Page 48: Surviving in a microservices environment

@svpember

Architecture• Do we have an overall design vision?

Page 49: Surviving in a microservices environment

Does Anyone Know What We’re Doing?!

Page 50: Surviving in a microservices environment
Page 51: Surviving in a microservices environment
Page 52: Surviving in a microservices environment

@svpember

Architecture• Do we have an overall design vision?

• What technologies do we use?

• How much freedom do we have in choosing new technologies?

Page 53: Surviving in a microservices environment

@svpember

Page 54: Surviving in a microservices environment

@svpember

Page 55: Surviving in a microservices environment

Be Careful When Choosing New Tech

Page 56: Surviving in a microservices environment

@svpember

Architecture• Do we have an overall design vision?

• What technologies do we use?

• How much freedom do we have in choosing new technologies?

• How do we test an individual service?

Page 57: Surviving in a microservices environment

Integration Tests are the Best Tests

Page 58: Surviving in a microservices environment

@svpember

Architecture• Do we have an overall design vision?

• What technologies do we use?

• How much freedom do we have in choosing new technologies?

• How do we test an individual service?

• How do we test the platform as a whole?

Page 59: Surviving in a microservices environment

@svpember

Test Environment• Run periodically (e.g. nightly)

• Each service generates fixture data

• Service data reset after EACH test

Page 60: Surviving in a microservices environment

@svpember

Architecture• Do we have an overall design vision?

• What technologies do we use?

• How much freedom do we have in choosing new technologies?

• How do we test an individual service?

• How do we test the platform as a whole?

• How do our services communicate?

Page 61: Surviving in a microservices environment

HTTP vs Async Events

Page 62: Surviving in a microservices environment

@svpember

HTTP• Well Established

• Built In libraries

• Existing structure for response codes (2**, 4**, 5**, etc)

• Synchronous

• Increases coupling

• Requires services to know which others require their data

• Has dependency on Service Discovery mechanism

• Susceptible to Data Loss

Page 63: Surviving in a microservices environment

@svpember

Events• Asynchronous

• Pub-sub / Fire and forget

• Loose Coupling

• Prevents Data Loss

• Allows for Reactive systems

• No existing structure for response error handling

• Dependency on Message Broker technology

• Can be difficult for Junior folks to understand

Page 64: Surviving in a microservices environment

Ensure you have Circuit Breaker or a Dead Letter Mechanism

Page 65: Surviving in a microservices environment

@svpember

Page 66: Surviving in a microservices environment

@svpember

<3 RabbitMq• Intelligent broker; dumb consumers

• Highly nuanced & robust routing

• Backpressure

• Dead letters /retries

• Message Ordering

• Multiple deliveries

• Ack / Nack/ Reject … re-enqueue

Page 67: Surviving in a microservices environment

@svpember

Architecture• Do we have an overall design vision?

• What technologies do we use?

• How much freedom do we have in choosing new technologies?

• How do we test an individual service?

• How do we test the platform as a whole?

• How do our services communicate?

• How/where is our data persisted?

Page 68: Surviving in a microservices environment

@svpember

Locality of Reference• Spatial: “How close together is our data?”

Page 69: Surviving in a microservices environment

@svpember

Locality of Reference• Spatial: “How close together is our data?”

• Temporal: “How often is our data accessed?”

Page 70: Surviving in a microservices environment

@svpember

Page 71: Surviving in a microservices environment

@svpember

Page 72: Surviving in a microservices environment

Beware the ‘Mini-Monolith’

Page 73: Surviving in a microservices environment

@svpember

Architecture• Do we have an overall design vision?

• What technologies do we use?

• How much freedom do we have in choosing new technologies?

• How do we test an individual service?

• How do we test the platform as a whole?

• How do our services communicate?

• How/where is our data persisted?

• Do we follow an overall architectural style?

Page 74: Surviving in a microservices environment

Make Sure Everyone Is Aware

Page 75: Surviving in a microservices environment

Applies to Both Intra- and Inter-Service

Page 76: Surviving in a microservices environment

It all Started With =>

Page 77: Surviving in a microservices environment

@svpember

Domain Driven Design• Ubiquitous Language

• Entities

• Aggregates

• Bounded Contexts

• No Direct communications across Boundaries

Page 78: Surviving in a microservices environment

@svpember

Page 79: Surviving in a microservices environment

@svpember

Page 80: Surviving in a microservices environment

… And CQRS

Page 81: Surviving in a microservices environment

@svpember

Page 82: Surviving in a microservices environment

@svpember

Page 83: Surviving in a microservices environment

Allows for interesting Architectures

Page 84: Surviving in a microservices environment
Page 85: Surviving in a microservices environment

While we’re at it, go Reactive

Page 86: Surviving in a microservices environment

@svpember

Architecture• Do we have an overall design vision?

• What technologies do we use?

• How much freedom do we have in choosing new technologies?

• How do we test an individual service?

• How do we test the platform as a whole?

• How do our services communicate?

• How/where is our data persisted?

• Do we follow an overall architectural style?

• When do we create new services?

Page 87: Surviving in a microservices environment

DDD to the rescue

Page 88: Surviving in a microservices environment
Page 89: Surviving in a microservices environment

@svpember

New Service?• Initially: design platform around Bounded Contexts, create services from

inner Contexts

• Don’t create services ‘just because’

• Do make an effort to identify boundaries

• Ensure a service has/will have proper context boundaries before creating

• If two services need to communicate synchronously or frequently, good candidates for MERGING

Page 90: Surviving in a microservices environment

# of services < # of developers

Page 91: Surviving in a microservices environment

@svpember

Microservice Topics• Infrastructure

• Architecture

• Team Communication

Page 92: Surviving in a microservices environment

@svpember

Team Communication• How are our teams structured?

Page 93: Surviving in a microservices environment

Conway’s Law is REAL

Page 94: Surviving in a microservices environment

–Johnny Appleseed

“Type a quote here.”

DBA

Engineers

QA

UX

Page 95: Surviving in a microservices environment

@svpember

Page 96: Surviving in a microservices environment

@svpember

Team Communication• How are our teams structured?

• Who owns which Service?

Page 97: Surviving in a microservices environment

Teams should be Owners

Page 98: Surviving in a microservices environment

@svpember

Team Communication• How are our teams structured?

• Who owns which Service?

• What’s our process for merging code?

Page 99: Surviving in a microservices environment
Page 100: Surviving in a microservices environment

@svpember

Team Communication• How are our teams structured?

• Who owns which Service?

• What’s our process for merging code?

• What’s our process for releasing code?

Page 101: Surviving in a microservices environment

@svpember

Page 102: Surviving in a microservices environment

@svpember

Team Communication• How are our teams structured?

• Who owns which Service?

• What’s our process for merging code?

• What’s our process for releasing code?

• What’s our process for monitoring code in production? Dealing with bugs?

Page 103: Surviving in a microservices environment

@svpember

Page 104: Surviving in a microservices environment

–Johnny Appleseed

“Type a quote here.”

Page 105: Surviving in a microservices environment

@svpember

Team Communication• How are our teams structured?

• Who owns which Service?

• What’s our process for merging code?

• What’s our process for releasing code?

• What’s our process for monitoring code in production? Dealing with bugs?

• Do we add more process if something goes wrong?

Page 106: Surviving in a microservices environment

Be Reluctant to Add New Process

Page 107: Surviving in a microservices environment

High Freedom / High Responsibility

Page 108: Surviving in a microservices environment

@svpember

Microservice Topics• Infrastructure

• Architecture

• Team Communication

• Miscellaneous Advice

Page 109: Surviving in a microservices environment

@svpember

Miscellaneous Advice• Don’t get cute with the naming of services

Page 110: Surviving in a microservices environment

Any idea what these

do?

Page 111: Surviving in a microservices environment

@svpember

Miscellaneous Advice• Don’t get cute with the naming of services

• New Feature -> walk backwards from what the user will see

Page 112: Surviving in a microservices environment

@svpember

Miscellaneous Advice• Don’t get cute with the naming of services

• New Feature -> walk backwards from what the user will see

• Release when a feature is ready

Page 113: Surviving in a microservices environment

@svpember

Miscellaneous Advice• Don’t get cute with the naming of services

• New Feature -> walk backwards from what the user will see

• Release when a feature is ready

• If a service A has another service B as a dependency => release B first

Page 114: Surviving in a microservices environment

@svpember

Miscellaneous Advice• Don’t get cute with the naming of services

• New Feature -> walk backwards from what the user will see

• Release when a feature is ready

• If a service A has another service B as a dependency => release B first

• How to bootstrap a new service?

Page 115: Surviving in a microservices environment

@svpember

Miscellaneous Advice• Don’t get cute with the naming of services

• New Feature -> walk backwards from what the user will see

• Release when a feature is ready

• If a service A has another service B as a dependency => release B first

• How to bootstrap a new service?

• Don’t release Friday afternoons

Page 116: Surviving in a microservices environment

In Summary

Page 117: Surviving in a microservices environment

Most of the Challenge is In infrastructure

Page 118: Surviving in a microservices environment

<3 Microservices

Page 119: Surviving in a microservices environment

Please share your survival tips!

Page 120: Surviving in a microservices environment

Any Questions? Anything I missed?

Page 121: Surviving in a microservices environment

Thank you!

@svpember

Page 122: Surviving in a microservices environment

@svpember

Images• Bad Odds (Jon Snow): https://www.reddit.com/r/gameofthrones/comments/4owm95/s6e9_megathread_gifwallpaperscreenshot_requests/

• Say Anything / John Cusak: http://www.glamour.com/story/happy-birthday-john-cusack-and

• Wilderness Survival Guide: https://www.kobo.com/us/en/ebook/the-wilderness-survival-guide-1

• XKCD: Code Review: https://xkcd.com/1513/

• Monolithic vs Microservices: @alvaro_sanchez

• Picard FacePalm: https://www.flickr.com/photos/30418788@N03/8381426895

• Council of Ricks: https://www.reddit.com/r/rickandmorty/comments/3exy00/it_looks_like_there_might_some_sort_of_council_of/

• Drago (break you): https://giphy.com/gifs/GWD5nSpiHxs3K

• Wrecking Ball: https://www.flickr.com/photos/rhysasplundh/5202454842/in/photostream/

• Rocky Stairs: http://pixgood.com/rocky-stairs.html

• Technical Difficulties: https://www.youtube.com/watch?v=EC15BmzsdhM

• Grafana example: https://i.imgur.com/KOqcD6L.png

• Zipkin example: https://blog.buoyant.io/2016/05/17/distributed-tracing-for-polyglot-microservices/

• Assembly Line: http://www.solidsmack.com/culture/humans-need-apply-new-short-film-explores-future-robots-manufacturing-automation/

Page 123: Surviving in a microservices environment

@svpember

Links• Eric Evans: DDD and Microservices: https://www.youtube.com/watch?

v=yPvef9R3k-M