Protect your users with Circuit breakers
-
Upload
scott-triglia -
Category
Software
-
view
169 -
download
0
Transcript of Protect your users with Circuit breakers
![Page 1: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/1.jpg)
Protect your users with Circuit Breakers
Scott Triglia Europython 2016
1
Jim’s
![Page 2: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/2.jpg)
2
Yelp’s Mission:Connecting people with great
local businesses.
![Page 3: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/3.jpg)
Yelp StatsAs of Q1 2016
90M 3270%102M
![Page 4: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/4.jpg)
Scott Triglia
4
@scott_triglia
Work with the $$$
![Page 5: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/5.jpg)
Let’s talk Circuit Breakers
5
![Page 6: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/6.jpg)
6
![Page 7: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/7.jpg)
7
![Page 8: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/8.jpg)
8
![Page 9: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/9.jpg)
9
![Page 10: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/10.jpg)
10
![Page 11: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/11.jpg)
Our goals today: introduce a basic circuit breaker
11
![Page 12: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/12.jpg)
Our goals today: a modular circuit breaker
12
![Page 13: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/13.jpg)
Our goals today: test it out on several scenarios
13
![Page 14: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/14.jpg)
14
![Page 15: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/15.jpg)
15
![Page 16: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/16.jpg)
1616
1
2
34
![Page 17: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/17.jpg)
the fundamental rule: your systems will fail
what’s your response?17
![Page 18: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/18.jpg)
1818
1
2
![Page 19: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/19.jpg)
1919
1
2
3
![Page 20: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/20.jpg)
2020
1
2
34
![Page 21: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/21.jpg)
21
Nygard’s circuit breaker
![Page 22: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/22.jpg)
22
![Page 23: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/23.jpg)
23
![Page 24: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/24.jpg)
24
![Page 25: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/25.jpg)
25
![Page 26: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/26.jpg)
26
Circuit Breaker States: * Healthy (or “closed”) * Recovering (or “half-open”) * Unhealthy (or “open”)
![Page 27: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/27.jpg)
27
![Page 28: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/28.jpg)
28
Recovery:
* Wait for recovery_timeout seconds* Send a trial request, trust its results
![Page 29: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/29.jpg)
29
Before a circuit breaker:
![Page 30: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/30.jpg)
30
Before a circuit breaker: * Diners wait forever to get food
![Page 31: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/31.jpg)
31
Before a circuit breaker: * Diners wait forever to get food * Kitchen has a growing backlog
![Page 32: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/32.jpg)
32
Before a circuit breaker: * Diners wait forever to get food * Kitchen has a growing backlog * New diners making things worse
![Page 33: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/33.jpg)
33
With a circuit breaker:
![Page 34: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/34.jpg)
34
With a circuit breaker: * Fewer frustrated users
![Page 35: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/35.jpg)
35
With a circuit breaker: * Fewer frustrated users * Reduced load on the backend
![Page 36: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/36.jpg)
36
With a circuit breaker: * Fewer frustrated users * Reduced load on the backend * A well defined failure mode
![Page 37: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/37.jpg)
37
![Page 38: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/38.jpg)
38
![Page 39: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/39.jpg)
39
![Page 40: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/40.jpg)
40
![Page 41: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/41.jpg)
41
![Page 42: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/42.jpg)
42
Should our waiters all agree?
Module 1:
![Page 43: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/43.jpg)
43
![Page 44: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/44.jpg)
44
![Page 45: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/45.jpg)
45
New Behavior: * Clients inform each other * Processes are no longer independent
![Page 46: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/46.jpg)
46
* Propagate failure faster
* Requires distributed datastore * Forces decisions about consistency
![Page 47: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/47.jpg)
47
What should we do in response?
Module 2:
![Page 48: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/48.jpg)
48
![Page 49: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/49.jpg)
49
![Page 50: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/50.jpg)
50
![Page 51: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/51.jpg)
51
![Page 52: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/52.jpg)
52
New Behavior: * Code can check in advance about healthiness of system * Automatic monitoring!
![Page 53: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/53.jpg)
53
* Build features on top of system health status
* Requires a single source of truth?
![Page 54: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/54.jpg)
54
Who decides we’re unhealthy?
Module 3:
![Page 55: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/55.jpg)
55
![Page 56: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/56.jpg)
56
def signal_overload(cb): if len(jobs) > THRESH: cb.mark_unhealthy()
![Page 57: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/57.jpg)
57
New Behavior:
* CB gets signals from anywhere * Signal combining logic
![Page 58: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/58.jpg)
58
* Allows many (many) new signals
* Must combine signals * Adds complexity to system
![Page 59: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/59.jpg)
59
How do we recover?
Module 4:
![Page 60: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/60.jpg)
60
![Page 61: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/61.jpg)
61
Dark launch:
* Reject but process normally * Dangerous with side effects
Block User Request Try to process anyway!
![Page 62: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/62.jpg)
62
Synthetic:
* Dark launching with fake requests * Not necessarily representative
Block User Request Process fake requests
![Page 63: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/63.jpg)
63
New Behavior:
* Traffic determines health * Removal of recovery timeouts
![Page 64: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/64.jpg)
64
* Faster(?) recovery * No timeout tuning required * Dark launching not always possible * Synthetic can be unrepresentative
![Page 65: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/65.jpg)
65
in summary
![Page 66: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/66.jpg)
66
Your system will fail, have a plan!
![Page 67: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/67.jpg)
67
The basic CB is better than nothing
![Page 68: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/68.jpg)
68
Questions to ask:
* Should our waiters all agree? * How should I deal with unhealthiness? * Who decides we’re unhealthy? * How do we recover?
![Page 69: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/69.jpg)
69
Questions to ask:
* Should our waiters all agree? * How should I deal with unhealthiness? * Who decides we’re unhealthy? * How do we recover?
![Page 70: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/70.jpg)
70
Questions to ask:
* Should our waiters all agree? * How should I deal with unhealthiness? * Who decides we’re unhealthy? * How do we recover?
![Page 71: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/71.jpg)
71
Questions to ask:
* Should our waiters all agree? * How should I deal with unhealthiness? * Who decides we’re unhealthy? * How do we recover?
![Page 72: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/72.jpg)
72
Questions to ask:
* Should our waiters all agree? * How should I deal with unhealthiness? * Who decides we’re unhealthy? * How do we recover?
![Page 73: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/73.jpg)
73
…and much more!
![Page 74: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/74.jpg)
Much comes down to your use case
74
![Page 76: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/76.jpg)
![Page 77: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/77.jpg)
77
Can’t we do better than rejecting requests?
![Page 78: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/78.jpg)
http://techblog.netflix.com/2011/12/making-netflix-api-more-resilient.html
![Page 79: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/79.jpg)
79
How do I safely test out a new circuit breaker?
![Page 80: Protect your users with Circuit breakers](https://reader031.fdocuments.in/reader031/viewer/2022030311/58ef67fa1a28ab58668b467d/html5/thumbnails/80.jpg)
https://engineering.heroku.com/blogs/2015-06-30-improved-production-stability-with-circuit-breakers/