java day minsk 2016 keynote about microservices in real world

142
Микросервисы огонь, вода, медные трубы 1

Upload: -

Post on 10-Feb-2017

442 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Java Day Minsk 2016 Keynote about Microservices in real world

Микросервисы

огонь, вода, медные трубы1

Page 2: Java Day Minsk 2016 Keynote about Microservices in real world

@tolkv

2

@lavcraft

Page 3: Java Day Minsk 2016 Keynote about Microservices in real world

3

@aatarasoff

@aatarasoff

Page 4: Java Day Minsk 2016 Keynote about Microservices in real world

DISCLAIMER

No warranty guarantee

4

Page 5: Java Day Minsk 2016 Keynote about Microservices in real world

5

Page 6: Java Day Minsk 2016 Keynote about Microservices in real world

6

Page 7: Java Day Minsk 2016 Keynote about Microservices in real world

“Microservices” - just a buzzword

7

Page 8: Java Day Minsk 2016 Keynote about Microservices in real world

“Microservices” - just a buzzword

8

Page 9: Java Day Minsk 2016 Keynote about Microservices in real world

Why?

● High abstraction level

9

Page 10: Java Day Minsk 2016 Keynote about Microservices in real world

Why?

● High abstraction level● Popular word

10

Page 11: Java Day Minsk 2016 Keynote about Microservices in real world

Why?

● High abstraction level● Popular word● Sell itself

11

Page 12: Java Day Minsk 2016 Keynote about Microservices in real world

Why?

● High abstraction level● Popular word● Sell itself● More talks

12

Page 13: Java Day Minsk 2016 Keynote about Microservices in real world

13

Not Gartner Curve

Page 14: Java Day Minsk 2016 Keynote about Microservices in real world

14

Page 15: Java Day Minsk 2016 Keynote about Microservices in real world

15

Not Gartner Curve

Page 16: Java Day Minsk 2016 Keynote about Microservices in real world

16

Not Gartner Curve

Page 17: Java Day Minsk 2016 Keynote about Microservices in real world

17

Page 18: Java Day Minsk 2016 Keynote about Microservices in real world

18

Page 19: Java Day Minsk 2016 Keynote about Microservices in real world

What is the architecture?

19

Page 20: Java Day Minsk 2016 Keynote about Microservices in real world

What is the architecture?

20

Page 21: Java Day Minsk 2016 Keynote about Microservices in real world

What is the architecture?

21

https://www.youtube.com/watch?v=_Kex5hwGE-w

Page 22: Java Day Minsk 2016 Keynote about Microservices in real world

22

Classic development

Page 23: Java Day Minsk 2016 Keynote about Microservices in real world

23

Page 24: Java Day Minsk 2016 Keynote about Microservices in real world

Big Ball of Mud

24

Page 25: Java Day Minsk 2016 Keynote about Microservices in real world

SOLID

Counter-Strike Cats

25

Page 26: Java Day Minsk 2016 Keynote about Microservices in real world

GOF

SOLID

GRASP

Counter-Strike Cats

26

Page 27: Java Day Minsk 2016 Keynote about Microservices in real world

12 April 1996SOA is Born

https://www.gartner.com/doc/302868/service-oriented-architectures- 27

Page 28: Java Day Minsk 2016 Keynote about Microservices in real world

12 April 1996SOA is Born

https://www.gartner.com/doc/302868/service-oriented-architectures- 28

Page 29: Java Day Minsk 2016 Keynote about Microservices in real world

SOA Principles1. Standardized service contract

2. Loose coupling

3. Encapsulation

4. Reusability

5. Autonomy

6. Statelessness

7. Discoverability29

Page 30: Java Day Minsk 2016 Keynote about Microservices in real world

Classic SOA

● centralized orchestration

● complicated (hi, SOAP)

● smart pipes (hi, ESB)

30

Page 31: Java Day Minsk 2016 Keynote about Microservices in real world

5 January 2009SOA is Dead

http://apsblog.burtongroup.com/2009/01/soa-is-dead-long-live-services.html 31

Page 32: Java Day Minsk 2016 Keynote about Microservices in real world

What did you say?

32

Page 33: Java Day Minsk 2016 Keynote about Microservices in real world

SOA != SOAP (WS-*)

33

Page 34: Java Day Minsk 2016 Keynote about Microservices in real world

34

Page 35: Java Day Minsk 2016 Keynote about Microservices in real world

35

Page 36: Java Day Minsk 2016 Keynote about Microservices in real world

...and what about people?2004 year

36

Page 37: Java Day Minsk 2016 Keynote about Microservices in real world

SOA was ahead of its time

37

Page 38: Java Day Minsk 2016 Keynote about Microservices in real world

38

SOA

So

Page 39: Java Day Minsk 2016 Keynote about Microservices in real world

A=F(Rq, FRq, NFRq,..........???............)

39

Page 40: Java Day Minsk 2016 Keynote about Microservices in real world

Microservices

40

Page 41: Java Day Minsk 2016 Keynote about Microservices in real world

A=F(Rq, FRq, NFRq,..........???............)

DevOps

OSS Domination

41

Page 42: Java Day Minsk 2016 Keynote about Microservices in real world

What is “microservices”?

42

Page 43: Java Day Minsk 2016 Keynote about Microservices in real world

In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies. James Lewis and Martin Fowler

43

Page 44: Java Day Minsk 2016 Keynote about Microservices in real world

Does size matter?

● Method/Function = Microservice?

● 10-300 LOC = Microservice?

● 1 week = Microservice?

● 1 developer = Microservice?

44

Page 45: Java Day Minsk 2016 Keynote about Microservices in real world

Size doesn’t matter*

● Single Responsibility

● One capability

● Bounded context

“In your organization, you should be thinking not in terms of data that is shared, but about the capabilities those contexts provide the rest of the domain.”– Sam Newman, Building Microservices

*within reason45

Page 46: Java Day Minsk 2016 Keynote about Microservices in real world

Domain-Driven Design

46

Page 47: Java Day Minsk 2016 Keynote about Microservices in real world

47

DDD

DdSOA

So

Page 48: Java Day Minsk 2016 Keynote about Microservices in real world

Microservices are new classes

48

Page 49: Java Day Minsk 2016 Keynote about Microservices in real world

In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies. James Lewis and Martin Fowler

49

Page 50: Java Day Minsk 2016 Keynote about Microservices in real world

Problem → So Many Teams

50

Page 51: Java Day Minsk 2016 Keynote about Microservices in real world

LSD Principle

- L programming languages- S average framework count by language- D data source types

complexity = L * S * D

51

Page 52: Java Day Minsk 2016 Keynote about Microservices in real world

Some LSD for you

- three programming languages- two average framework count by language- seven data source types

- legacy WS, mongo db- OLTP, OLAP- elasticsearch, neo4j- Mishka’s database %)

complexity = 3 * 2 * 7 = 42 (!)52

Page 53: Java Day Minsk 2016 Keynote about Microservices in real world

What can’t be sacrificed?

min (L * S * D) → ?

53

Page 54: Java Day Minsk 2016 Keynote about Microservices in real world

min (L * S * D) → max (D)

54

Page 55: Java Day Minsk 2016 Keynote about Microservices in real world

L = Java 18+S = Spring BootD = ∞

55

Page 56: Java Day Minsk 2016 Keynote about Microservices in real world

java

Ja

spring boot

Sb

56

LSD principle

LsDDD

DdSOA

So

Page 57: Java Day Minsk 2016 Keynote about Microservices in real world

Data Isolation Patterns

57

Page 58: Java Day Minsk 2016 Keynote about Microservices in real world

N services → 1 DB

Isolated by Schema/Tables58

Page 59: Java Day Minsk 2016 Keynote about Microservices in real world

N services → N DB

Distributed Transactions are Painfull59

Page 60: Java Day Minsk 2016 Keynote about Microservices in real world

M services → 1 DB L services → L DB

M + L = N, M << L60

Page 61: Java Day Minsk 2016 Keynote about Microservices in real world

Event Sourcing / CQRS / SAGAS

http://gotocon.com/dl/goto-chicago-2015/slides/CaitieMcCaffrey_ApplyingTheSagaPattern.pdf

61

Page 62: Java Day Minsk 2016 Keynote about Microservices in real world

java

Ja

spring boot

Sb

62

Data Isolation

DiLSD principle

LsDDD

DdSAGAS

SaSOA

So

Page 63: Java Day Minsk 2016 Keynote about Microservices in real world

Problem -> Many Services

63

Page 64: Java Day Minsk 2016 Keynote about Microservices in real world

git clone <cool_service_repo>

64

Page 65: Java Day Minsk 2016 Keynote about Microservices in real world

git clone <template_repo>

65

Page 66: Java Day Minsk 2016 Keynote about Microservices in real world

lazybones/start.spring.io/yeoman

66

Page 67: Java Day Minsk 2016 Keynote about Microservices in real world

lazybones create api 1.0.1 service_name

67

Page 68: Java Day Minsk 2016 Keynote about Microservices in real world

~home > lazybones create api 0.0.1 rent-serviceCreating project from template api 0.0.1 in 'rent-service'Define value for 'group' [by.javaday]:Define value for 'version' [0.0.1]:

srv1 ├──srv2 └──srv3

loggingsleuth

Define value for 'dependencies' [logging,sleuth]:

Project created for rent-service!

68

Page 69: Java Day Minsk 2016 Keynote about Microservices in real world

lazybones

Lz

yoman

Yo

start.spring.io

Ssjava

Ja

spring boot

Sbgroovy

Gy

69

Data Isolation

DiLSD principle

LsDDD

DdSAGAS

SaSOA

So

Page 70: Java Day Minsk 2016 Keynote about Microservices in real world

Problem → DRY off

70

Page 71: Java Day Minsk 2016 Keynote about Microservices in real world

TServerTransport serverTransport = new TServerSocket( new InetSocketAddress(InetAddress.getLocalHost(), port));

TProcessor processor = new TInsuranceService.Processor<>(

//business value here);

server = new TSimpleServer(new TServer.Args(serverTransport).processor

(processor));

server.serve();

71

Page 72: Java Day Minsk 2016 Keynote about Microservices in real world

TSocket transport = new TSocket(host, port);transport.open();

TBinaryProtocol tBinaryProtocol = new TBinaryProtocol(transport);TInsuranceService.Client client =

new TInsuranceService.Client(tBinaryProtocol);

perform(client); //business value here

transport.close(); 72

Page 73: Java Day Minsk 2016 Keynote about Microservices in real world

@ThriftControllerpublic class InsuranceController implements TInsuranceService.Iface { @Override public void someMethod(TInsurance insurance){ //business value here }}

73

Page 74: Java Day Minsk 2016 Keynote about Microservices in real world

@ThriftClient(serviceId = "insurance-service")TInsuranceService.Client client;

...perform(client); //business value here...

74

Page 75: Java Day Minsk 2016 Keynote about Microservices in real world

smart libsstarters

launchers

shared libsutils

helpers

75

Page 76: Java Day Minsk 2016 Keynote about Microservices in real world

smart libs/shared libs

76

Page 77: Java Day Minsk 2016 Keynote about Microservices in real world

documentation → smart documentation

77

Page 78: Java Day Minsk 2016 Keynote about Microservices in real world

Not smart= This is main documentation

This document describes how to be the most fundamental and important document in the world of documents

...COPY-PASTE documentation from another document...

78

Page 79: Java Day Minsk 2016 Keynote about Microservices in real world

Not so smart= This is main documentation

This document describes how to be the most fundamental and important document in the world of documents

include::https://raw.github.com/asciidoctor/asciidoctor/master/Gemfile[]

include::../other.adoc[]include::/home/tolkv/git/docs-0/superdoc.adoc[]

79

Page 80: Java Day Minsk 2016 Keynote about Microservices in real world

Really smart= This is main documentation

This document describes how to be the most fundamental and important document in the world of documents

include::https://raw.github.com/asciidoctor/asciidoctor/master/Gemfile[]

include::gradle://gradle-advanced:service-with-deps:1.0/deps.adoc[]include::gradle://:service/doc.adoc[]

80

Page 81: Java Day Minsk 2016 Keynote about Microservices in real world

Payment Service[jar,doc] Insurance Service [jar,doc]

One Point of View [UberDoc.zip]

Rent Service[jar,doc] Other Service [jar,doc]

Information Aggregation

81

Page 82: Java Day Minsk 2016 Keynote about Microservices in real world

Centralization Paradox

To work effectively with distributed applications, you need to have a very good centralized libraries and tools.

For example: logging, health-checking, metrics, exception handling, documentation autogeneration

82

Page 83: Java Day Minsk 2016 Keynote about Microservices in real world

Centralization Paradox

To work effectively with distributed applications, you need to have a very good centralized libraries and tools.

But: don’t do this with you business logic or domain model

83

Page 84: Java Day Minsk 2016 Keynote about Microservices in real world

lazybones

Lz

yoman

Yo

start.spring.io

Ssjava

Ja

thrift

Th

spring boot

Sb

gradle

Grasciidoctor

Ad

groovy

Gy

84

Data Isolation

DiCentralization paradox

CpLSD principle

LsDDD

DdSAGAS

SaSmart Docs

SdSmart Libs

SlSOA

So

Page 85: Java Day Minsk 2016 Keynote about Microservices in real world

Delivery Story

85

Page 86: Java Day Minsk 2016 Keynote about Microservices in real world

war/ear

86

Page 87: Java Day Minsk 2016 Keynote about Microservices in real world

executable fatJar

87

Page 88: Java Day Minsk 2016 Keynote about Microservices in real world

88

Not Gartner Curve

Page 89: Java Day Minsk 2016 Keynote about Microservices in real world

docker/rkt/packer

89

Page 90: Java Day Minsk 2016 Keynote about Microservices in real world

./gradlew deployViaSSH

90

Page 91: Java Day Minsk 2016 Keynote about Microservices in real world

./gradlew deployViaSSH

ConsistencyHigh Availability

91

Page 92: Java Day Minsk 2016 Keynote about Microservices in real world

./gradlew deployToArtifactoryansible -i [stage,dev,test] -t deploy

Predefined Configuration92

Page 93: Java Day Minsk 2016 Keynote about Microservices in real world

Magic

Private PAAS93

Page 94: Java Day Minsk 2016 Keynote about Microservices in real world

mesos/kubernetes/∞

94

Page 95: Java Day Minsk 2016 Keynote about Microservices in real world

How we run cluster

95

Page 96: Java Day Minsk 2016 Keynote about Microservices in real world

More spice!

96

Page 97: Java Day Minsk 2016 Keynote about Microservices in real world

More spice!

97

Page 98: Java Day Minsk 2016 Keynote about Microservices in real world

More spice!

98

Page 99: Java Day Minsk 2016 Keynote about Microservices in real world

Mesos lets us treat a cluster as one big computer

WEB

WASTED

CACHE

WASTED WASTED

HADOOP

99

Page 100: Java Day Minsk 2016 Keynote about Microservices in real world

Mesos lets us treat a cluster as one big computer

WEB

WASTED

CACHE

WASTED WASTED

HADOOP

WASTED

WEBCACHE

HADOOP FREE FREE

100

Page 101: Java Day Minsk 2016 Keynote about Microservices in real world

lazybones

Lz

yoman

Yo

start.spring.io

Ss

python

Py

java

Ja

spring boot

Sb

gradle

Grasciidoctor

Addocker

Dr

mesos

Ms

marathon

Machronos

Chaurora

Au

Kubernetes

Kbgroovy

Gy

101

Data Isolation

DiCentralization paradox

CpLSD principle

LsDDD

DdSAGAS

SaSmart Docs

SdDynamic Sharing

DsSmart Libs

SlSOA

So

ansible

Anthrift

ThArtifactory

Ar

Page 102: Java Day Minsk 2016 Keynote about Microservices in real world

Problem → Find them All

102

Page 103: Java Day Minsk 2016 Keynote about Microservices in real world

insert into settings_table values (key, endpoint)

103

Page 104: Java Day Minsk 2016 Keynote about Microservices in real world

update template → services.locationkill -s HUP nginx

104

Page 105: Java Day Minsk 2016 Keynote about Microservices in real world

eureka/consul/etcd/zookeper

105

Page 106: Java Day Minsk 2016 Keynote about Microservices in real world

106

Service ClientRegistry-aware

HTTP Client

Service Registry

Service Instance 1

Service Instance N

Service Instance ...

Load balance request

Client side discovery

Page 107: Java Day Minsk 2016 Keynote about Microservices in real world

107

Service Client

Service Registry

Service Instance 1

Service Instance N

Service Instance ...

Load balance requestRouter/Proxy

Server side discovery

Page 108: Java Day Minsk 2016 Keynote about Microservices in real world

Problem → Defend yourself

108

Page 109: Java Day Minsk 2016 Keynote about Microservices in real world

109

Page 110: Java Day Minsk 2016 Keynote about Microservices in real world

110

Circuit Breaker

Page 111: Java Day Minsk 2016 Keynote about Microservices in real world

hystrix/apache camel/akka

111

Page 112: Java Day Minsk 2016 Keynote about Microservices in real world

112

Хочу бегемота!

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

5мс

Page 113: Java Day Minsk 2016 Keynote about Microservices in real world

113

Хочу бегемота!

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мс

Page 114: Java Day Minsk 2016 Keynote about Microservices in real world

114

Хочу бегемота!

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мс

Page 115: Java Day Minsk 2016 Keynote about Microservices in real world

115

Хочу бегемота!

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мс

Page 116: Java Day Minsk 2016 Keynote about Microservices in real world

116

Хочу бегемота!

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мс

Page 117: Java Day Minsk 2016 Keynote about Microservices in real world

117

Хочу бегемота!

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мсOpen

Page 118: Java Day Minsk 2016 Keynote about Microservices in real world

118

Хочу бегемота!

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мсHalf-Open

Page 119: Java Day Minsk 2016 Keynote about Microservices in real world

119

Хочу бегемота!

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

5мсHalf-Open

Page 120: Java Day Minsk 2016 Keynote about Microservices in real world

120

Хочу бегемота!

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

5мс

Page 121: Java Day Minsk 2016 Keynote about Microservices in real world

121

Page 122: Java Day Minsk 2016 Keynote about Microservices in real world

Problem → Follow the Trace

122

Page 123: Java Day Minsk 2016 Keynote about Microservices in real world

No Trace

123

Page 124: Java Day Minsk 2016 Keynote about Microservices in real world

X-Request-Id = X-Request-Id ?: new ID

Good Old ServletFilter124

Page 125: Java Day Minsk 2016 Keynote about Microservices in real world

spring-cloud-sleuth/open zipkin

125

Page 126: Java Day Minsk 2016 Keynote about Microservices in real world

126

Rent

Ser

vice

Paym

ent

Serv

ice

Secu

rity

Ser

vice

Bloc

kcha

in S

ervi

ce

TraceId = XSpanId = A

No TraceIdNo SpanId

TraceId = XSpanId = A

TraceId = XSpanId = A

TraceId = XSpanId = B

TraceId = XSpanId = B

TraceId = XSpanId = C

TraceId = XSpanId = C

TraceId = XSpanId = D

TraceId = XSpanId = D

TraceId = XSpanId = E

TraceId = XSpanId = E

TraceId = XSpanId = F

TraceId = XSpanId = G

Page 127: Java Day Minsk 2016 Keynote about Microservices in real world

127

Page 128: Java Day Minsk 2016 Keynote about Microservices in real world

128

Page 129: Java Day Minsk 2016 Keynote about Microservices in real world

129

Rent

Ser

vice

Paym

ent

Serv

ice

SpanId = BClient Send

SpanId = BServer Received

SpanId = BClient Received

SpanId = BServer Send

TraceId = XSpanId = A

TraceId = XSpanId = C

Page 130: Java Day Minsk 2016 Keynote about Microservices in real world

yoman

Yo

start.spring.io

Ss

python

Py

lazybones

Lzjava

Ja

spring boot

Sb

gradle

Grasciidoctor

Adthrift

Thdocker

Dr

mesos

Ms

marathon

Machronos

Chaurora

AuArtifactory

Ar

Kubernetes

Kb

eureka

Eu

consul

Cl

etcd

Ed

zookeeper

Zkhystrix

Hx

sleuth

Sl

zipkin

Zn

groovy

Gy

130

Data Isolation

DiCentralization paradox

CpLSD principle

LsDDD

DdSAGAS

SaSmart Docs

SdDynamic Sharing

DsSmart Libs

SlSOA

So

ansible

An

Page 131: Java Day Minsk 2016 Keynote about Microservices in real world

1. Архитектура функция от множества переменных

2. Всё новое - хорошо забытое старое3. Микросервисы как iPhone4. Микросервисы - новые классы5. Каждой задаче - свой инструмент

Запомните это

131

Page 132: Java Day Minsk 2016 Keynote about Microservices in real world

1. SOA принципы живы2. Принцип LSD3. Изоляция данных делает жизнь приятнее4. В сложных ситуациях Event

Sourcing/CQRS/SAGAS5. Парадокс централизации6. Планируй ресурсы динамически

Придерживайтесь принципов

132

Page 133: Java Day Minsk 2016 Keynote about Microservices in real world

LinksSpring Thrift Starter: https://github.com/aatarasoff/spring-thrift-starter

Тоже, но для grpc: https://github.com/lavcraft/grpc-spring-boot-starter

Какие-то примеры:https://github.com/lavcraft/wild-microservices-in-kiev

Gradle doc plugin blueprint: https://github.com/aatarasoff/documentation-plugin-demo

133

Page 134: Java Day Minsk 2016 Keynote about Microservices in real world

Спасибо! Готовы ответить на ваши вопросы

@tolkv

@aatarasoff

134

@lavcraft

@aatarasoff

Page 135: Java Day Minsk 2016 Keynote about Microservices in real world

Post Scriptum

135

Page 136: Java Day Minsk 2016 Keynote about Microservices in real world

Event Sourcing / CQRS / SAGA

http://gotocon.com/dl/goto-chicago-2015/slides/CaitieMcCaffrey_ApplyingTheSagaPattern.pdf

136

Page 137: Java Day Minsk 2016 Keynote about Microservices in real world

137

Page 138: Java Day Minsk 2016 Keynote about Microservices in real world

138

Page 139: Java Day Minsk 2016 Keynote about Microservices in real world

Saga guarantee

● T1 -> T2 -> T3 -> … -> Tn

● T1 -> T2 -> … Tn -> Cn … -> C2 -> C1

139

Page 140: Java Day Minsk 2016 Keynote about Microservices in real world

140

Page 141: Java Day Minsk 2016 Keynote about Microservices in real world

141

Page 142: Java Day Minsk 2016 Keynote about Microservices in real world

142