wild microservices v2

69
WILD microSERVICES 18+

Upload: aleksandr-tarasov

Post on 10-Feb-2017

288 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: WILD microSERVICES v2

WILD microSERVICES

18+

Page 2: WILD microSERVICES v2

@tolkv

2

Page 3: WILD microSERVICES v2

@aatarasoff

3

Page 4: WILD microSERVICES v2

WILD microSERVICES

18+

Page 5: WILD microSERVICES v2

DISCLAIMER

No warranty guarantee

5

Page 6: WILD microSERVICES v2

Agenda

1. Theory

2. Practice

3. Q&A

6

Page 7: WILD microSERVICES v2

7

Page 8: WILD microSERVICES v2

8

Page 9: WILD microSERVICES v2

9

Page 10: WILD microSERVICES v2

Ball of Mud

10

Page 11: WILD microSERVICES v2

SOA Principles1. standardized service contract

2. loose coupling

3. encapsulation

4. reusability

5. autonomy

6. statelessness

7. discoverability11

Page 12: WILD microSERVICES v2

12

Page 13: WILD microSERVICES v2

13

Page 14: WILD microSERVICES v2

Никто не любит “некрасивые” технологии

поэтому они умирают

Page 15: WILD microSERVICES v2

15

Про тренды

Page 16: WILD microSERVICES v2

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

Что такое микросервисы?

16

Page 17: WILD microSERVICES v2

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

Что такое микросервисы?

17

Page 18: WILD microSERVICES v2

Размер имеет значение?

● Method/Function = Microservice?

● 10-300 LOC = Microservice?

● 1 week = Microservice?

● 1 developer = Microservice?

18

Page 19: WILD microSERVICES v2

Размер не имеет значения*

● 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

*до разумных пределов конечно19

Page 20: WILD microSERVICES v2

Domain-Driven Design

20

Page 21: WILD microSERVICES v2

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

Что такое микросервисы?

21

Page 22: WILD microSERVICES v2

Process segregation

22

Page 23: WILD microSERVICES v2

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

Что такое микросервисы?

23

Page 24: WILD microSERVICES v2

Независимый деплой

build test

24

Page 25: WILD microSERVICES v2

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

Что такое микросервисы?

25

Page 26: WILD microSERVICES v2

Language/technology segregation

26

Page 27: WILD microSERVICES v2

Data segregation

27

Page 28: WILD microSERVICES v2

Team segregation

28

Page 29: WILD microSERVICES v2

Принцип LSD

- L языков программирования- S в среднем фреймворков на язык- D типов источников данных

complexity = L * S * D

29

Page 30: WILD microSERVICES v2

Пример

- три языка программирования- два в среднем фреймворка на язык- семь типов источников данных

- legacy WS, mongo db- хранимые процедуры, JDBC-templates- elasticsearch, neo4j- мишкина база

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

Page 31: WILD microSERVICES v2

Чем нельзя жертвовать?

min (L * S * D) -> ?

31

Page 32: WILD microSERVICES v2

Закон трёх букв

min (L * S * D) -> max (D)

32

Page 33: WILD microSERVICES v2

Почему Spring Boot/Spring Cloud?

33

Page 34: WILD microSERVICES v2

А теперь попробуем

34

Page 35: WILD microSERVICES v2

Demo

Page 36: WILD microSERVICES v2

Demo -> Deploy Time

Page 37: WILD microSERVICES v2

Service Discovery

37

Page 38: WILD microSERVICES v2

Demo -> Time to Discover

Page 39: WILD microSERVICES v2

Где мой порт?

39

Page 40: WILD microSERVICES v2

40

Page 41: WILD microSERVICES v2

Какие есть варианты?

● Nginx/Haproxy + consul template

● Haproxy + bamboo (need marathon)

● Netflix Zuul (Java way!!!)

● Custom Servlet <- все с этого начинают!

41

Page 42: WILD microSERVICES v2

Netflix Zuul

42

Page 43: WILD microSERVICES v2

Demo -> Gateway Time

Page 44: WILD microSERVICES v2

Безопасность

44

Page 45: WILD microSERVICES v2

Защита на уровне сервиса

45

Page 46: WILD microSERVICES v2

Защита на уровне сервиса #2

46

Page 47: WILD microSERVICES v2

Опять этот gateway

47

Page 48: WILD microSERVICES v2

REST/HTTP

Authorization: Bearer <TOKEN>ClientID: <ID>

48

Page 49: WILD microSERVICES v2

Thrift API Gateway

service InternalTestService {

SomeReturnData getSomeData(

1: UserData userData,

2: RequestData requestData

) throws (1: SomeException e);

}

49

Page 50: WILD microSERVICES v2

Thrift API Gateway

service InternalTestService {

SomeReturnData getSomeData(

1: UserData userData,

2: RequestData requestData

) throws (1: SomeException e);

}

service ExternalTestService {

SomeReturnData getSomeData(

1: AuthToken authData,

2: RequestData requestData

) throws (1: SomeException e,

99: UnauthorizedException ue);

}

50

Page 51: WILD microSERVICES v2

51

Page 52: WILD microSERVICES v2

Springway@SpringBootApplication@EnableThriftGatewaypublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}

52

Page 53: WILD microSERVICES v2

Demo -> Thrift the Ripper

Page 54: WILD microSERVICES v2
Page 55: WILD microSERVICES v2
Page 56: WILD microSERVICES v2

Demo -> Hystrix the Saviour

Page 57: WILD microSERVICES v2

Типичная микросервисная архитектура

57

Page 58: WILD microSERVICES v2

58

Page 59: WILD microSERVICES v2

А что в этих ваших интернетах?

Page 60: WILD microSERVICES v2

60

DDDD (4D)

Page 61: WILD microSERVICES v2

Выводы

61

● Микросервисы - это просто

Page 62: WILD microSERVICES v2

Выводы

62

● Микросервисы - это просто

● Микросервисы - это сложно

Page 63: WILD microSERVICES v2

Парадокс (де)централизации микросервисов

Чтобы эффективно работать с распределенными приложениями, нужно иметь очень хорошие

централизованные библиотеки/инструменты

Например: логирование, health-чеки, метрики, обработку программных ошибок

63

Page 64: WILD microSERVICES v2

Парадокс (де)централизации микросервисов

Чтобы эффективно работать с распределенными приложениями, нужно иметь очень хорошие

централизованные библиотеки/инструменты

Но: не выносите бизнес-логику или доменные объекты

64

Page 65: WILD microSERVICES v2

LSD вам в помощь

min (L * S * D) -> max (D)

65

Page 66: WILD microSERVICES v2

СсылкиОригинальное исполнение

https://github.com/bsideup/thrift-spring-boot-starter

Крутой плагин для Gradle

https://github.com/bsideup/GradleThrift

Forward2Dockerhttps://github.com/bsideup/forward2docker/releases

66

@bsideup

Page 67: WILD microSERVICES v2

Code. Better. Together.Spring Thrift Clienthttps://github.com/aatarasoff/spring-thrift-starter

Thrift API Gatewayhttps://github.com/aatarasoff/thrift-api-gateway-corehttps://github.com/aatarasoff/spring-thrift-api-gateway

Примеры сегодняшнего дняhttps://github.com/lavcraft/jug-samples

67

Page 68: WILD microSERVICES v2

Высокие теории

Sam Newman “Building Microservices”

Martin Fowler “Microservice TradeOff” “Microservices”

“The Twelwe-Factor App” http://12factor.net

Hystrix: managing failures in distributed systems - Tomasz Nurkiewicz https:

//www.youtube.com/watch?v=JadVts_prtA

68

Page 69: WILD microSERVICES v2

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

@tolkv

@aatarasoff

69