Java Day Minsk 2016 Keynote about Microservices in real world

Post on 10-Feb-2017

444 views 1 download

Transcript of Java Day Minsk 2016 Keynote about Microservices in real world

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

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

@tolkv

2

@lavcraft

3

@aatarasoff

@aatarasoff

DISCLAIMER

No warranty guarantee

4

5

6

“Microservices” - just a buzzword

7

“Microservices” - just a buzzword

8

Why?

● High abstraction level

9

Why?

● High abstraction level● Popular word

10

Why?

● High abstraction level● Popular word● Sell itself

11

Why?

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

12

13

Not Gartner Curve

14

15

Not Gartner Curve

16

Not Gartner Curve

17

18

What is the architecture?

19

What is the architecture?

20

What is the architecture?

21

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

22

Classic development

23

Big Ball of Mud

24

SOLID

Counter-Strike Cats

25

GOF

SOLID

GRASP

Counter-Strike Cats

26

12 April 1996SOA is Born

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

12 April 1996SOA is Born

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

SOA Principles1. Standardized service contract

2. Loose coupling

3. Encapsulation

4. Reusability

5. Autonomy

6. Statelessness

7. Discoverability29

Classic SOA

● centralized orchestration

● complicated (hi, SOAP)

● smart pipes (hi, ESB)

30

5 January 2009SOA is Dead

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

What did you say?

32

SOA != SOAP (WS-*)

33

34

35

...and what about people?2004 year

36

SOA was ahead of its time

37

38

SOA

So

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

39

Microservices

40

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

DevOps

OSS Domination

41

What is “microservices”?

42

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

Does size matter?

● Method/Function = Microservice?

● 10-300 LOC = Microservice?

● 1 week = Microservice?

● 1 developer = Microservice?

44

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

Domain-Driven Design

46

47

DDD

DdSOA

So

Microservices are new classes

48

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

Problem → So Many Teams

50

LSD Principle

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

complexity = L * S * D

51

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

What can’t be sacrificed?

min (L * S * D) → ?

53

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

54

L = Java 18+S = Spring BootD = ∞

55

java

Ja

spring boot

Sb

56

LSD principle

LsDDD

DdSOA

So

Data Isolation Patterns

57

N services → 1 DB

Isolated by Schema/Tables58

N services → N DB

Distributed Transactions are Painfull59

M services → 1 DB L services → L DB

M + L = N, M << L60

Event Sourcing / CQRS / SAGAS

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

61

java

Ja

spring boot

Sb

62

Data Isolation

DiLSD principle

LsDDD

DdSAGAS

SaSOA

So

Problem -> Many Services

63

git clone <cool_service_repo>

64

git clone <template_repo>

65

lazybones/start.spring.io/yeoman

66

lazybones create api 1.0.1 service_name

67

~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

lazybones

Lz

yoman

Yo

start.spring.io

Ssjava

Ja

spring boot

Sbgroovy

Gy

69

Data Isolation

DiLSD principle

LsDDD

DdSAGAS

SaSOA

So

Problem → DRY off

70

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

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

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

73

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

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

74

smart libsstarters

launchers

shared libsutils

helpers

75

smart libs/shared libs

76

documentation → smart documentation

77

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

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

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

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

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

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

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

Delivery Story

85

war/ear

86

executable fatJar

87

88

Not Gartner Curve

docker/rkt/packer

89

./gradlew deployViaSSH

90

./gradlew deployViaSSH

ConsistencyHigh Availability

91

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

Predefined Configuration92

Magic

Private PAAS93

mesos/kubernetes/∞

94

How we run cluster

95

More spice!

96

More spice!

97

More spice!

98

Mesos lets us treat a cluster as one big computer

WEB

WASTED

CACHE

WASTED WASTED

HADOOP

99

Mesos lets us treat a cluster as one big computer

WEB

WASTED

CACHE

WASTED WASTED

HADOOP

WASTED

WEBCACHE

HADOOP FREE FREE

100

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

Problem → Find them All

102

insert into settings_table values (key, endpoint)

103

update template → services.locationkill -s HUP nginx

104

eureka/consul/etcd/zookeper

105

106

Service ClientRegistry-aware

HTTP Client

Service Registry

Service Instance 1

Service Instance N

Service Instance ...

Load balance request

Client side discovery

107

Service Client

Service Registry

Service Instance 1

Service Instance N

Service Instance ...

Load balance requestRouter/Proxy

Server side discovery

Problem → Defend yourself

108

109

110

Circuit Breaker

hystrix/apache camel/akka

111

112

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

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

5мс

113

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

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мс

114

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

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мс

115

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

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мс

116

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

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мс

117

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

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мсOpen

118

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

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

300мсHalf-Open

119

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

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

5мсHalf-Open

120

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

Rent Service

Payment Service

Security Service Blockchain Service

Insurance Service

5мс

121

Problem → Follow the Trace

122

No Trace

123

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

Good Old ServletFilter124

spring-cloud-sleuth/open zipkin

125

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

127

128

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

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

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

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

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

131

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

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

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

132

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

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

@tolkv

@aatarasoff

134

@lavcraft

@aatarasoff

Post Scriptum

135

Event Sourcing / CQRS / SAGA

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

136

137

138

Saga guarantee

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

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

139

140

141

142