microservice architecture...microservices, the term 4 “microservice” venice software architects...

56
Microservice architecture A systems integration lecture Ing. Marek Schmidt Principal Quality Engineer, Red Hat Middleware 2017-03-03

Upload: others

Post on 31-Dec-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architecture

A systems integration lecture

Ing. Marek SchmidtPrincipal Quality Engineer, Red Hat Middleware

2017-03-03

Page 2: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures2

MICROSERVICES

ConceptsSmall & autonomous, loose coupling & tight cohesion, Conway’s law, resilience & scaling

TestingConsumer-driven contracts, Canary releases, Semantic monitoring

MonitoringDistributed logging, Correlation IDs, Distributed Tracing

PatternsTimeouts, Circuit breakers, Bulkheads, Idempotency, Fail fast, Decoupling Middleware

Introduction

Page 3: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Introduction

Page 4: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

MICROSERVICES, THE TERM

4

“microservice”Venice software architects workshop

‘11

“Micro services” Java, the Unix Way, James Lewis

33rd Degree, Kraków

‘12

“Fine grained SOA” Adrian Cockcroft @ Netflix

‘14‘07 ‘09

Page 5: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

NETFLIX STORY

5

○ ...the very first piece of Netflix that was running in the cloud was the search auto-complete service. ... That ran as a service, there was no graphics around it. All of the website that was supporting that was still running in the datacenter. It’s just that as you type that word in, it was sent off to a search index in the cloud.... .

○ ..It’s a trivial piece of technology, but it taught us everything about pushing production systems to the cloud, hooking them up to a load balancer and the tooling we needed to do it. Two or three engineers, I think, worked on getting that built in a month or so maybe. It was a very small piece of work, plus the tooling, but it proved certain things worked. Then, we got the first bits and pieces up and running in the cloud one piece at a time...

-- Adrian Cockcroft

Page 6: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures6

-- Lions commentary on UNIX 2nd Edition

JAVA, THE UNIX WAY

Page 7: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures7

Martin Fowler - Microservicesa definition of this new architectural term

https://martinfowler.com/articles/microservices.html

Page 8: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Concepts

Page 9: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

SMALL AND AUTONOMOUS

9

Small

● Each application only does one thing● Small enough to fit in your head

Packaging and Deployment

● single “fat jar” file● independently testable● installable as any system service● containers

○ fat jar vs. shared layers

Page 10: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

SMALL AND AUTONOMOUSe.g. as a SystemD service

[Unit]Description=Store CatalogueAfter=network.service

[Service]Environment=SPRING_DATASOURCE_URI=jbdc://foo/barExecStart=/bin/sh -c 'java -jar /opt/store/catalogue.jar'User=catalogue

[Install]WantedBy=multi-user.target

10

Page 11: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

LOOSE COUPLING

11

...and tight cohesion

● The Single Responsibility Principle○ Gather together those things that change for the same reason, and

separate those things that change for different reasons.

● Services separated via network calls○ APIs

■ JSON/XML over HTTP (REST), Messaging■ versioning

Page 12: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

CONWAY’S LAW

12

Organizations which design systems are constrained to produce designs whose structure are copies of the communication structures of these organizations -- Melvin Conway 1968

● Each application in separate source repository○ Treat common code as any other shared library

● Mythical Man-Month● 2 pizza rule

Page 13: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

RESILIENCE AND SCALING

13

Design for failure

● Resilience○ A resilient system keeps processing transactions, even when there are

transient impulses, persistent stresses, or component failures disrupting normal processing.

○ Ability to contain a failure to the failing component.

● Scaling○ horizontal scaling

■ fault tolerance via redundancy

Page 14: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

LOAD BALANCING

14

Load balancer

http://foo-service

Page 15: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

WORKER BASED SCALING

15

Queue

activemq:queue:FOO

Page 16: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Testing

Page 17: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

TEST CATEGORIES

17

Store catalogue service

Store Manager Mgmt.

Web Shop

Store inventory service

Page 18: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

TEST CATEGORIES

18

Store catalogue service

Store Manager Mgmt.

Web Shop

Store inventory service

Unit tests

Individual unit tests scope

Page 19: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

TEST CATEGORIES

19

Store catalogue service

Store Manager Mgmt.

Web Shop

Store inventory service

Service tests

Service tests scope

Page 20: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

TEST CATEGORIES

20

Store catalogue service

Store Manager Mgmt.

Web Shop

Store inventory service

End-to-end tests

End-to-end tests scope

Page 21: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

TEST CATEGORIES

21

Store catalogue service

Store Manager Mgmt.

Web Shop

Store inventory service

Consumer-driven contracts

Store Manager Mgmt. CDC Test scope

Mocked or Stubbed

Page 22: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

TEST CATEGORIES

22

Unit tests

Service and consumer-driven tests

End-to-endtests

Page 23: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

TESTING IN PRODUCTION

23

Testing environment is never identical to production

● Blue/green deployment● Canary release● Semantic monitoring● Chaos monkey

Page 24: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Monitoring

Page 25: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

LOGGING

25

aggregation

● ELK / EFK● Correlation ID● Distributed Tracing

Page 26: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

DISTRIBUTED TRACING

26

Page 27: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

DISTRIBUTED TRACING

27

Page 28: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

MONITORING

28

individual services

● Mechanisms○ JMX / Jolokia

● Data○ Traffic indicators○ Resource pool health○ DB connections health○ Integration point health○ Cache health

Page 29: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

OPERATIONS DATABASE

29

Apps

Servers

Batch jobs

OpsDB

Capacity planning

Dashboard

Reports

status variablesbusiness metricsinternal metrics

performanceutilization

Page 30: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Patterns

Page 31: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

TIMEOUTS

31

networks are fallible

● prevents calls to integration points from causing blocked threads○ cascading failures

● thread / connection pools● consider delayed retries / queueing

○ Beware of Acts of self-denial

Page 32: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

CIRCUIT BREAKER

32

“don’t do it if it hurts”

Page 33: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

CIRCUIT BREAKER

33

Service functions normally

Some service

Service boundary

Calling code

Calling code

Closed

Page 34: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

CIRCUIT BREAKER

34

Calls starting to timeout or returning errors

Some service

Service boundary

Calling code

Calling code

Closed

Page 35: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

CIRCUIT BREAKER

35

Connection stopped when threshold reached

Some service

Service boundary

Calling code

Calling code

Open

Requests fail fast

Page 36: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

CIRCUIT BREAKER

36

Retry after grace period, or occasional health check

Some service

Service boundary

Calling code

Calling code

Half-open

Page 37: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

CIRCUIT BREAKER

37

Connection reset when healthy threshold reached

Some service

Service boundary

Calling code

Calling code

Closed

Page 38: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

BULKHEADS

38

isolating from failure

● Separation of concerns (separate service)● Separating thread/connection pools

Page 39: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

BULKHEADS

39

Store

Catalog service

Ordering service

Connection pool

Page 40: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

BULKHEADS

40

Store

Catalog service

Ordering service

Connection pool

Store

Catalog service

Ordering service

Connection pool

Connection pool

Page 41: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

DECOUPLING MIDDLEWARE

41

enable message processing in different place and time

Ordering service

Store service

Unreliable store backend

system

place order

order receipt

Page 42: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

DECOUPLING MIDDLEWARE

42

enable message processing in different place and time

Ordering service

Store service

Unreliable store backend

system

place order

intermediary order receipt

activemq

Page 43: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

IDEMPOTENCY

43

and eventual consistency

Page 44: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

IDEMPOTENCY

44

PUT http://order-service/order

{ “customer”: { “name”: “John Doe”, ... }, “items” = [ {“storeId”: 1000, “itemPrice”: 99.90, “amount”: 2} ]}

Page 45: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

IDEMPOTENCY

45

PUT http://order-service/order

{ “uuid”: “12de-adbe-ef42”, “customer”: { “name”: “John Doe”, ... }, “items” = [ {“storeId”: 1000, “itemPrice”: 99.90, “amount”: 2} ]}

Page 46: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

COMPENSATING TRANSACTIONS

46

Store

Order table Pickup table

Customercode

Monolithic service

Warehousecode Single

transactional boundary

Page 47: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

COMPENSATING TRANSACTIONS

47

Store service

Order table Pickup table

Customer service

Separate services

Warehouse service

Separate transactional boundaries

order

1st 2nd

Page 48: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

COMPENSATING TRANSACTIONS

48

Store service

Order table Pickup table

(idempotent)Customer service

Compensating Transactions

(idempotent)Warehouse service

activemq

order

1st 2nd

Page 49: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

COMPENSATING TRANSACTIONS

49

Store service

Order table Pickup table

(idempotent)Customer service

Compensating Transactions

(idempotent)Warehouse service

activemq

order

1st 2nd

Failure

Page 50: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

COMPENSATING TRANSACTIONS

50

Store service

Order table Pickup table

(idempotent)Customer service

Compensating Transactions

(idempotent)Warehouse service

activemq

order

1st 2nd

Failure

3rd

cancel order

Page 51: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Summary

Page 52: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

MICROSERVICE BENEFITS

52

INDEPENDENT COMPONENT SCALING

CONTINUOUS AND DECOUPLED DEPLOYMENTS

SMALL AND AGILE DEV TEAMS

Page 53: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

MICROSERVICE TRADE-OFFS

53

DISTRIBUTED SYSTEM

EVENTUAL CONSISTENCY

OPERATIONAL COMPLEXITY

Page 54: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

MICROSERVICE TRADE-OFFS

54

DISTRIBUTED SYSTEM

EVENTUAL CONSISTENCY

OPERATIONAL COMPLEXITY

Design for failure Carefully consider consistency requirements

Embrace immutable infrastructure, automate

Page 55: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

Microservice architectures

Further reading

55

Page 56: Microservice architecture...MICROSERVICES, THE TERM 4 “microservice” Venice software architects workshop ‘11 “Micro services” Java, the Unix Way, James Lewis 33rd Degree,

THANK YOU

plus.google.com/+RedHat

linkedin.com/company/red-hat

youtube.com/user/RedHatVideos

facebook.com/redhatinc

twitter.com/RedHatNews