Upload
aleksandr-tarasov
View
291
Download
0
Embed Size (px)
Citation preview
WILD microSERVICES
18+
@tolkv
2
@aatarasoff
3
WILD microSERVICES
18+
DISCLAIMER
No warranty guarantee
5
Agenda
1. Theory
2. Practice
3. Q&A
6
7
8
9
Ball of Mud
10
SOA Principles1. standardized service contract
2. loose coupling
3. encapsulation
4. reusability
5. autonomy
6. statelessness
7. discoverability11
12
13
Никто не любит “некрасивые” технологии
поэтому они умирают
15
Про тренды
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
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
Размер имеет значение?
● Method/Function = Microservice?
● 10-300 LOC = Microservice?
● 1 week = Microservice?
● 1 developer = Microservice?
18
Размер не имеет значения*
● 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
Domain-Driven Design
20
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
Process segregation
22
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
Независимый деплой
build test
24
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
Language/technology segregation
26
Data segregation
27
Team segregation
28
Принцип LSD
- L языков программирования- S в среднем фреймворков на язык- D типов источников данных
complexity = L * S * D
29
Пример
- три языка программирования- два в среднем фреймворка на язык- семь типов источников данных
- legacy WS, mongo db- хранимые процедуры, JDBC-templates- elasticsearch, neo4j- мишкина база
complexity = 3 * 2 * 7 = 42 (!)30
Чем нельзя жертвовать?
min (L * S * D) -> ?
31
Закон трёх букв
min (L * S * D) -> max (D)
32
Почему Spring Boot/Spring Cloud?
33
А теперь попробуем
34
Demo
Demo -> Deploy Time
Service Discovery
37
Demo -> Time to Discover
Где мой порт?
39
40
Какие есть варианты?
● Nginx/Haproxy + consul template
● Haproxy + bamboo (need marathon)
● Netflix Zuul (Java way!!!)
● Custom Servlet <- все с этого начинают!
41
Netflix Zuul
42
Demo -> Gateway Time
Безопасность
44
Защита на уровне сервиса
45
Защита на уровне сервиса #2
46
Опять этот gateway
47
REST/HTTP
Authorization: Bearer <TOKEN>ClientID: <ID>
48
Thrift API Gateway
service InternalTestService {
SomeReturnData getSomeData(
1: UserData userData,
2: RequestData requestData
) throws (1: SomeException e);
}
49
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
51
Springway@SpringBootApplication@EnableThriftGatewaypublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
52
Demo -> Thrift the Ripper
Demo -> Hystrix the Saviour
Типичная микросервисная архитектура
57
58
А что в этих ваших интернетах?
60
DDDD (4D)
Выводы
61
● Микросервисы - это просто
Выводы
62
● Микросервисы - это просто
● Микросервисы - это сложно
Парадокс (де)централизации микросервисов
Чтобы эффективно работать с распределенными приложениями, нужно иметь очень хорошие
централизованные библиотеки/инструменты
Например: логирование, health-чеки, метрики, обработку программных ошибок
63
Парадокс (де)централизации микросервисов
Чтобы эффективно работать с распределенными приложениями, нужно иметь очень хорошие
централизованные библиотеки/инструменты
Но: не выносите бизнес-логику или доменные объекты
64
LSD вам в помощь
min (L * S * D) -> max (D)
65
СсылкиОригинальное исполнение
https://github.com/bsideup/thrift-spring-boot-starter
Крутой плагин для Gradle
https://github.com/bsideup/GradleThrift
Forward2Dockerhttps://github.com/bsideup/forward2docker/releases
66
@bsideup
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
Высокие теории
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
Спасибо! Готовы ответить на ваши вопросы
@tolkv
@aatarasoff
69