Breaking Down the Monolith - Peter Marton, RisingStack

78
Breaking down the monolith Peter Marton, Trace by RisingStack

Transcript of Breaking Down the Monolith - Peter Marton, RisingStack

Page 1: Breaking Down the Monolith - Peter Marton, RisingStack

Breaking down the monolithPeter Marton, Trace by RisingStack

Page 2: Breaking Down the Monolith - Peter Marton, RisingStack

whoamiwork: CTO, Co-founder of RisingStack

twitter: slashdotpeter

email: [email protected]

blog: https://blog.risingstack.com

Page 3: Breaking Down the Monolith - Peter Marton, RisingStack

agenda1. Monolith and Microservices

2. Our experiences

3. Microservices challenges

Page 4: Breaking Down the Monolith - Peter Marton, RisingStack

1. Monolith and microservices

Page 5: Breaking Down the Monolith - Peter Marton, RisingStack

monolith

Page 6: Breaking Down the Monolith - Peter Marton, RisingStack

monolithself-contained

Page 7: Breaking Down the Monolith - Peter Marton, RisingStack

monolithresponsible for multiple tasks

Page 8: Breaking Down the Monolith - Peter Marton, RisingStack

monolithindependent from other services

Page 9: Breaking Down the Monolith - Peter Marton, RisingStack

microservice

https://microserviceweekly.com

Page 10: Breaking Down the Monolith - Peter Marton, RisingStack

microservicesmaller services each with separate DB

https://microserviceweekly.com

Page 11: Breaking Down the Monolith - Peter Marton, RisingStack

microservicesplit code by featurenot by functionality

https://microserviceweekly.com

Page 12: Breaking Down the Monolith - Peter Marton, RisingStack

microservicecomplexity in network

https://microserviceweekly.com

Page 13: Breaking Down the Monolith - Peter Marton, RisingStack

microserviceNOT FOR MVP!

Page 14: Breaking Down the Monolith - Peter Marton, RisingStack

agenda1. Monolith and Microservices

2. Our experiences

3. Microservices challenges

Page 15: Breaking Down the Monolith - Peter Marton, RisingStack

What is Trace?- I work on it

- Product by RisingStack

- Node.js and microservice monitoring tool

- Built with Node.js

- Built as a monolith in MVP phase

Page 16: Breaking Down the Monolith - Peter Marton, RisingStack
Page 17: Breaking Down the Monolith - Peter Marton, RisingStack

Why we moved to microservices?

Page 18: Breaking Down the Monolith - Peter Marton, RisingStack

Why we moved?

growing engineering team

Page 19: Breaking Down the Monolith - Peter Marton, RisingStack

Why we moved?

separated features -> focused people

Page 20: Breaking Down the Monolith - Peter Marton, RisingStack

Why we moved?

need for fault tolerance

Page 21: Breaking Down the Monolith - Peter Marton, RisingStack

2. Our experiences

Page 22: Breaking Down the Monolith - Peter Marton, RisingStack

Pros

Page 23: Breaking Down the Monolith - Peter Marton, RisingStack

Well focused independent teams (pro)

Page 24: Breaking Down the Monolith - Peter Marton, RisingStack

Easier to scale a specific part (pro)

Page 25: Breaking Down the Monolith - Peter Marton, RisingStack

Easier to develop a feature (pro)

Page 26: Breaking Down the Monolith - Peter Marton, RisingStack

Features fails independently (pro)

Page 27: Breaking Down the Monolith - Peter Marton, RisingStack

Cons

Page 28: Breaking Down the Monolith - Peter Marton, RisingStack

Increasing architectural complexity (cons)

Page 29: Breaking Down the Monolith - Peter Marton, RisingStack

Increasingresponse times (cons)

Page 30: Breaking Down the Monolith - Peter Marton, RisingStack

Harder totest and deploy (cons)

Page 31: Breaking Down the Monolith - Peter Marton, RisingStack

agenda1. Monolith and Microservices

2. Our experiences

3. Microservices challenges

Page 32: Breaking Down the Monolith - Peter Marton, RisingStack

3. Microservice challenges

Page 33: Breaking Down the Monolith - Peter Marton, RisingStack

Fault tolerance

Page 34: Breaking Down the Monolith - Peter Marton, RisingStack

If monitoring goes down...who knows that you are down?

Page 35: Breaking Down the Monolith - Peter Marton, RisingStack

Fault tolerance

servicesfail separately

Page 36: Breaking Down the Monolith - Peter Marton, RisingStack

Fault tolerance

critical resources should be cached

Page 37: Breaking Down the Monolith - Peter Marton, RisingStack

Our service caching- service level caching

- our service-lib handles it

- via cache headers

Page 38: Breaking Down the Monolith - Peter Marton, RisingStack

Fault tolerance

temporary failures -> persistent queues

Page 39: Breaking Down the Monolith - Peter Marton, RisingStack

Fault tolerance

event sourcing(not just microservices)

Page 40: Breaking Down the Monolith - Peter Marton, RisingStack

~Event sourcing with queue

Page 41: Breaking Down the Monolith - Peter Marton, RisingStack

Increasing complexity

Page 42: Breaking Down the Monolith - Peter Marton, RisingStack

Where we started (~8 months ago)

Page 43: Breaking Down the Monolith - Peter Marton, RisingStack

Where we are (today)

Page 44: Breaking Down the Monolith - Peter Marton, RisingStack

What if it breaks?

Page 45: Breaking Down the Monolith - Peter Marton, RisingStack

Logs everywhere

Page 46: Breaking Down the Monolith - Peter Marton, RisingStack

Where is the issue?

Page 47: Breaking Down the Monolith - Peter Marton, RisingStack

there...

Page 48: Breaking Down the Monolith - Peter Marton, RisingStack

Distributed tracing- Trace by RisingStack

- Zipkin

- Google Dapper white paper

- Transaction ID, Correlation ID

Page 49: Breaking Down the Monolith - Peter Marton, RisingStack

Response time

Page 50: Breaking Down the Monolith - Peter Marton, RisingStack

Even with very fast services

Page 51: Breaking Down the Monolith - Peter Marton, RisingStack

...you can have a slow app

:(

Page 52: Breaking Down the Monolith - Peter Marton, RisingStack

Because of network delays

Page 53: Breaking Down the Monolith - Peter Marton, RisingStack

Network delay is evil in microservices

Page 54: Breaking Down the Monolith - Peter Marton, RisingStack

Keep your services “close” to each other

Page 55: Breaking Down the Monolith - Peter Marton, RisingStack

Proxy approach

Page 56: Breaking Down the Monolith - Peter Marton, RisingStack

Proxy

Page 57: Breaking Down the Monolith - Peter Marton, RisingStack

Proxy- Re-route requests to services

- Authorize requests via access-service

- Decorate flippers (feature flag)

- Rewrite urls

Page 58: Breaking Down the Monolith - Peter Marton, RisingStack

Proxy- Evolutionary design (pro)

- Authentication in proxy (pro)

- Cookie handling at service (cons)

- Service format response for browser (cons)

Page 59: Breaking Down the Monolith - Peter Marton, RisingStack

Services interfaces are designed with browser in mind

Page 60: Breaking Down the Monolith - Peter Marton, RisingStack

API Gateway

Page 61: Breaking Down the Monolith - Peter Marton, RisingStack

API Gateway

Img: http://bits.citrusbyte.com/microservices

Page 62: Breaking Down the Monolith - Peter Marton, RisingStack

API Gateway- Everything that’s client(s) specific:

- Auth: Cookie headers, JWT token etc.

- Response format: JSON, XML etc.

- Combine resources: from multiple services

Page 63: Breaking Down the Monolith - Peter Marton, RisingStack

Security

Page 64: Breaking Down the Monolith - Peter Marton, RisingStack

Request signing- Trusted sources (services) on public channel

- node-http-signature

- Built-in in request and super-request npm

modules

https://github.com/joyent/node-http-signature

Page 65: Breaking Down the Monolith - Peter Marton, RisingStack

Request signing

Page 66: Breaking Down the Monolith - Peter Marton, RisingStack

Service teams

Page 67: Breaking Down the Monolith - Peter Marton, RisingStack

Your services are productsfor your customers and co-workers!

Page 68: Breaking Down the Monolith - Peter Marton, RisingStack

Service principles

Page 69: Breaking Down the Monolith - Peter Marton, RisingStack

Service principles

max. three depth call chains

Page 70: Breaking Down the Monolith - Peter Marton, RisingStack

Service principles

always backward compatible endpoints

Page 71: Breaking Down the Monolith - Peter Marton, RisingStack

Service principles

do not version services (only endpoints)

Page 72: Breaking Down the Monolith - Peter Marton, RisingStack

Service principles

use feature toggles heavily (flippers)

Page 73: Breaking Down the Monolith - Peter Marton, RisingStack

Service principles

good to start here:https://github.com/Yelp/service-principles

Page 74: Breaking Down the Monolith - Peter Marton, RisingStack

Documented API(s)

Page 75: Breaking Down the Monolith - Peter Marton, RisingStack

Documented API

enforce documentation

Page 76: Breaking Down the Monolith - Peter Marton, RisingStack

Documented API

update docstogether with code

Page 77: Breaking Down the Monolith - Peter Marton, RisingStack

Documented API

make it availablefor everyone

Page 78: Breaking Down the Monolith - Peter Marton, RisingStack

Thanks!

https://trace.risingstack.com