Resiliente Microservices mit Spring Boot und Failsafe
如果无法正常显示,请先停止浏览器的去广告插件。
1. Resiliente
Microservices mit
Spring Boot und
Failsafe
JavaLand 2018
13.03.2018
Malte Pickhan
@mpickhan
Zalando Payments GmbH
2. WHOAMI
> 5 years experience as Java
Backend Engineer
3 years in Telco industry
2 years in E-Commerce
Contributor to open source
Project (Failsafe-Actuator)
Published article in Java
Magazin (10/17)
2
3. ZALANDO TECHNOLOGY
help our brand to
HOME-BREWED,
CUTTING-EDGE
& SCALABLE
WIN ONLINE
technology solutions
1,800
employees from
77
nations
6
3
tech locations
+ HQs in Berlin
4. HANDS ON EXPERIENCE ON HOW WE BUILD
RESILIENT MICROSERVICES WITH
SPRING BOOT AND FAILSAFE
5. BLACK FRIDAY 2017
R
e
q
u
e
s
t
s
TIME
5
6. RESILIENCE
In computer networking: resilience is the ability to
provide and maintain an acceptable level of service
in the face of faults and challenges to normal
operation. [0]
6
7. MICROSERVICES
Accept failures instead of
avoiding them
•
•
•
•
7
Latency
Network
More clients
Maybe even unknown
clients
8. SPRING BOOT
Takes an opinionated view of
building production-ready
Spring applications. Spring
Boot favors convention over
configuration and is designed
to get you up and running as
quickly as possible. [1]
8
9. ACTUATOR
Actuator endpoints allow you to monitor and interact with
your application. Spring Boot includes a number of
built-in endpoints and you can also add your own. For
example the health endpoint provides basic application
health information. [2]
9
10. FAILSAFE
Failsafe is a lightweight, zero-dependency library for
handling failures. It was designed to be as easy to
use as possible, with a concise API for handling
everyday use cases and the flexibility to handle
everything else. [3]
10
11. FAILSAFE
Execution Context
Calls can be put to
Lambda expressions
or Callbacks
11
Supports retries out
of the box
Async execution can
be observed via
Listener API
12. EXAMPLE
12
13. CIRCUIT BREAKER
●
●
●
13
Fail fast
Be excellent to others
Three states
○ Closed
○ Open
○ Half Open
14. CIRCUIT BREAKER
14
15. THIS WAS GOOD, BUT WE CAN DO BETTER
16. FALLBACK
●
●
16
Call alternative service in
case primary is unavailable
Not only be available, but
also deliver valid results
17. REAL WORLD EXAMPLE
●
●
●
17
Product detail page
Customer might not be
interested in details at all
Why should we serve a 500
because of that and miss
the sale?
18. FALLBACK EXAMPLE
18
19. RETRY
●
●
●
19
Retry call in case of transient errors
Try to get as much through at possible
Every request is a paying customer
20. RETRY EXAMPLE
20
21. RETRY
delay = backoff + jitterFactor
●
●
●
21
backoff is growing exponentially with each retry
(1 .. 5 seconds)
jitterFactor is randomly picked in range
(-10 .. 10 ms)
retries will be equally distributed
22. MONITORING
●
●
●
22
Monitor Circuit Breaker to
identify problems early
Returns JSON containing
the state of all registered
Circuit Breaker
Failsafe-Actuator provides
this functionality
○ Spring Boot 2 support
close to come
23. DEMO
23
24. QUESTIONS?
25. BIBLIOGRAPHY
[0]
https://en.wikipedia.org/wiki/Resilience_(n
etwork)
[1]
https://projects.spring.io/spring-boot/
[2]
https://docs.spring.io/spring-boot/docs/curr
ent/reference/html/production-ready-endp
oints.html
[3]
https://github.co/mjhalterman/failsafe
25