Protect your users with Circuit breakers

80
Protect your users with Circuit Breakers Scott Triglia Europython 2016 1 Jim’s

Transcript of Protect your users with Circuit breakers

Page 1: Protect your users with Circuit breakers

Protect your users with Circuit Breakers

Scott Triglia Europython 2016

1

Jim’s

Page 2: Protect your users with Circuit breakers

2

Yelp’s Mission:Connecting people with great

local businesses.

Page 3: Protect your users with Circuit breakers

Yelp StatsAs of Q1 2016

90M 3270%102M

Page 4: Protect your users with Circuit breakers

Scott Triglia

4

@scott_triglia

Work with the $$$

Page 5: Protect your users with Circuit breakers

Let’s talk Circuit Breakers

5

Page 6: Protect your users with Circuit breakers

6

Page 7: Protect your users with Circuit breakers

7

Page 8: Protect your users with Circuit breakers

8

Page 9: Protect your users with Circuit breakers

9

Page 10: Protect your users with Circuit breakers

10

Page 11: Protect your users with Circuit breakers

Our goals today: introduce a basic circuit breaker

11

Page 12: Protect your users with Circuit breakers

Our goals today: a modular circuit breaker

12

Page 13: Protect your users with Circuit breakers

Our goals today: test it out on several scenarios

13

Page 14: Protect your users with Circuit breakers

14

Page 15: Protect your users with Circuit breakers

15

Page 16: Protect your users with Circuit breakers

1616

1

2

34

Page 17: Protect your users with Circuit breakers

the fundamental rule: your systems will fail

what’s your response?17

Page 18: Protect your users with Circuit breakers

1818

1

2

Page 19: Protect your users with Circuit breakers

1919

1

2

3

Page 20: Protect your users with Circuit breakers

2020

1

2

34

Page 21: Protect your users with Circuit breakers

21

Nygard’s circuit breaker

Page 22: Protect your users with Circuit breakers

22

Page 23: Protect your users with Circuit breakers

23

Page 24: Protect your users with Circuit breakers

24

Page 25: Protect your users with Circuit breakers

25

Page 26: Protect your users with Circuit breakers

26

Circuit Breaker States: * Healthy (or “closed”) * Recovering (or “half-open”) * Unhealthy (or “open”)

Page 27: Protect your users with Circuit breakers

27

Page 28: Protect your users with Circuit breakers

28

Recovery:

* Wait for recovery_timeout seconds* Send a trial request, trust its results

Page 29: Protect your users with Circuit breakers

29

Before a circuit breaker:

Page 30: Protect your users with Circuit breakers

30

Before a circuit breaker: * Diners wait forever to get food

Page 31: Protect your users with Circuit breakers

31

Before a circuit breaker: * Diners wait forever to get food * Kitchen has a growing backlog

Page 32: Protect your users with Circuit breakers

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

33

With a circuit breaker:

Page 34: Protect your users with Circuit breakers

34

With a circuit breaker: * Fewer frustrated users

Page 35: Protect your users with Circuit breakers

35

With a circuit breaker: * Fewer frustrated users * Reduced load on the backend

Page 36: Protect your users with Circuit breakers

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

37

Page 38: Protect your users with Circuit breakers

38

Page 39: Protect your users with Circuit breakers

39

Page 40: Protect your users with Circuit breakers

40

Page 41: Protect your users with Circuit breakers

41

Page 42: Protect your users with Circuit breakers

42

Should our waiters all agree?

Module 1:

Page 43: Protect your users with Circuit breakers

43

Page 44: Protect your users with Circuit breakers

44

Page 45: Protect your users with Circuit breakers

45

New Behavior: * Clients inform each other * Processes are no longer independent

Page 46: Protect your users with Circuit breakers

46

* Propagate failure faster

* Requires distributed datastore * Forces decisions about consistency

Page 47: Protect your users with Circuit breakers

47

What should we do in response?

Module 2:

Page 48: Protect your users with Circuit breakers

48

Page 49: Protect your users with Circuit breakers

49

Page 50: Protect your users with Circuit breakers

50

Page 51: Protect your users with Circuit breakers

51

Page 52: Protect your users with Circuit breakers

52

New Behavior: * Code can check in advance about healthiness of system * Automatic monitoring!

Page 53: Protect your users with Circuit breakers

53

* Build features on top of system health status

* Requires a single source of truth?

Page 54: Protect your users with Circuit breakers

54

Who decides we’re unhealthy?

Module 3:

Page 55: Protect your users with Circuit breakers

55

Page 56: Protect your users with Circuit breakers

56

def signal_overload(cb): if len(jobs) > THRESH: cb.mark_unhealthy()

Page 57: Protect your users with Circuit breakers

57

New Behavior:

* CB gets signals from anywhere * Signal combining logic

Page 58: Protect your users with Circuit breakers

58

* Allows many (many) new signals

* Must combine signals * Adds complexity to system

Page 59: Protect your users with Circuit breakers

59

How do we recover?

Module 4:

Page 60: Protect your users with Circuit breakers

60

Page 61: Protect your users with Circuit breakers

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

62

Synthetic:

* Dark launching with fake requests * Not necessarily representative

Block User Request Process fake requests

Page 63: Protect your users with Circuit breakers

63

New Behavior:

* Traffic determines health * Removal of recovery timeouts

Page 64: Protect your users with Circuit breakers

64

* Faster(?) recovery * No timeout tuning required * Dark launching not always possible * Synthetic can be unrepresentative

Page 65: Protect your users with Circuit breakers

65

in summary

Page 66: Protect your users with Circuit breakers

66

Your system will fail, have a plan!

Page 67: Protect your users with Circuit breakers

67

The basic CB is better than nothing

Page 68: Protect your users with Circuit breakers

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

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

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

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

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

73

…and much more!

Page 74: Protect your users with Circuit breakers

Much comes down to your use case

74

Page 75: Protect your users with Circuit breakers

Questions?

75

[email protected] @scott_triglia

Page 76: Protect your users with Circuit breakers
Page 77: Protect your users with Circuit breakers

77

Can’t we do better than rejecting requests?

Page 78: Protect your users with Circuit breakers

http://techblog.netflix.com/2011/12/making-netflix-api-more-resilient.html

Page 79: Protect your users with Circuit breakers

79

How do I safely test out a new circuit breaker?

Page 80: Protect your users with Circuit breakers

https://engineering.heroku.com/blogs/2015-06-30-improved-production-stability-with-circuit-breakers/