reliability and resilience
DESCRIPTION
How to add reliability and resilience into your codeTRANSCRIPT
![Page 1: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/1.jpg)
Thank you to our Sponsors
Media Sponsor:
![Page 2: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/2.jpg)
SystemReliability and
Resilienceand stuff
![Page 3: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/3.jpg)
tuple
![Page 4: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/4.jpg)
//Initialize customer and invoiceInitialize(customer, invoice);
![Page 5: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/5.jpg)
public void Initialize(Customer customer, Invoice
invoice){
customer.Name = “asdf”;invoice.Date = DateTime.Now;
}
![Page 6: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/6.jpg)
Initialize(customer, invoice);//did something happen to customer// and/or invoice?
![Page 7: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/7.jpg)
customer.Name =
InitNameFrom(customer, invoice);invoice.Date =
InitDateFrom(customer, invoice);
![Page 8: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/8.jpg)
customer.Name =
GetNameFrom(customer, invoice);invoice.Date =
GetDateFrom(customer, invoice);
![Page 9: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/9.jpg)
var results = Initialize(customer,
invoice);
customer.Name = results.Item1;invoice.Date = results.Item2;
![Page 10: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/10.jpg)
public tuple<string, DateTime>Initialize(customer,
invoice){
return new Tuple<string, DateTime>
(“asdf”, DateTime.Now);}
![Page 11: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/11.jpg)
public static bool TryParse(string s, out DateTime result)
or
public static tuple<bool, DateTime?>
TryParse(string s)
![Page 12: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/12.jpg)
tuple• Avoid side effects• Avoid out parameters•multiple values without a specific type
![Page 13: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/13.jpg)
null object
![Page 14: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/14.jpg)
private ILogger _logger;public MyClass(ILogger logger) {
_logger = logger;}
…
if (_logger != null) {_logger.Debug(
“it worked on my machine!”);}
![Page 15: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/15.jpg)
null checks for everyone!
![Page 16: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/16.jpg)
forget one and…
![Page 17: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/17.jpg)
public class NullLogger : ILogger {
public void Debug(string text) {
//do sweet nothing}
}
![Page 18: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/18.jpg)
private ILogger _logger = new NullLogger();
public MyClass(ILogger logger) {_logger = logger;
}
…
_logger.Debug(“it worked on my machine!”);
![Page 19: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/19.jpg)
null object• Can eliminate null checks• Simple to implement
![Page 20: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/20.jpg)
Circuit Breaker
![Page 21: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/21.jpg)
![Page 22: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/22.jpg)
Retry
![Page 23: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/23.jpg)
You
r A
pp
licati
on O
ut o
f Pro
cess
Dep
en
dency
N times
![Page 24: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/24.jpg)
Ou
t of P
roce
ss D
ep
en
dency
N times*
Y clients
![Page 25: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/25.jpg)
= Denial of Service Attack
![Page 26: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/26.jpg)
Limit the # of retries
![Page 27: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/27.jpg)
N * Ybecomes
5 * Y
![Page 28: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/28.jpg)
Y isstill a
problem
![Page 29: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/29.jpg)
![Page 30: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/30.jpg)
Circuit Breaker
![Page 31: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/31.jpg)
![Page 32: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/32.jpg)
State Machine
On :: Off
![Page 33: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/33.jpg)
On Offwhen not healthy
![Page 34: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/34.jpg)
Off Onmanually
![Page 35: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/35.jpg)
Get to softwarebefore we ask you to dance
![Page 36: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/36.jpg)
Healthyor
Unhealthy
Ou
t of P
roce
ss D
ep
en
dency
![Page 37: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/37.jpg)
State is independent of requestor
Ou
t of P
roce
ss D
ep
en
dency
![Page 38: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/38.jpg)
You
r A
pp
licati
on
Has many independent external dependencies
![Page 39: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/39.jpg)
You
r A
pp
licati
on
Can throttle itself
![Page 40: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/40.jpg)
You
r A
pp
licati
on
Has a wait threshold
![Page 41: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/41.jpg)
Your Application
External Dependency
Circuit Breaker
Threshold = 2Pause = 10msTimeout = 30sState = ClosedRequest
Request
Failure (i.e. HTTP 500)Failure Count = 1Pause 10ms
Request
Failure (i.e. HTTP 500)Failure Count = 2State = Open
OperationFailedException
![Page 42: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/42.jpg)
Threshold = 2Pause = 10msTimeout = 30sState = OpenRequest
30s has not passed
CircuitBreakerOpenException
Request
30s has not passed
CircuitBreakerOpenException
System can try to
become healthyfor 30s
Your Application
External Dependency
Circuit Breaker
![Page 43: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/43.jpg)
Threshold = 2Pause = 10msTimeout = 30sState = ½ OpenRequest
Request
Failure (i.e. HTTP 500)
Failure Count = 2State = Open
OperationFailedException
30s has passed
Your Application
External Dependency
Circuit Breaker
![Page 44: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/44.jpg)
Threshold = 2Pause = 10msTimeout = 30sState = ½ OpenRequest
Request
Failure Count = 0State = Closed
Response
30s has passed
Response
Your Application
External Dependency
Circuit Breaker
![Page 45: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/45.jpg)
ClosedOpen
½ Open
![Page 46: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/46.jpg)
½ Open is like a
manual reset
![Page 47: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/47.jpg)
PauseTimeout
![Page 48: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/48.jpg)
Pausebetween calls
in the loop
![Page 49: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/49.jpg)
Timeoutbefore you
can call again
![Page 50: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/50.jpg)
Exceptions
![Page 51: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/51.jpg)
OperationFailed:
AggregateException
![Page 52: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/52.jpg)
CircuitBreakerOpen:
ApplicationException
![Page 53: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/53.jpg)
Don’t Loose Exception Info
![Page 54: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/54.jpg)
Always use InnerException(s)
![Page 55: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/55.jpg)
Threshold = 3State = ClosedRequest
Request
Failure (i.e. HTTP 500)Request
Failure (i.e. HTTP 500)Failure Count = 2
Failure Count = 0State = Closed
Response
Response
Request?
Your Application
External Dependency
Circuit Breaker
Failure Count = 1
![Page 56: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/56.jpg)
SegregateDependencies
![Page 57: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/57.jpg)
circuitBreaker(“database”)
circuitBreaker(“weatherservice”)
![Page 58: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/58.jpg)
Dependency type, endpoint svc,
endpoint
![Page 59: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/59.jpg)
Where?
![Page 60: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/60.jpg)
You
r A
pp
licati
on O
ut o
f Pro
cess
Dep
en
dency
Cir
cuit
Bre
ake
r
Pro
xy
![Page 61: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/61.jpg)
Watch forInception
![Page 62: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/62.jpg)
You
r A
pp
licati
on W
eb
Serv
iceC
ircu
it B
reake
r
Cir
cuit
Bre
ake
r
Pro
xy
Data
base
Reposi
tory
![Page 63: Reliability and Resilience](https://reader035.vdocument.in/reader035/viewer/2022062709/5590ee6c1a28ab16748b4790/html5/thumbnails/63.jpg)
circuit breaker• retry looping• slow down attempts• good neighbour