C# Programming
Published in

C# Programming

Proactive Resilience Engineering

Photo from: https://www.rina.org/en/business/transport-infrastructure/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:

Demo
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.

Reference

Focuses on ASP.Net | ASP.Net Core | .Net & C# advance design, best practices & experiences to make developers life simple..!!

Recommended from Medium

Istio — Part 2: Traffic Management, Consistent Hashing, Canary & Dark Releases

My hackNY Application

Install Pygame Library Mac Python 2

Create Dismissible List in Flutter

Dust thrown in the wind

Working with Geospatial data — Part:4, Cloud Optimized GeoTiffs

Testing Embedded H2 DB with Scala and Scalatest

Data Mining: Instagram Scraper (1)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
LAI TOCA

LAI TOCA

Coding for fun

More from Medium

My top three technology podcasts

What is MVC in .NET ?

Things you should know about .NET 5 Updated Version

Write Cleaner Code Using C# 10