Top Banner
VINCENT KOK | ENGINEERING MANAGER, TRELLO | @VINCENTKOK Microservices 5 things I wish I’d known 5 6 things I wish I’d known
74

Microservices 5 Things I Wish I'd Known - JFall 2017

Jan 21, 2018

Download

Engineering

Vincent Kok
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Microservices 5 Things I Wish I'd Known - JFall 2017

VINCENT KOK | ENGINEERING MANAGER, TRELLO | @VINCENTKOK

Microservices5 things I wish I’d known5 6 things I wish I’d known

Page 2: Microservices 5 Things I Wish I'd Known - JFall 2017

Part-time speaker For fun and zero profit

About me: @vincentkok

Trello Engineering Manager on the

Trello team

Dutch You probably heard that already ;)

Page 3: Microservices 5 Things I Wish I'd Known - JFall 2017

Microservices Everybody seems to want them. Do we really know the impact of our choices?

Why do we want them so badly? Microservices are messy!

https://flic.kr/p/9u5pDA

Page 4: Microservices 5 Things I Wish I'd Known - JFall 2017

http://geek-and-poke.com/geekandpoke/2013/7/13/foodprints

Page 5: Microservices 5 Things I Wish I'd Known - JFall 2017

Grow Fat Code base grows. All

the things slow down.

Age Your code base will become a jurassic

park introducing new tech becomes hard

Ownership Who is responsible for which part and

more important: who has the pager

Economies of Scale

The bigger the team the more they

interrupt each other

Monolithical issues

Page 6: Microservices 5 Things I Wish I'd Known - JFall 2017
Page 7: Microservices 5 Things I Wish I'd Known - JFall 2017

8100Build jobs ran last week

Page 8: Microservices 5 Things I Wish I'd Known - JFall 2017

31992Automated tests

Page 9: Microservices 5 Things I Wish I'd Known - JFall 2017

Cause of issues can be extremely hard

Page 10: Microservices 5 Things I Wish I'd Known - JFall 2017

Who is having the pager?

INCIDENT RESPONSE

Page 11: Microservices 5 Things I Wish I'd Known - JFall 2017

Remember, we’re not all webscale

Page 12: Microservices 5 Things I Wish I'd Known - JFall 2017
Page 13: Microservices 5 Things I Wish I'd Known - JFall 2017

Optimise for rapid and sustainable flow of value.

DAN NORD

Page 14: Microservices 5 Things I Wish I'd Known - JFall 2017
Page 15: Microservices 5 Things I Wish I'd Known - JFall 2017

Small The size will be reasonable and

manageable

Independent lifecycle

Nothing will hold the team back. Go as

fast as you can

Optimise for the problem Pick solution and tech based on the problem at hand

Replaceable It is easier to replace if there is a need for

it

The microservice promise

Page 16: Microservices 5 Things I Wish I'd Known - JFall 2017

Patterns

Basics

Deployments

Testing

Security

Operations

https://flic.kr/p/9t2138

Decomposition

Page 17: Microservices 5 Things I Wish I'd Known - JFall 2017

#1: Basics

https://flic.kr/p/5E9ZF

Page 18: Microservices 5 Things I Wish I'd Known - JFall 2017

Creating a call-out Watch the tutorial in the Presentation Guidelines to learn how to create call-outs on screenshots within this template.

Page 19: Microservices 5 Things I Wish I'd Known - JFall 2017

MINIMAL SERVICE

Health check 200 app is alive. 500 app is unhealthy, destroy the node

Stateless* Run as many nodes as you need

Expose a port Only access to the service

Page 20: Microservices 5 Things I Wish I'd Known - JFall 2017

DEEPCHECK

Deep check Quickly discover if a service

fails to connect to a dependency

Page 21: Microservices 5 Things I Wish I'd Known - JFall 2017

DEEPCHECK EXAMPLE

{ "avatar": { "details": { "avatarRepository": { "isHealthy": true }, "crowd": { "isHealthy": true }, "deadlock": { "isHealthy": true

Page 22: Microservices 5 Things I Wish I'd Known - JFall 2017

CODE & BUILDS

1 repository 1 build

Page 23: Microservices 5 Things I Wish I'd Known - JFall 2017

Libraries Feel free to use

shared libraries but keep them loose

Config Be aware of the configuration

lifecycle

Schemas Make sure that

services are resilient to schema changes

-> Postel’s law

Testing Test in isolation.

Keep them decoupled

Page 24: Microservices 5 Things I Wish I'd Known - JFall 2017

Strict separation of config from code.

12 FACTOR APP

Page 25: Microservices 5 Things I Wish I'd Known - JFall 2017

Redeploy Part of the service

configuration.

Configuration lifecycles

Instant change Switches you would like to

enable/disable straight away

Rebuild Rebuild to apply changes

Page 26: Microservices 5 Things I Wish I'd Known - JFall 2017

Treat them as cattle, not pets.

BILL BAKER

Page 27: Microservices 5 Things I Wish I'd Known - JFall 2017

#2: Deployments

https://flic.kr/p/qP31Tf

Page 28: Microservices 5 Things I Wish I'd Known - JFall 2017

Only one person There is only one person in

the team that owns it

Deployment smells

Takes more then 15 mins

Setting it up should be quick and initial deployment should

quick

Requires a ticket A ticket for the deployment

team

Page 29: Microservices 5 Things I Wish I'd Known - JFall 2017

Always deploy an empty service into production

ME AND PROBABLY OTHERS

Page 30: Microservices 5 Things I Wish I'd Known - JFall 2017

Developers in control

Artifact What is the artifact we’re running. We’re mostly standardising on Docker

Resources What resources are requires: RDS, SQS, Dynamo etc..

Compute What EC2 instance do we want how many of those and when to scale

Alarms What are the alarm thresholds for this service

Ownership Who is owning the service

Configuration We will be adding more icons as need arises. Speak up if in need!

Page 31: Microservices 5 Things I Wish I'd Known - JFall 2017

DECLARATIVE DEPLOYMENT

name: Confluencedescription: Confluence Cloudlinks: binary: type: docker name: docker.atlassian.io/confluence tag: latest healthcheck: uri: /wiki/internal/healthcheck deepcheck: uri: /wiki/internal/deepcheck semanticCheck: dockerImage:

Page 32: Microservices 5 Things I Wish I'd Known - JFall 2017

CONFIGURATION

config: environmentVariables: ASAP_AUDIENCE: "foo" ASAP_ISSUER: "foo" CONFLUENCE_VERTIGO_SMTP_HOST: "smtp.foo.com" CONFLUENCE_VERTIGO_SMTP_PORT: "587" LOG4J_EXTRA_RULES: "log4j.logger.org.hiberate=DEBUG"

environmentOverrides: staging: config: environmentVariables: ASAP_PUBLIC_KEY_FALLBACK_REPOSITORY_URL: "https://s3.amazonaws.com/keysto

Page 33: Microservices 5 Things I Wish I'd Known - JFall 2017

RESOURCES

resources: - type: sqs name: default attributes: MaxReceiveCount: 20 VisibilityTimeout: 60 scaling: instance: m3.xlarge min: 7

Page 34: Microservices 5 Things I Wish I'd Known - JFall 2017

SIDECARS

compose: httpfrontend: image: nginx tag: ‘1.13.6’ ports: - 8080:80

Page 35: Microservices 5 Things I Wish I'd Known - JFall 2017

500Services in production

Page 36: Microservices 5 Things I Wish I'd Known - JFall 2017

#3: Testing

https://flic.kr/p/hn4K4b

Page 37: Microservices 5 Things I Wish I'd Known - JFall 2017

Testing microservices

Page 38: Microservices 5 Things I Wish I'd Known - JFall 2017

TESTING MONOLITHS IS EASY

Page 39: Microservices 5 Things I Wish I'd Known - JFall 2017

Unit

Integration

UI

Page 40: Microservices 5 Things I Wish I'd Known - JFall 2017

TESTING

Live service Test agains a real serviceMock service

Test against a mock service

Page 41: Microservices 5 Things I Wish I'd Known - JFall 2017

In process A local implementation of

your client

Out of process Use tools like WireMock and

MockServer

Two options

Page 42: Microservices 5 Things I Wish I'd Known - JFall 2017

MOCKING SERVICES - IN PROCESS

<beans profile=“integration-test"> <bean id="attachmentService"

class=“c.a.attachment.AttachmentStub”/></beans>

Page 43: Microservices 5 Things I Wish I'd Known - JFall 2017

MOCKING SERVICES - WIREMOCK

{ "request": { "url": “/rest/api/content“, "method": “POST” "Accept": { "matches": “application/json” } }, "response": { "status": 200 }}

Page 44: Microservices 5 Things I Wish I'd Known - JFall 2017

Stable API If it is external it already

should have a CTK so rely on it

How to trust your mock?

Contract testing Internal fast moving API’s an

benefit from this

Rely on monitoring Small service, low MTTR

therefore low impact

Page 45: Microservices 5 Things I Wish I'd Known - JFall 2017

Semantic Check Automated test that runs against a node before it will be added to the load balancer

Page 46: Microservices 5 Things I Wish I'd Known - JFall 2017

#4: Security

https://flic.kr/p/7LcF2W

Page 47: Microservices 5 Things I Wish I'd Known - JFall 2017

OAuth 2.0 Grant a client access to

resources based on a newly created set of credentials

Common standards

OpenID Connect Identity on top of OAuth 2

OpenID Allows identity and some

metadata only

Page 48: Microservices 5 Things I Wish I'd Known - JFall 2017

How to secure a set of many services?

SECURING SERVICES

Page 49: Microservices 5 Things I Wish I'd Known - JFall 2017

ASAPAtlassian Service Authentication Protocol

Page 50: Microservices 5 Things I Wish I'd Known - JFall 2017

HOW DOES IT WORK?

Foo BarJWT

Page 51: Microservices 5 Things I Wish I'd Known - JFall 2017

WHAT’S INSIDE?

Foo Bar

{ "typ": "JWT", "kid": "foo/key1", "alg": "RS256"}{ "sub": “32769:87e…” "aud": "bar", "nbf": 1494284564, "iss": "foo", "exp": 1494284624, "iat": 1494284564, "jti": “961253cf-ac…”}

Page 52: Microservices 5 Things I Wish I'd Known - JFall 2017

{ "kid": "foo/key1",}{ "sub": “32769:87e…” "aud": "bar", "iss": "foo"}

Page 53: Microservices 5 Things I Wish I'd Known - JFall 2017

s2sauth.bitbucket.io

AVAILABLE ON BITBUCKET

Page 54: Microservices 5 Things I Wish I'd Known - JFall 2017

#5: Operations

https://flic.kr/p/npbxAm

Page 55: Microservices 5 Things I Wish I'd Known - JFall 2017

100 lbs 99% water

dehydrate 98%

Guess the weight!https://flic.kr/p/npbxAm

Page 56: Microservices 5 Things I Wish I'd Known - JFall 2017

50lbs

Page 57: Microservices 5 Things I Wish I'd Known - JFall 2017

Uptime of a system with 30 services of 99.99?

TRANSLATING THIS TO A MICROSERVICE ARCHITECTURE

Page 58: Microservices 5 Things I Wish I'd Known - JFall 2017

2 hours99.99 = 99.7

30

Page 59: Microservices 5 Things I Wish I'd Known - JFall 2017

Failure is imminent

RESILIENCE

Page 60: Microservices 5 Things I Wish I'd Known - JFall 2017

Circuit breakers Write code with failure in

mind

Three must haves

Request tracing Don’t spend hours debugging

Log aggregations Stream all logs into one

place.

Page 61: Microservices 5 Things I Wish I'd Known - JFall 2017

DO YOU KNOW YOUR SYSTEM?

Page 62: Microservices 5 Things I Wish I'd Known - JFall 2017

CREATE INSIGHT: AGGREGATED LOGGING

Page 63: Microservices 5 Things I Wish I'd Known - JFall 2017

Response times How much time do services spend calling other services.

Back pressure Stop putting pressure on a system that is in trouble and fail fast

Fallback How do you handle failure. A mandatory step in the programming model.

Circuit breakers

Page 64: Microservices 5 Things I Wish I'd Known - JFall 2017

CREATE INSIGHT: CIRCUIT BREAKERS

Page 65: Microservices 5 Things I Wish I'd Known - JFall 2017

Request TracingX-B3-TraceId : 1X-B3-SpanId : 1

X-B3-TraceId : 1X-B3-SpanId : 2X-B3-ParentSpanId : 1

X-B3-TraceId : 1X-B3-SpanId : 3X-B3-ParentSpanId : 2

X-B3-TraceId : 1X-B3-SpanId : 4X-B3-ParentSpanId : 3

Page 66: Microservices 5 Things I Wish I'd Known - JFall 2017

TRACE ID’S

Page 67: Microservices 5 Things I Wish I'd Known - JFall 2017

You Build It You Run It The team who builds it looks after it.

Ops Team Handover your services and let them

deal with the fun. Don’t do this.

Page 68: Microservices 5 Things I Wish I'd Known - JFall 2017

#6: Decomposition

https://flic.kr/p/4hAC16

Page 69: Microservices 5 Things I Wish I'd Known - JFall 2017

The monolith is deprecated

MAKE A STATEMENT

Page 70: Microservices 5 Things I Wish I'd Known - JFall 2017

A CONFLUENCE EXAMPLE

Core functionality

Scheduler

Attachments

Operational Transformation

Platform ServicesFront end

Page 71: Microservices 5 Things I Wish I'd Known - JFall 2017

Code Team is responsible for the codebase.Focus on

ownershipPipeline Team responsible for CI and Deployment

Incidents You built it you run it

Page 72: Microservices 5 Things I Wish I'd Known - JFall 2017

Decomposing core functionality

GraphQL service

Page 73: Microservices 5 Things I Wish I'd Known - JFall 2017

What should you take home?

Basics Services are cattle not pets.

Testing Testing a monolith is “easy” think about your service testing strategy

Deployment Deploying a service shouldn’t take longer then 15 minutes

Operations You build it you run it.

Security Think how you would like to secure service to service communications

Focus on value Optimise for rapid and sustainable flow of value

Page 74: Microservices 5 Things I Wish I'd Known - JFall 2017

VINCENT KOK | ENGINEERING MANAGER, TRELLO | @VINCENTKOK

Thanks!