41
Resilient Applications with Circuit Breakers

Resilient Applications with Circuit Breakers

Embed Size (px)

Citation preview

Resilient Applications

with Circuit Breakers

failure • n. (pl. failures) 1 inability of a system or component to perform its required functions within specified performance requirements

Extracted from Netflix’s Github

Dependencies

Extracted from Netflix’s Github

Dependencies

Extracted from Netflix’s Github

Dependencies

Error propagation

Embrace failure● Faults will occur● Faults are tolerable

“We should write software that is cynical and expects bad things to happen” - Michael T. Nygard

1 an automatic device for stopping the flow of a current in an electric circuit as a safety measure

circuit-breaker • n. (pl. circuit-breakers)

Resilience

● Fail fast

Resilience

● Fail fast● Rapidly recover

The Pattern

Netflix Hystrix

How it works● Wrap calls● Thread pool● Timeout● Measuring● Fallback

The Code

class SleepCommand extends HystrixCommand<String> {

SleepCommand() { super( withGroupKey('sleep-group'). andCommandPropertiesDefaults( withCircuitBreakerSleepWindowInMilliseconds(wait). withExecutionTimeoutInMilliseconds(timeout) ) ) } ...

class SleepCommand extends HystrixCommand<String> {

SleepCommand() { super( withGroupKey('sleep-group'). andCommandPropertiesDefaults( withCircuitBreakerSleepWindowInMilliseconds(wait). withExecutionTimeoutInMilliseconds(timeout) ) ) } ...

class SleepCommand extends HystrixCommand<String> {

SleepCommand() { super( withGroupKey('sleep-group'). andCommandPropertiesDefaults( withCircuitBreakerSleepWindowInMilliseconds(wait). withExecutionTimeoutInMilliseconds(timeout) ) ) } ...

class SleepCommand extends HystrixCommand<String> {

SleepCommand() { super( withGroupKey('sleep-group'). andCommandPropertiesDefaults( withCircuitBreakerSleepWindowInMilliseconds(wait). withExecutionTimeoutInMilliseconds(timeout) ) ) } ...

class SleepCommand extends HystrixCommand<String> {

SleepCommand() { super( withGroupKey('sleep-group'). andCommandPropertiesDefaults( withCircuitBreakerSleepWindowInMilliseconds(wait). withExecutionTimeoutInMilliseconds(timeout) ) ) } ...

static final Integer timeout = 100

@Override String run() throws Exception { def time = Math.abs random.nextInt(150) Thread.sleep time "Sleeped for ${time} miliseconds" }

@Override String getFallback() { "Didn't sleep at all" }

static final Integer timeout = 100

@Override String run() throws Exception { def time = Math.abs random.nextInt(150) Thread.sleep time "Sleeped for ${time} miliseconds" }

@Override String getFallback() { "Didn't sleep at all" }

static final Integer timeout = 100

@Override String run() throws Exception { def time = Math.abs random.nextInt(150) Thread.sleep time "Sleeped for ${time} miliseconds" }

@Override String getFallback() { "Didn't sleep at all" }

static final Integer timeout = 100

@Override String run() throws Exception { def time = Math.abs random.nextInt(150) Thread.sleep time "Sleeped for ${time} miliseconds" }

@Override String getFallback() { "Didn't sleep at all" }

References

References

References

References

References

ReferencesRelease It, Design and Deploy Production-ready Software, Michael T. Nygardhttps://pragprog.com/book/mnee/release-it

Application Resilience Engineering at Netflix, Ben Christensenhttps://www.youtube.com/watch?v=RzlluokGi1w

Operational Excellence with Netflix Hystrix, Billy Yuenhttps://www.youtube.com/watch?v=VuCYkY7pFk8

Making Netflix more resilient, Ben Schmaushttp://techblog.netflix.com/2011/12/making-netflix-api-more-resilient.html

Hystrix, Defend Your App, Netflix Githubhttps://github.com/Netflix/Hystrix/wiki/How-it-Works

Josué Neis

jneis josueneis josueneis