Learning the Three Types of Microservices SACon London 2018 Mike - - PowerPoint PPT Presentation

learning the three types of microservices
SMART_READER_LITE
LIVE PREVIEW

Learning the Three Types of Microservices SACon London 2018 Mike - - PowerPoint PPT Presentation

Learning the Three Types of Microservices SACon London 2018 Mike Amundsen @mamund API Academy http://apiacademy.co http://g.mamund.com/msabook @TheCAMBook "A reusable guide to the technology, business, and politics of doing APIs at


slide-1
SLIDE 1

Learning the Three Types

  • f Microservices

Mike Amundsen @mamund API Academy

SACon London 2018

slide-2
SLIDE 2
slide-3
SLIDE 3

http://apiacademy.co

slide-4
SLIDE 4

http://g.mamund.com/msabook

slide-5
SLIDE 5

@TheCAMBook

"A reusable guide to the technology, business, and politics of doing APIs at scale within the enterprise."

  • - Kin Lane, API Evangelist
slide-6
SLIDE 6

http://g.mamund.com/cambook

slide-7
SLIDE 7

Overview

  • Programming the Network
  • Microservices
  • Three Types of Microservice Components
  • Nygard's Stability Patterns
  • Applying Nygard to Microservices
  • But Wait, There's More...
slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14
slide-15
SLIDE 15

Traveling

slide-16
SLIDE 16

Traveling

slide-17
SLIDE 17

Traveling the Network

slide-18
SLIDE 18

Programming the Network

slide-19
SLIDE 19
slide-20
SLIDE 20
slide-21
SLIDE 21

"Data on the Inside vs. Data on the Outside, Helland (2005) http://cidrdb.org/cidr2005/papers/P12.pdf

"There is no simultaneity at a distance."

  • - Pat Helland (2005)

Programming the Network

Pat Helland

slide-22
SLIDE 22

Newton rules the "inside"

Sir Isaac Newton

slide-23
SLIDE 23

Einstein rules the "outside"

Albert Einstein

slide-24
SLIDE 24

"Data on the Inside vs. Data on the Outside, Helland (2005) http://cidrdb.org/cidr2005/papers/P12.pdf

Programming the Network

Pat Helland

slide-25
SLIDE 25

"Data on the Inside vs. Data on the Outside, Helland (2005) http://cidrdb.org/cidr2005/papers/P12.pdf

Programming the Network

Pat Helland

slide-26
SLIDE 26

"Data on the Inside vs. Data on the Outside, Helland (2005) http://cidrdb.org/cidr2005/papers/P12.pdf

Programming the Network

Pat Helland

slide-27
SLIDE 27

https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing

Fallacies of Distributed Computing (1994)

L Peter Deutsch

slide-28
SLIDE 28

The Language of the System, Rich Hickey (2012) https://www.youtube.com/watch?v=ROor6_NGIWU

The Language of the System (2012)

Rich Hickey

slide-29
SLIDE 29

Programming the Network brings new challenges

slide-30
SLIDE 30

Microservices

slide-31
SLIDE 31

"An approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms."

  • - Martin Fowler, 2014

https://www.thoughtworks.com/insights/blog/microservices-nutshell

slide-32
SLIDE 32

"Emphasizes scalability of component interactions, generality of interfaces, independent deployment of components, and intermediary components."

  • - Roy Fielding, 2000
slide-33
SLIDE 33

"A universal linked information system, in which generality and portability are [most] important."

  • - Tim Berners-Lee, 1989
slide-34
SLIDE 34

Microservice Characteristics

  • Make each program to one thing well
  • Expect the output of every program to be the input of

another program

  • Design and build software to be tried early
  • Use tools to lighten the programming task
slide-35
SLIDE 35

Unix Operating Principles (1978)

  • Make each program to one thing well
  • Expect the output of every program to be the input of

another program

  • Design and build software to be tried early
  • Use tools to lighten the programming task

https://en.wikipedia.org/wiki/Unix_philosophy

slide-36
SLIDE 36

Loosely-coupled components running in an engineered system.

slide-37
SLIDE 37

Three Types of Microservices

slide-38
SLIDE 38

Three Types of Microservices

  • Stateless
  • Persistence
  • Aggregator
slide-39
SLIDE 39

Stateless Microservices

slide-40
SLIDE 40

Stateless Microservices

  • Simple processors (converters, translators, etc.)
  • No dependence on other microservices
  • No local data storage (disk I/O)

The most common MSC example, but the least useful!

slide-41
SLIDE 41

Stateless Microservices

  • No shared state
  • Easy to replace
  • Easy to scale up

Ephemeral Computing

slide-42
SLIDE 42

Stateless Microservices

WARNING: NOT REAL CODE!

slide-43
SLIDE 43

Persistence Microservices

slide-44
SLIDE 44

Persistence Microservices

  • Simple (local) storage (reads and/or writes)
  • Disk I/O dependent
  • Possibly VM or one-U dependent

Commonly needed MSC, not the easiest to implement.

slide-45
SLIDE 45

Persistence Microservices

  • System of Record/Source of Truth
  • Relatively easy to scale for reads (CQRS)
  • No cross-service two-phase commits (Saga)

Durable Storage

slide-46
SLIDE 46

Persistence Microservices

WARNING: NOT REAL CODE!

slide-47
SLIDE 47

Aggregator Microservices

slide-48
SLIDE 48

Aggregator Microservices

  • Depends on other ("distant") microservices
  • Network dependent
  • Usually Disk I/O dependence, too

The most often-needed; most challenging, too.

slide-49
SLIDE 49

Aggregator Microservices

  • Sequence vs. Parallel calls
  • Timing is everything
  • Easy to scale (should be…)

Workflow Choreography

slide-50
SLIDE 50

Aggregator Microservices

WARNING: NOT REAL CODE!

slide-51
SLIDE 51

Three Types of Microservices

  • Stateless (ephemeral)
  • Persistence (durable)
  • Aggregator (workflow)
slide-52
SLIDE 52

But, what about the network?

slide-53
SLIDE 53

Nygard's Stability Patterns

slide-54
SLIDE 54

“Bugs will happen. They cannot be eliminated, so they must be survived instead.”

  • - Michael T. Nygard
slide-55
SLIDE 55
slide-56
SLIDE 56

Nygard Stability Patterns

  • Timeout
  • Circuit Breaker
  • Bulkhead
  • Steady State
  • Fail Fast
  • Handshaking
slide-57
SLIDE 57

"Nygard Stability Patterns" -- Timeout

"The timeout is a simple mechanism allowing you to stop waiting for an answer once you think it will not come."

  • - Chapter 5.1
slide-58
SLIDE 58

"Nygard Stability Patterns" -- Timeout

"The timeout is a simple mechanism allowing you to stop waiting for an answer once you think it will not come."

  • - Ch 5.1

WARNING: NOT REAL CODE!

slide-59
SLIDE 59

"Nygard Stability Patterns" -- Circuit Breaker

"Circuit breakers are a way to automatically degrade functionality when the system is under stress."

  • - Chapter 5.2
slide-60
SLIDE 60

"Nygard Stability Patterns" -- Circuit Breaker

"Circuit breakers are a way to automatically degrade functionality when the system is under stress."

  • - Chapter 5.2
slide-61
SLIDE 61

"Nygard Stability Patterns" -- Bulkhead

"The bulkhead enforces a principle of damage containment."

  • - Chapter 5.3
slide-62
SLIDE 62

"Nygard Stability Patterns" -- Bulkhead

"The bulkhead enforces a principle of damage containment."

  • - Chapter 5.3
slide-63
SLIDE 63

"Nygard Stability Patterns" -- Bulkhead

"The bulkhead enforces a principle of damage containment."

  • - Chapter 5.3
slide-64
SLIDE 64

"Nygard Stability Patterns" -- Steady State

"The system should be able to run indefinitely without human intervention."

  • - Chapter 5.4
  • Avoid fiddling
  • Purge data w/ app logic
  • Limit caching
  • Roll the logs
slide-65
SLIDE 65

"Nygard Stability Patterns" -- Steady State

"The system should be able to run indefinitely without human intervention."

  • - Chapter 5.4
  • Avoid fiddling
  • Purge data w/ app logic
  • Limit caching
  • Roll the logs
slide-66
SLIDE 66

"Nygard Stability Patterns" -- Fail Fast

"If the system can determine in advance that it will fail at an

  • peration, it’s always better to fail fast."
  • - Chapter 5.5
slide-67
SLIDE 67

"Nygard Stability Patterns" -- Fail Fast

"If the system can determine in advance that it will fail at an

  • peration, it’s always better to fail fast."
  • - Chapter 5.5

WARNING: NOT REAL CODE!

slide-68
SLIDE 68

"Nygard Stability Patterns" -- Handshaking

"Handshaking is all about letting the server protect itself by throttling its own workload."

  • - Chapter 5.6
slide-69
SLIDE 69

"Nygard Stability Patterns" -- Handshaking

"Handshaking is all about letting the server protect itself by throttling its own workload."

  • - Chapter 5.6

WARNING: NOT REAL CODE!

slide-70
SLIDE 70

"Nygard Stability Patterns" -- Cache

"Caching can reduce the load on the server and cut response times to a fraction of what they would be without caching."

  • - Chapter 10.2
slide-71
SLIDE 71

"Nygard Stability Patterns" -- Cache

"Caching can reduce the load on the server and cut response times to a fraction of what they would be without caching."

  • - Chapter 10.2

WARNING: NOT REAL CODE!

slide-72
SLIDE 72

"Nygard Stability Patterns" -- Cache

"Caching can reduce the load on the server and cut response times to a fraction of what they would be without caching."

  • - Chapter 10.2

WARNING: NOT REAL CODE!

slide-73
SLIDE 73

Stabilizing Stateless Microservices

slide-74
SLIDE 74

Stateless Microservices

WARNING: NOT REAL CODE!

slide-75
SLIDE 75

Networked Stateless

  • What if the work takes too long?
slide-76
SLIDE 76

Stable Stateless Microservices

  • 1. Fail-Fast

WARNING: NOT REAL CODE!

slide-77
SLIDE 77

Stabilizing Persistence Microservices

slide-78
SLIDE 78

Persistence Microservices

WARNING: NOT REAL CODE!

slide-79
SLIDE 79

Networked Persistence

  • What if the work takes too long?
  • What is the dependent service doesn't respond in time?
  • What if the dependent service is down?
  • What if the storage overflows (data, logs, etc.)?
slide-80
SLIDE 80

Stable Persistence Microservices

  • 1. Fail-Fast
  • 2. Timeout
  • 3. Circuit Breaker
  • 4. Steady State

WARNING: NOT REAL CODE!

slide-81
SLIDE 81

Stabilizing Aggregator Microservices

slide-82
SLIDE 82

Aggregator Microservices

WARNING: NOT REAL CODE!

slide-83
SLIDE 83

Networked Aggregators

  • What if the work takes too long?
  • What if a dependent services doesn't respond in time?
  • What if a dependent service is down?
  • What if storage overflows (data, logs, etc.)?
  • What if a dependent service is unhealthy?
  • What if traffic for a service spikes?
slide-84
SLIDE 84

Stable Aggregator Microservices

  • 1. Fail-Fast
  • 2. Timeout
  • 3. Circuit Breaker
  • 4. Steady State
  • 5. Handshaking
  • 6. Bulkhead

WARNING: NOT REAL CODE!

slide-85
SLIDE 85

Nygard's Admonition...

slide-86
SLIDE 86

Applying Nygard's Patterns to Services

  • Stateless

○ fail fast

  • Persistence

○ fail fast, timeout, circuit breaker, steady state

  • Aggregation

○ fail fast, timeout, circuit breaker, steady state, handshaking, bulkhead

Apply Nygard's Stability Patterns to improve the health

  • f your components and your system.
slide-87
SLIDE 87
slide-88
SLIDE 88

https://blogs.technet.microsoft.com/michael_platt/2005/08/30/integration-and-interoperability/

"Interoperation is peer to peer. Integration is where a system is subsumed within another."

  • - Michael Platt, Microsoft

Aim for Interop, not Integration...

slide-89
SLIDE 89

Aim for Interop, not Integration...

By Wkinterop - Powerpoint -> PNG, CC BY-SA 3.0, https://en.wikipedia.org/w/index.php?curid=35139609

slide-90
SLIDE 90

https://blogs.technet.microsoft.com/michael_platt/2005/08/30/integration-and-interoperability/

"There is no simultaneity at a distance."

  • - Pat Helland, Salesforce

Include time/distance in your models

Pat Helland

slide-91
SLIDE 91

"I'm sorry that coined the term 'objects' for this

  • topic. The big idea is 'messaging'."

Alan Kay, 1998

Include time/distance in your models

slide-92
SLIDE 92

https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing

L Peter Deutsch

Remember, you're programming the network

slide-93
SLIDE 93
  • Safety

Remember, you're programming the network

https://www.w3.org/2011/10/integration-workshop/p/hypermedia-oriented-design.pdf

slide-94
SLIDE 94
  • Safety

The HTTP protocol supports a number of "safe" actions such as HEAD, and GET. The HTTP methods PUT, POST, and DELETE are categorized as "unsafe" actions.

Remember, you're programming the network

https://www.w3.org/2011/10/integration-workshop/p/hypermedia-oriented-design.pdf

slide-95
SLIDE 95
  • Safety
  • Idempotence

Remember, you're programming the network

https://www.w3.org/2011/10/integration-workshop/p/hypermedia-oriented-design.pdf

slide-96
SLIDE 96
  • Safety
  • Idempotence

In HTML when a FORM element has the METHOD property set to "get" this represents an idempotent action. When the same property is set to "post" the affordance represents a non-idempotent action.

Remember, you're programming the network

https://www.w3.org/2011/10/integration-workshop/p/hypermedia-oriented-design.pdf

slide-97
SLIDE 97

Other Considerations...

  • Interop vs. Integration
  • Time & Distance
  • Safety & Idempotence
slide-98
SLIDE 98

So...

slide-99
SLIDE 99

We need microservices...

slide-100
SLIDE 100

So that we can program the network...

slide-101
SLIDE 101

Which means applying patterns to our code..,

  • 1. Fail-Fast
  • 2. Timeout
  • 3. Circuit Breaker
  • 4. Steady State
  • 5. Handshaking
  • 6. Bulkhead
slide-102
SLIDE 102

And that means understanding the role of semantics...

slide-103
SLIDE 103

And the role of distance & time...

slide-104
SLIDE 104

And constantly reminding ourselves of the challenge.

slide-105
SLIDE 105

That's a lot!

slide-106
SLIDE 106

The Best Software Architecture

"The best software architecture 'knows' what changes often and makes that easy."

  • Paul Clements
slide-107
SLIDE 107

Let's continue the conversation...

slide-108
SLIDE 108

Learning the Three Types

  • f Microservices

Mike Amundsen @mamund API Academy

SACon London 2018

slide-109
SLIDE 109

Learning the Three Types

  • f Microservices

Mike Amundsen @mamund API Academy

SACon London 2018