microservices practitioner summit jan '15 - don't build a distributed monolith - ben...

91
Ben Christensen @benjchristensen Microservices Summit – Jan 2016 Avoid Distributed Monoliths

Upload: datawire

Post on 10-Jan-2017

2.265 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Ben Christensen@benjchristensen

Microservices Summit – Jan 2016Avoid Distributed Monoliths

Page 2: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Don't Couple SystemsWith Binary Dependencies

Page 3: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Shared Libraries&

Network Clients

Page 4: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Shared Librariesthat are required

Page 5: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Shared Librariesoften called "the platform"

Page 6: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Shared Libraries(and the transitive variety)

Page 7: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Network Clientsof the "official" variety

Page 8: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

What does binary coupling look like?

Page 9: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Common Examples ...

RoutingDiscoveryLoggingTracing

Fault Injection

GuavaRxJavaLog4j

Apache CommonsSpringetc ...

SpringStrutsNetty

TomcatApache HttpClient

Page 10: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Not long until 100s of libraries

are required to exist in a given system

Page 11: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Not long until 100s of libraries

are required to exist in a given system

This is a "distributed monolith"

Page 12: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Have you ever seen it take

months to upgrade a library across your

company?

Page 13: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Have you ever seen it take

months to upgrade a library across your

company?

This is a "distributed monolith"

Page 14: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Will it take a ~year to use a new language for

a new service?

Page 15: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Will it take a ~year to use a new language for

a new service?

This is a "distributed monolith"

Page 16: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

These Symptoms == Lost BenefitsLost Benefits

Page 17: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Lost Benefits

Polyglot

Page 18: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Lost Benefits

Polyglot

Can Java, .Net, Node.js, Go, Rust, C++, etc co-exist in your system? idiomatically?

Page 19: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Lost Benefits

Organizational and Technical Decoupling

Page 20: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Lost Benefits

Organizational and Technical Decoupling

Can an individual team adopt a new language or platform without convincing a central authority?

Page 21: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Lost Benefits

Organizational and Technical Decoupling

Can individual teams choose a different concurrency model than the "core platform"?

Page 22: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Lost Benefits

Temporal Decoupling

Page 23: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Lost Benefits

Temporal Decoupling

Can an individual team upgrade their networking stack?

Page 24: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Lost Benefits

Temporal Decoupling

Can they upgrade to the newest version of Guava?

Page 25: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

But isn't shared code good?

Page 26: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

But isn't shared code good?

Not Always

Page 27: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Not necessarily the right principle to prioritize across system boundaries.

But isn't shared code good?

Page 28: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

"First, you lose true technology heterogeneity. The library typically has to be in the same language, or at the very

least run on the same platform."

"Building Microservices" – Sam Newman

Page 29: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

"Second, the ease with which you can scale parts of your system independently

from each other is curtailed."

"Building Microservices" – Sam Newman

Page 30: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

"...you cannot deploy a new library without redeploying the entire process, so your ability to deploy changes in isolation

is reduced."

"Building Microservices" – Sam Newman

Page 31: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

"And perhaps the kicker is that you lack the obvious seams around which to erect architectural safety measures to ensure

system resiliency."

"Building Microservices" – Sam Newman

Page 32: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

But DRY!?!?

Page 33: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

"Building Microservices" – Sam NewmanPage 59, "DRY and the Perils of Code Reuse in a Microservice World"

"This approach, however, can be deceptively dangerous in a microservice

architecture."

Page 34: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

"Building Microservices" – Sam NewmanPage 59, "DRY and the Perils of Code Reuse in a Microservice World"

"One of the things we want to avoid at all costs is overly coupling a microservice and consumers such that any small change to

the microservice itself can cause unnecessary changes to the consumer."

Page 35: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

"Building Microservices" – Sam NewmanPage 59, "DRY and the Perils of Code Reuse in a Microservice World"

"If your use of shared code ever leaks outside your service boundary, you have introduced a potential form of coupling."

Page 36: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

"Building Microservices" – Sam NewmanPage 59, "DRY and the Perils of Code Reuse in a Microservice World"

"The evils of too much coupling between services are far worse than the problems

caused by code duplication."

Page 37: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Page 59"DRY and the Perils of Code Reuse

in a Microservice World"

Just go read it ...

Page 38: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Observed Outcomes

Page 39: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Client library becomes ONLY official way to access the service.

Page 40: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Service logic drifts into the client.

Page 41: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Nearly impossible to adopt new architectures, languages, etc.

Page 42: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Far Reaching Effects

Page 43: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Consuming team is at the mercy of the service-owner.

Page 44: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Brittle "Black Market" Clients

Page 45: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Projection of technical decisions, architecture, and resource utilization

on all service consumers.

Page 46: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Operational complexity is spread to all consumers.

Page 47: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Team consuming 10 services now potentially has arbitrary code from 10

teams to operate and debug.

Page 48: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

So what is the alternative?

Page 49: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Contracts & Protocols!

Page 50: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Like programming languages use interfaces and APIs.

Page 51: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Services should hide all implementation details.

Page 52: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Network Protocol & Data Contract

Consume with any language and any technology!Iterate and change over time!

No dependency on service implementation!

Page 53: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Just like the Internet!

Page 54: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

But, but, but!!!

Page 55: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

What about ... ?

Page 56: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

What about ... ?

standardized logging, fault injection,distributed tracing, discovery, routing,

bulkheading, etc, etc, etc

Page 57: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Legitimate Needs for Standardization

Page 58: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Standardization Does Not Need Binary Coupling

Page 59: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Standardization via Protocols & Contracts

Page 60: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Enabled via independent common libraries that consumers can choose to use

... or reimplement to suit their needs.

Standardization via Protocols & Contracts

Page 61: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Standardization via Protocols & Contracts

Example

Public AWS APIswith

various available clients

Page 62: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Standardization via Auditing

Page 63: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Standardization via Auditing

An "integration test" for new services.

Tracing? Logging? Fault injection? Routing?

Page 64: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Doesn't this make it harder to start a new service?

Page 65: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

It could. But it doesn't need to.

Page 66: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Common "Tech Stacks"do not break this pursuit of decoupling

Page 67: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Key is that existence of protocols and contracts

allow new stacks to be built.

Page 68: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Anything achieved by any libraryshould be replaceable by coding against

protocols and contracts.

Page 69: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Litmus test ...

Can a group of engineers wanting to use the new hotness

build a new stack without convincing the rest of the company?

and without resorting to sidecars and proxies?

Page 70: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

What might this look like?

Page 71: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Shared Libraries&

Network Clients

Page 72: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Transitive Dependencies

Page 73: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Shade Internal Dependencies

Transitive Dependencies

Page 74: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

or copy/paste the needed method!

Transitive Dependencies

Page 75: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

If part of public API ...

Transitive Dependencies

Page 76: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

If part of public API ...

it can't ever have a breaking change.

Transitive Dependencies

Page 77: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

(so no libraries that bump their major version every 6-12 months)

Transitive Dependencies

If part of public API ...

it can't ever have a breaking change.

Page 78: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

OkHttp & RxJava as examples

http://jakewharton.com/java-interoperability-policy-for-major-version-updates/https://publicobject.com/2015/12/12/com-squareup-okhttp3/

https://github.com/ReactiveX/RxJava/issues/3170 https://github.com/ReactiveX/RxJava/issues/3173

Transitive Dependencies

Page 79: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Shared Libraries&

Network Clients

Page 80: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

/pets: get: description: Returns all pets from the system that the user has access to produces: - application/json responses: '200': description: A list of pets. schema: type: array items: $ref: '#/definitions/pet'

Swagger / OpenAPI

Page 81: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Swagger / OpenAPI

Page 82: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

5: optional TweetType tweetType = TweetType.TWEET; 16: optional string language = "english";}

typedef list<Tweet> TweetList

struct TweetSearchResult { 1: TweetList tweets;}

exception TwitterUnavailable { 1: string message;}

const i32 MAX_RESULTS = 100;

service Twitter { void ping(), bool postTweet(1:Tweet tweet) throws (1:TwitterUnavailable unavailable), TweetSearchResult searchTweets(1:string query); oneway void zip()}

Page 83: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

message Person { required string name = 1; required int32 id = 2; optional string email = 3;

enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; }

message PhoneNumber { required string number = 1; optional PhoneType type = 2 [default = HOME]; }

repeated PhoneNumber phone = 4;}

message AddressBook { repeated Person person = 1;}

Page 84: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

@version("0.1.0")package hello {

@doc("A value class for Request data for the hello service.") class Request { String text; }

@doc("A value class for Response data from the hello service.") class Response { @doc("A greeting from the hello service.") String result; }

@doc("The hello service.") interface Hello extends Service {

@doc("Respond to a hello request.") @delegate(self.rpc, {"timeout": 3000}) Response hello(Request request);

}

@doc("A client adapter for the hello service.") class HelloClient extends Client, Hello {}

@doc("A server adapter for the hello service.") class HelloServer extends Server<Hello> {}

}

Quark by DataWire

Page 85: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

/pets: get: description: Returns all pets from the system that the user has access to produces: - application/json responses: '200': description: A list of pets. schema: type: array items: $ref: '#/definitions/pet'

Single | Multi | N | Infinite

Beyond Request/Response

Page 86: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Caching Tiers

Default Fallback Values

Flow Control & Health

Page 87: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

So why do we fail at this so often?

Page 88: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Ease.

Short-term feels more productive.

Service-owners have "first-mover" advantage.

Page 89: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Delayed cost of decoupling is high. And it's very hard.

Page 90: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

The solutions have limited tax on the short-term.

So let's look beyond the short-term ease.

Page 91: Microservices Practitioner Summit Jan '15 - Don't Build a Distributed Monolith - Ben Christensen, Facebook

Avoid Binary Couplingby using

Contracts, Protocols & Automated Tooling