microservices 101: exploiting reality's constraints with technology

50
Deputy CTO @viktorklang Microservices 101: ploiting Reality's Constraints with Technolo

Upload: typesafeinc

Post on 12-Aug-2015

3.799 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Microservices 101: Exploiting Reality's Constraints with Technology

√Deputy CTO

@viktorklang

Microservices 101:Exploiting Reality's Constraints with Technology

Page 2: Microservices 101: Exploiting Reality's Constraints with Technology

2

Connectedness

«Software is becomingincreasingly interconnected»

Page 3: Microservices 101: Exploiting Reality's Constraints with Technology

4

Klang’s Conjecture

«If you cannot solve a problem without programming;you cannot solve a problem with programming.»

Page 4: Microservices 101: Exploiting Reality's Constraints with Technology

Reality Imaginary>

Page 5: Microservices 101: Exploiting Reality's Constraints with Technology

assert(nrOfDimensions > 0)

Page 6: Microservices 101: Exploiting Reality's Constraints with Technology

Reality• separation in space & time gives us

• communication for coordination

• variable delays

• partial failures

• partial/local/stale knowledge

9

Page 7: Microservices 101: Exploiting Reality's Constraints with Technology

10

System

«a set of things working together as parts of a mechanism or an interconnecting network;

a complex whole»

noun

Page 8: Microservices 101: Exploiting Reality's Constraints with Technology

Systems• Purpose is (typically) simple

• Complex inner workings

• Consist of collaborating components

• Components can be systems themselves

• Components are as simple as feasible,

but not simpler

11

Page 9: Microservices 101: Exploiting Reality's Constraints with Technology

12

Resilience

«Any sufficiently complex system is alwaysrunning in degraded mode»

— Richard I. Cook, MD “How complex systems fail” (paraphrased)

Page 10: Microservices 101: Exploiting Reality's Constraints with Technology

13

Conway’s Law

«Organizations which design systems … are constrained to produce designs which are copies of the communication structures of these organizations» —

Melvin Conway

Page 11: Microservices 101: Exploiting Reality's Constraints with Technology

Communication• The production and consumption of messages

• Messaging means that we need to be able to address recipients

• Addresses/Identities are important!

• They are knowledge that can be shared

• Messages can become lost, delayed or misunderstood

14

Page 12: Microservices 101: Exploiting Reality's Constraints with Technology

Think ‘Reliability’• Are we ever guaranteed delivery?

• at-most-once

• at-least-once

• exactly-once

• It’s not about guarantees,it’s about reliability

15

Page 13: Microservices 101: Exploiting Reality's Constraints with Technology

Two-faced Commit

16

Page 14: Microservices 101: Exploiting Reality's Constraints with Technology

Encoding & Medium• Embrace protocols

• Overcome the fear of using multiple media• Removes the single-point of failure

• No encoding is one-size-fits-all

• Allow protocols to evolve over time

17

Page 15: Microservices 101: Exploiting Reality's Constraints with Technology

Quiz!

Page 16: Microservices 101: Exploiting Reality's Constraints with Technology

299 792 458

Page 17: Microservices 101: Exploiting Reality's Constraints with Technology

340.29

Page 18: Microservices 101: Exploiting Reality's Constraints with Technology

~0.4

Scharnowski et al., 2009; Heinen, Jolij, & Lamme, 2005

Page 19: Microservices 101: Exploiting Reality's Constraints with Technology

22

Universal Scalability Law

«N is the number of users;or the number of CPUs, is the contention level,α the coherency latency.β

C is the relative capacity»

Page 20: Microservices 101: Exploiting Reality's Constraints with Technology

Perfect

23

Load

Throughp

ut

Page 21: Microservices 101: Exploiting Reality's Constraints with Technology

Imperfect

24

Load

Throughp

ut

Page 22: Microservices 101: Exploiting Reality's Constraints with Technology

Bounded

25

Load

Throughp

ut

Page 23: Microservices 101: Exploiting Reality's Constraints with Technology

Regressive

26

Load

Throughp

ut

Page 24: Microservices 101: Exploiting Reality's Constraints with Technology

Discovery is EC• Since knowledge is always

local/partial/stale

• Discovery of components must embraceeventual consistency

• Conflict-Free Replicated Datatypes(CRDTs) show great promise here

27

Page 25: Microservices 101: Exploiting Reality's Constraints with Technology

Latency is

the enemyof responsiveness

Page 26: Microservices 101: Exploiting Reality's Constraints with Technology

Expectation management

• To humans, fast & slow is about perception

• Manageable

• The key is consistency—because reliability

• Not the same for machine-to-machine

29

Page 27: Microservices 101: Exploiting Reality's Constraints with Technology

Burstiness• Most communication is bursty

• Some is predictable

• Some is not

• requires flow control

• can leverage elasticity

• load shedding can cause burstiness

30

Page 28: Microservices 101: Exploiting Reality's Constraints with Technology

31

Little’s Law

«L is mean length;λ is effective arrival rate;W is mean time spent»

L=λW

Page 29: Microservices 101: Exploiting Reality's Constraints with Technology

32

Little’s Law

«L is mean length;λ is effective arrival rate;W is mean time spent»

W=L / λ

Page 30: Microservices 101: Exploiting Reality's Constraints with Technology

Flow control / Back pressure

34

• Buffers are only grease between cogs

• They do not solve overload problems

• Load shedding does not inform sender

• When possible, use effectively bounded, asynchronous, non-blocking, demand-driven back pressure

www.reactive-streams.org

Page 31: Microservices 101: Exploiting Reality's Constraints with Technology

36

Requirements Push Pull

support potentially unbounded sequences 😃 😃

sender runs separately from receiver 😃 😃

rate of reception may vary from rate of sending 😃 😃

dropping elements should be a choice and not a necessity 💩 😃

minimal (if any) overhead in terms of latency and throughput 😃 💩

Comparing Push vs Pull

Page 32: Microservices 101: Exploiting Reality's Constraints with Technology

&37

Supply

Demand

Page 33: Microservices 101: Exploiting Reality's Constraints with Technology

38

Publisher Subscriber

data

demand

Page 34: Microservices 101: Exploiting Reality's Constraints with Technology

• “push” when subscriber is faster

• “pull” when publisher is faster

• switches automatically between both

• batching demand allows batching ops

39

DynamicPush–Pull

Reactive Streams

Page 35: Microservices 101: Exploiting Reality's Constraints with Technology

40

Requirements Push Pull Both

support potentially unbounded sequences 😃 😃 😃

sender runs separately from receiver 😃 😃 😃

rate of reception may vary from rate of sending 😃 😃 😃

dropping elements should be a choice and not a necessity 💩 😃 😃

minimal (if any) overhead in terms of latency and throughput 😃 💩 😃

Comparing Push vs Pull vs Both

🌟

Page 36: Microservices 101: Exploiting Reality's Constraints with Technology

Stream splitting

41

demand

data

splitting the data means merging the demand

Page 37: Microservices 101: Exploiting Reality's Constraints with Technology

Stream merging

42

merging the data means splitting the demand

Page 38: Microservices 101: Exploiting Reality's Constraints with Technology

Collaboration• Assume no malice

• Sanity check inputs & outputs

• Never wait forever or actively

• There’s always a Plan B

43

Page 39: Microservices 101: Exploiting Reality's Constraints with Technology

44

Circuit Breakers

Page 40: Microservices 101: Exploiting Reality's Constraints with Technology

Responsibility• Having multiple responsibilities

• creates conflict regarding priorities

• lowers reliability

• increases accidental damage

• decreases predictability

• hides the cause from the outside

45

Page 41: Microservices 101: Exploiting Reality's Constraints with Technology

Resilience• Never assume that other entities are immortal

• Treat expectation violations as failures

• Always have a Plan B

• Clients are not responsible to fix a faulty provider

• Fail fast & predictably

46

Page 42: Microservices 101: Exploiting Reality's Constraints with Technology

49

Zombie Apocalypse

Page 43: Microservices 101: Exploiting Reality's Constraints with Technology

50

Supervision• Responsibility to deal with the failure/corruption of other

• Does not place the burden of fixing it on the collaborators

«Quis custodiet ipsos custodes?»— Decimus Iunius Iuvenalis

Page 44: Microservices 101: Exploiting Reality's Constraints with Technology

Harden up• Isolate

• Replicate

• Shard

• Control flow

• Predict changes in load

• React to changes in load

51

Page 45: Microservices 101: Exploiting Reality's Constraints with Technology

53

E l a s t i c i t y

«Lagom is a Swedish word, meaning "just the right amount"»

— Wikipedia

Page 46: Microservices 101: Exploiting Reality's Constraints with Technology

• Mind shift in going async

• Mind shift in dealing with failure

• Importance of appropriate configuration

• Integration using blocking APIs requires care

• Avoid the distributed monolith

• Deployment requires modern tooling

55

Transitioning

Page 47: Microservices 101: Exploiting Reality's Constraints with Technology

Summary• Isolate & Contain + Distribute & Replicate

• Single Purpose Components

• Communicate asynchronously

• Divide & Conquer

• Avoid coordination & minimize contention

• Embrace inconsistency

• Strive for lagom amount of utilisation

56

Page 48: Microservices 101: Exploiting Reality's Constraints with Technology

The Reactive Traits

www.reactivemanifesto.org

Page 49: Microservices 101: Exploiting Reality's Constraints with Technology

Perhaps you’d also like…

MADE FOR MICROSERVICES

WEBINAR: Introducing Typesafe ConductR

WATCH NOW

ACTIVATOR TEMPLATE

Try this Microservices Seed Project

CHECK IT OUT

HAVE QUESTIONS?

Get in touch with Typesafe today!

CONTACT US

Page 50: Microservices 101: Exploiting Reality's Constraints with Technology

©Typesafe 2015 – All Rights Reserved√