670 likes | 809 Vues
This document discusses strategies for improving system reliability and resilience, specifically focusing on the implementation of circuit breakers. Circuit breakers can help manage external dependencies by preventing overwhelming requests when a service becomes unavailable, thus enhancing application stability. This includes initialization techniques for managing customers and invoices, handling potential null references with a Null Object pattern, and establishing a robust retry mechanism to gracefully handle failures. The implementation details are tailored for developers seeking to bolster the resilience of their applications.
E N D
SystemReliability and Resilience and stuff
//Initialize customer and invoiceInitialize(customer, invoice);
public void Initialize (Customer customer, Invoice invoice){customer.Name=“asdf”;invoice.Date =DateTime.Now;}
Initialize(customer, invoice);//did something happen to customer// and/or invoice?
customer.Name =InitNameFrom(customer, invoice);invoice.Date = InitDateFrom(customer, invoice);
customer.Name =GetNameFrom(customer, invoice);invoice.Date = GetDateFrom(customer, invoice);
var results = Initialize(customer, invoice);customer.Name =results.Item1;invoice.Date = results.Item2;
public tuple<string, DateTime>Initialize(customer, invoice){ return new Tuple<string, DateTime> (“asdf”, DateTime.Now);}
public static boolTryParse (string s, outDateTime result)orpublic static tuple<bool, DateTime?>TryParse (string s)
tuple • Avoid side effects • Avoid out parameters • multiple values without a specific type
private ILogger _logger;public MyClass(ILogger logger) {_logger = logger;}…if (_logger != null) {_logger.Debug(“it worked on my machine!”);}
public class NullLogger:ILogger{ public void Debug(string text) { //do sweet nothing}}
private ILogger _logger = newNullLogger();public MyClass(ILogger logger) {_logger = logger;}…_logger.Debug(“it worked on my machine!”);
null object • Can eliminate null checks • Simple to implement
Your Application Out of Process Dependency N times
Out of Process Dependency N times * Y clients
HealthyorUnhealthy Out of Process Dependency
State is independent of requestor Out of Process Dependency
Has many independent external dependencies Your Application
Can throttle itself Your Application
Has a wait threshold Your Application
Circuit Breaker External Dependency Your Application Threshold = 2 Pause = 10ms Timeout = 30s State = Closed Request Request Failure (i.e. HTTP 500) Failure Count = 1 Pause 10ms Request Failure (i.e. HTTP 500) Failure Count = 2 State = Open OperationFailedException
Circuit Breaker External Dependency Your Application Threshold = 2 Pause = 10ms Timeout = 30s State = Open System can try to become healthy for 30s Request 30s has not passed CircuitBreakerOpenException Request 30s has not passed CircuitBreakerOpenException
Circuit Breaker External Dependency Your Application Threshold = 2 Pause = 10ms Timeout = 30s State = ½ Open 30s has passed Request Request Failure (i.e. HTTP 500) Failure Count = 2 State = Open OperationFailedException
Circuit Breaker External Dependency Your Application Threshold = 2 Pause = 10ms Timeout = 30s State = ½ Open 30s has passed Request Request Response Failure Count = 0 State = Closed Response