Proactive Resilience Engineering
Sometimes we would like to robust our application(s) or service(s) under diverse situations. For instance, networking recovering/monitoring handling (Retry/Circuit-breaker/Cache…policies). If you might interest more detail see Polly which could through you into more details.
The article might talking about using cache policy (memory cache) to handle duplicated requests (might comes from same identity: IP address or…) and acting with expected controlling.
Image that we have main service API that serve user authentication affairs. And we got one block list according the specific IP address that we would like to control and logs if any request belong to the list. The usual code flow might looks as below:
So far the code section works without any logical problem. But suppose If the same identity request coming in the instance highly frequency (maybe every 2–3 seconds per request). The logs function will consume the server resource for log down the meaningless information of duplicated records. we would like to avoid the case which apply cache policy would be the good ideal:
You could easily introduced memory cache via add method services.AddMemoryCache()[under class Startup.cs inside of ConfigureServices]
If your application running under ASP.NET CORE
After we apply cache policy that we have expected logs behavior:

T1, First entry we have captured the beginning request in (06:25:02) and logs down the relative information.
T2, Second entry we logs down the same request as we expected (06:25:27).
----------------------------------------
We have setup cache expired time to 20 seconds.
That means during the time interval 06:25:02-06:25:22,
We won't logs down (console print out) any duplicated information if the request came from the same identity (IP address).
Note that value(s) stored in memory cache will be reset if your application restart then.
Just the simplest example to demonstrate the basic way of proactive resilience programming. So far we have to connect more and more micro service(s) and cloud-based system(s) to serve diverse client(s) nowadays, how to design and stable each system’s component(s) would be important.