Dieser Vortrag führt relevante Entwurfsmuster ein, um skalierbare, umgebungsunabhängige, fehlertolerante und versionierte Microservices bereitzustellen. Darauf basierend wird die Umsetzung durch Komponenten des Netflix Open Source Stacks vorgestellt: Konfiguration mit Archaius, elastische Dienste mit Eureka, Gateway Service mit Zuul, Resilience mit Hystrix und Service-Komposition mit RxJava.
7. Senacor Technologies AG
DIGITALIZATION
The “Digital Ready Architecture” is based on a set of key
assumptions/guidelines
19.08.2017
2. Elasticity and Scalability
Cloud native applications
Digital
Ready
Architecture
1. Embrace Change
Fast delivery of ideas into production
3. Embrace Failure
Cope with failures; high availability
4. Responsiveness and Reactivity
Excellent user experience from end-to-end
Elasticity
Resilience
Responsive
Changeability
FrOSCon 2017
9. Senacor Technologies AG
MICROSERVICE ARCHITECTURE
Vertical decomposition of monolithic applications in independent services
decouples releases of independent functionality
19.08.2017 FrOSCon 2017
Loan
Service
Account
Service
Partner
Service
Loan
Frontend
Account
Frontend
Partner
Frontend
Self-
Contained
System
Self-
Contained
System
Self-
Contained
System
Loan
DB
Account
DB
Partner
DB
Micro
Services
Frontend
Integration
FrontendServicesDatabase
Loan
UI
Account
UI
Partner
UI
Loan
Service
Account
Service
Trading
Service
Loan
Schema
Account
Schema
Partner
Schema
Release
monthly
Release
quarterly
Release
2-weekly
Release
half a year
Monolithic
Applications
11. Senacor Technologies AG
This is not how it works!
(Well, maybe it is, if it was a good one)
But most likely not
MICROSERVICE ARCHITECTURE
19.08.2017 FrOSCon 2017
A Microservice is not …
… your monolith cut into pieces
16. Senacor Technologies AG
MICROSERVICE ARCHITECTURE
Microservices with Spring Cloud and Netflix OSS
19.08.2017 FrOSCon 2017
SpringBoot
Creation of stand-alone,
Spring-based Applications
SpringCloud
Routing and Load-Balancing
Service registration and discovery
Messaging
Circuit Breakers
Service-to-service calls
NetflixOSS
Eureka
Spring Framework Integration
Parent/Dependency-POMs
Maven-Plugins
Ribbon
Zuul
RxJava
Hystrix
Feign
Based on integrates
Tool integration and pattern adaption
for distributed systems
Distributed/versioned configuration
Archaius
17. Senacor Technologies AG
MICROSERVICE ARCHITECTURE
Get started with a small application class and spring boot starter POMs
19.08.2017 FrOSCon 2017
package hello;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
+ Java Classes
+ Maven POMs
+ Configuration
Fat
JAR
18. Senacor Technologies AG
MICROSERVICE ARCHITECTURE
How to implement to implement changeability, elasticity, resilience and
responsiveness in a Microservice architecture?
19.08.2017 FrOSCon 2017
2. Elasticity and Scalability
Cloud native applications
Microservice
Architecture
1. Embrace Change
Fast delivery of ideas into production
3. Embrace Failure
Cope with failures; high availability
4. Responsiveness and Reactivity
Excellent user experience from end-to-end
Elasticity
Resilience
Responsive
Changeability
19. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - CHANGEABILITY
How to implement to implement changeability
in a Microservice architecture?
19.08.2017 FrOSCon 2017
2. Elasticity and Scalability
Cloud native applications
1. Embrace Change
Fast delivery of ideas into production
3. Embrace Failure
Cope with failures; high availability
4. Responsiveness and Reactivity
Excellent user experience from end-to-end
Elasticity
Resilience
Responsive
Changeability
Microservice
Architecture
20. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - CHANGEABILITY
19.08.2017 FrOSCon 2017
Web FrontendClients
Services Layer
Account
Service
Account
Service
…
Account
Service
IP2:Port2IP1:Port1
http://<domain>/services/bank-accounts/
IP3:Port3
Routing and load balancing
21. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - CHANGEABILITY
19.08.2017 FrOSCon 2017
Web FrontendClients
Services Layer
Account
Service
Account
Service
…
Account
Service
ZUUL
Reverse Proxy and Load Balancer
Proxy
IP2:Port2IP1:Port1
http://<domain>/services/bank-accounts/
Reverse proxy to route service requests to instances
Versioned APIs enable a decoupling of services and clients
v2.0/
v1.0
v1.0
v2.0
IP3:Port3
22. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - CHANGEABILITY
ZUUL gateway can be biuld as Spring cloud application
19.08.2017 FrOSCon 2017
package example.zuul;
import …;
@SpringBootApplication
@EnableZuulProxy
public class ZuulApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
+ Java Classes
+ Maven POMs
+ Configuration
Fat
JAR
ZUUL
App
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
zuul:
routes:
bankaccounts:
path: /bank-accounts/v2.0/**
url: http://IP3:Port3
Zuul
Deployment
23. Senacor Technologies AG
Zuul: static
route configuration
MICROSERVICE ARCHITECTURE - CHANGEABILITY
19.08.2017 FrOSCon 2017
Web FrontendClients
Services Layer
Account
Service
Account
Service
…
Account
Service
ZUUL
Reverse Proxy and Load Balancer
Proxy
IP2:Port2IP1:Port1
http://<domain>/services/bank-accounts/ v2.0/
v1.0
v1.0
v2.0
IP3:Port3
zuul:
routes:
bankaccounts:
path: /bank-accounts/v2.0/**
url: http://IP3:Port3
25. Senacor Technologies AG
Build once, run everywhere
Good
java -jar service.jar -spring.profiles.active="production“
Bad
mvn clean install spring-boot:repacke -P "production"
MICROSERVICE ARCHITECTURE - CHANGEABILITY
19.08.2017 FrOSCon 2017
A microservice JAR file is built exactly
once and then never touched again
26. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - CHANGEABILITY
A configuration server enables environment independent
delivery artefacts
19.08.2017 FrOSCon 2017
Config
Server
Service Service
Frontend
Frontend
Integration
Service
Layer
Configuration Server
offers a service interface to query profile-specific
configuration values
Configuration Client (Services)
retrieve configuration after start-up
PUSH
Dynamic configuration update
Annotate dynamic properties with
@RefreshScope
after triggering a refresh endpoint
(/refresh)
on change using a message bus
27. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - CHANGEABILITY
A configuration server enables environment independent
delivery artefacts
19.08.2017 FrOSCon 2017
Config
Server
Service Service
Frontend
Frontend
Integration
Service
Layer
PUSH
Config-Server
Activation by Annotation: @EnableConfigServer
GIT-configuration:
spring.cloud.configrepo.server.git.uri = <uri>
Config-Client
Activation by configuration:
cloud:
config:
enabled: true
uri: <url>
28. Senacor Technologies AG
Archaius:
Framework to access properties
Based on Apache commons
Aggregates different sources:
Properties-Files, URLs, database
Type safe access
On change callbacks
MICROSERVICE ARCHITECTURE - CHANGEABILITY
19.08.2017 FrOSCon 2017
29. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - ELASTICITY
How to implement to implement elasticity and scalability
in a Microservice architecture?
19.08.2017 FrOSCon 2017
2. Elasticity and Scalability
Cloud native applications
Microservice
Architecture
1. Embrace Change
Fast delivery of ideas into production
3. Embrace Failure
Cope with failures; high availability
4. Responsiveness and Reactivity
Excellent user experience from end-to-end
Elasticity
Resilience
Responsive
Changeability
30. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - ELASTICITY
19.08.2017 FrOSCon 2017
Web FrontendClients
Services Layer
…
ZUUL
Reverse Proxy and Load Balancer
Proxy
http://<domain>/services/bank-accounts/v2.0/
Account
Service
Account
Service
Account
Service
Scale
Out!
Account
ServiceHow to enable a transparent scale-out
31. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - ELASTICITY
19.08.2017 FrOSCon 2017
Web FrontendClients
Services Layer
…
Proxy
Account
Service
Account
Service
Account
Service
Scale
Out!
Account
Service
ServiceRegistry
Service registration on start up
Heart beat guarantees services availability
Master/Slave operation mode for service registry
http://<domain>/services/bank-accounts/v2.0/
ZUUL
Reverse Proxy and Load Balancer
32. Senacor Technologies AG
Service Discovery in a Spring Cloud ZUUL application is
enabled via configuration and annotation @EnableDiscoveryClient
MICROSERVICE ARCHITECTURE - ELASTICITY
19.08.2017 FrOSCon 2017
zuul:
routes:
bankAccounts:
path: /bank-accounts/v1.0/**
serviceId: bankAccounts
eureka:
client:
serviceUrl:
defaultZone: <URL Registry>
Zuul Applicatin Configuration
33. Senacor Technologies AG
Service invocations with Feign
Simple creation of REST clients with connection to Eureka
Definition via interfaces and annotations
Activation of feign clients: @EnableFeignClients
@FeignClient("users-service")
interface UserClient {
@RequestMapping(method = RequestMethod.GET, value = "/user")
User getUser();
}
MICROSERVICE ARCHITECTURE - ELASTICITY
19.08.2017 FrOSCon 2017
34. Senacor Technologies AG
RESILIENCE
How to implement to implement resilience
in a Microservice architecture?
19.08.2017 FrOSCon 2017
2. Elasticity and Scalability
Cloud native applications
Microservice
Architecture
1. Embrace Change
Fast delivery of ideas into production
3. Embrace Failure
Cope with failures; high availability
4. Responsiveness and Reactivity
Excellent user experience from end-to-end
Elasticity
Resilience
Responsive
Changeability
35. Senacor Technologies AG
Resilience
The system stays responsive in the face of failure with
a graceful degradation of service if required
MICROSERVICE ARCHITECTURE - RESILIENCE
19.08.2017 FrOSCon 2017
Isolate
failures by
Redundancy
Insulation
Loose coupling
Circuit Breaker Pattern
Fallback
i.e. cached data
see Elasticity
own data store
asynchronous messaging
location transparency
eventual consistency
36. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - RESILIENCE
Unavailable services can affect the overall availability
of synchronous, blocking systems
19.08.2017 FrOSCon 2017
Microservice Backend
Requests
Timeout
37. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - RESILIENCE
19.08.2017 FrOSCon 2017
Circuit Breaker
The circuit breaker breaks the circuit instead of the house
burning down – since 1879
37
38. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - RESILIENCE
Circuit Breaker Pattern isolates backend access
19.08.2017 FrOSCon 2017
Microservice
x x
Backend
TimeoutFailfast
39. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - RESILIENCE
Hystrix isolates invocations in Server-side service compositions
19.08.2017 FrOSCon 2017
Web FrontendClients
Services Layer
…
ZUUL
Reverse Proxy and Load Balancer
Proxy
Account
Service
Authorization
Service
Service
Service
ServiceRegistryhttp://<domain>/services/bank-accounts/v2.0/
Hystrix
Hystrix
Hystrix Hystrix-Integration
40. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - RESPONSIVENESS
How to implement to implement responsiveness
in a Microservice architecture?
19.08.2017 FrOSCon 2017
2. Elasticity and Scalability
Cloud native applications
Microservice
Architecture
1. Embrace Change
Fast delivery of ideas into production
3. Embrace Failure
Cope with failures; high availability
4. Responsiveness and Reactivity
Excellent user experience from end-to-end
Elasticity
Resilience
Responsive
Changeability
41. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - RESPONSIVENESS
Client side service composition result in communication overhead
19.08.2017 FrOSCon 2017
100 ms
Browser
200 ms 300 ms 400 ms 500 ms 600 ms
Services
Server Request Latency Network Latency
Prefer server-side service compositions
42. Senacor Technologies AG
// load customer data
customerService.findById( customerId, reply -> {
// check on error
if (reply.succeeded()) {
// extract customer from reply
Customer customer = (Customer) reply.result().body();
// update address
customer.setAddress( "..." );
// update customer
customerService.update(customer, updateReply -> {
// ...
// nested code for error checking and processing
// ...
});
} else {
// process error
});
MICROSERVICE ARCHITECTURE - RESPONSIVENESS
Callbacks result in nested code
19.08.2017 FrOSCon 2017
43. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - RESPONSIVENESS - RXJAVA
How to design the API?
19.08.2017 FrOSCon 2017
single
data set
multiple
data sets
synchronous Object
Iterable
Stream
asynchronous
Callback
Future
CompletableFuture
Observable
44. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - RESPONSIVENESS - RXJAVA
19.08.2017 FrOSCon 2017
library for creating, transforming, composing and
subscribing asynchronous and event-based streams
using observable sequences
ObservableObserver
subscribe
onNext(T)
onError(Throwable t)
onCompleted()
45. Senacor Technologies AG
MICROSERVICE ARCHITECTURE - RESPONSIVENESS - RXJAVA
19.08.2017 FrOSCon 2017
// asynchronous send method returns an observable
customerService.findById", "123")
//extract customer from response
.map(asyncResult -> (Customer) asyncResult.body())
//update customer object
.map(customer -> ... )
//save customer data
.flatMap(customer -> customerService.update(customer))
//consume result and error
.subscribe(customer -> ..., error -> ... );
47. Senacor Technologies AG
Spring cloud offers a seamless integration of Netflix OSS that provides
infrastructure components for microservice systems
CONCLUSION
FrOSCon 2017
SpringCloud
Routing and Load-Balancing
Service registration and discovery
Messaging
Circuit Breakers
Service-to-service calls
NetflixOSS
Eureka
Ribbon
Zuul
RxJava
Hystrix
Feign
integrates
Tool integration and pattern
adaption for distributed systems
Distributed/versioned configuration
Archaius
19.08.2017
50. Senacor Technologies AG
Fehlertolerante und skalierbare Systeme
mit dem Netflix OSS
Dr. Michael Menzel, Senacor Technologies AG
Email: michael.menzel@senacor.com
Twitter: @mwmenzel
FrOSCon 2017, 19.08.2017
51. Senacor Technologies AG
Images links / Copyright belongs to resp. author
Rick Ligthelm ligthelm@flickr
Ben Babcock tachyondecay@flickr
PhotoArt Laatzen trombone65@flickr
Leslie Lamport wikipedia.org
Steve Watts quicksandala@morguefile.com
DAVINCI Haus 62694216@N05@flickr
Susanne Nilsson infomastern@flickr
Kurtis Garbutt kjgarbutt@flickr
Oliver Widder geek-and-poke.com
Angus MacRae gustaffo89@flickr
Lynne Cazaly lynnecazaly.com.au
REFERENCES
5151
ctbto@flickr
Stefano Leotta mylife1@flicker
Osvaldo Gago fotografar@flickr
Moyan Brenn aigle_dore@flickr
Martin Fowler martinfowler.com
leafbug@flickr
Sonya Ong and Travis Hydzik SonyaandTravis.com
Tony Guyton tonzpalmer24@flickr
Timothy Pearce timpearcelosgatos@flickr
dany13@flickr
Will Arktek https://www.flickr.com/people/bongonian