The electrical pattern that will keep your .NET services alive

  Рет қаралды 68,547

Nick Chapsas

Nick Chapsas

Күн бұрын

Пікірлер: 80
@kaiserbergin
@kaiserbergin 2 жыл бұрын
circuitbreaker + retry extensions with jitter + timeout + cached fallback == $$. I love polly.
@MartinMaat
@MartinMaat 2 жыл бұрын
When we learned about transistors/diodes in electronics class one of the first things the teacher said was "we won't speak of open and closed because these terms are horribly ambiguous, we will speak of pass-through and blocking".
@nickchapsas
@nickchapsas 2 жыл бұрын
I cannot begin to describe you how much this naming messed with me when I was first introduced to the topic
@galandilvogler8577
@galandilvogler8577 2 жыл бұрын
As an electronic engineer turned game developer, I'd like to point out that the correct terminology for transistors zones are cut-off ("off"), saturation ("on") and active (signal amplifier). I never heard of pass-through/blocking. For diodes, they're called forward ("on") and reverse ("off") bias.
@MartinMaat
@MartinMaat 2 жыл бұрын
@@galandilvogler8577 In reality my teacher used Dutch words. I freely translated them to English.
@pradipdixit2853
@pradipdixit2853 2 жыл бұрын
This is brilliant, easily understandable.. would like to see how you integrate this with the DI.
@TonoNamnum
@TonoNamnum 2 жыл бұрын
In my case this was useful when I send error notifications if something goes wrong. Sometimes sending to many errors via email/pushover is anoying. This patter will definitely help me solve that problem without having to code any complex logic.
@Forshen
@Forshen 2 жыл бұрын
This is brilliant. Definitely something I wanna try implementing/experimenting.
@Strekeln
@Strekeln 2 жыл бұрын
A good way to protect the APIs you need to call and well explained, good job.
@sebbe4717
@sebbe4717 Жыл бұрын
7:20 you talk about delegate and wrapping in a delegate, do you mean lambda function? or are these the same thing? im confused!
@KantiKiranBhupathi
@KantiKiranBhupathi 2 жыл бұрын
Very well demonstrated the cases.
@iSoldat
@iSoldat 2 жыл бұрын
I would hate to implement Polly from scratch and the more I learn, the more I realize, I need to learn more.
@02244
@02244 2 жыл бұрын
Why do you need to wait for 3 queries to fail when you can return the cached version immediately in the catch block for the method?
@Xamdify
@Xamdify 2 жыл бұрын
Because you cannot control wat a remote api does when you try to use it when it is down. Sometimes api’s ip ban the remote client that keeps failing. Also if you have certain amount of calls per day or month the failed request do count. So it is to prevent your api from using all the requests allotted for that time period.
@parlor3115
@parlor3115 2 жыл бұрын
@@Xamdify That doesn't answer his question. I think he's asking why doesn't Nick just return the cached data whenever an API call fails and my guess is this might not be the best example to showcase the package.
@alexclark6777
@alexclark6777 2 жыл бұрын
I think this was more a demo of Poly and its circuit breaking abilities rather than all the appropriate ways to handle failure, but yes I agree - seems if you have a cached value and the API you're forwarding your request onto fails, you should return that cached value and minimize disruption to the client. In this example, the API call had to fail several times in a row before falling back to the cached value, which seems inefficient.
@mheys1
@mheys1 2 жыл бұрын
Because you don't have to make an expensive api call and wait for it to fail, possibly wasting limited api calls before returning the cached version.
@wiser7062
@wiser7062 2 жыл бұрын
Because it's just an example?
@CarmenSantiNova
@CarmenSantiNova 2 жыл бұрын
Great video as always! While Polly is a great tool, in a real world application of a decent size you would want to get rid of this kind code from your services and instead push the problem to the infrastructure level. That way, your web service code have one less concern to take care of. Of course, your Ops will instead inherit that concern =O) What I'm talking about here is of course service meshes.
@nickchapsas
@nickchapsas 2 жыл бұрын
It depends on the problem. Your fallback logic can have domain specific logic in it. In that case I wouldn’t expose it to something like the api gateway and instead use something like Redis to manage the state. It really depends on the problem
@SuperMarcotorino
@SuperMarcotorino 2 жыл бұрын
Hi, Nick! Great video! I assume in real world applications you use combine both this and the retry techniques. Is my assumption correct? And, if so, do you have any recommendations / best practices on how to implement both propertly? (P.S.: I haven't gone deeply into Polly's documentation yet, so, if there is anything there which answers my question, feel free to simply point it out) ;-)
@abdurrahmanisk5238
@abdurrahmanisk5238 2 жыл бұрын
I would say it depends on situation. If you facing a non-durable service or 3rd party call with timeout issues, then using retry policy would sufficient. Circuit breaker is more convenient where service doesn't managed by you in any case of outage and cause cascading failures in your distributed systems. Answer is yes for your question. You can combine multiple policies with PolicyWrap extension. Again, it depends on need but maybe wait-and-retry policy first and then after circuit breaker policy could be strong handler for this type of situation.
@corso321
@corso321 2 жыл бұрын
Great explanation
@krzysztofhandzlik9273
@krzysztofhandzlik9273 2 жыл бұрын
Nice :), thanks polly rocks
@pinoyruel
@pinoyruel 2 жыл бұрын
Very nice explained, thanks a lot!
@crahun
@crahun 2 жыл бұрын
Wow, really interesting
@sheikhAbdelrahman
@sheikhAbdelrahman 2 жыл бұрын
This circuitbreake is easy to implement with your own code - no need to depend on external libraries for every tiny feature. I always prefer to implement myself all my main functionalities - HTTPClient, Webserver, SIP Server .. etc.
@jimifriis4507
@jimifriis4507 2 жыл бұрын
Thanks!
@foonlam7134
@foonlam7134 6 ай бұрын
How is it different from cancellation token. Why do we need to introduce the circuit breaker?
@kaisersolo76
@kaisersolo76 2 жыл бұрын
Good Stuff well explained.
@titiksasanti2205
@titiksasanti2205 2 жыл бұрын
Thank you!
@BK-19
@BK-19 2 жыл бұрын
Vey usefull thing. Dont know about this. Thank you Nick.
@bigboy3775
@bigboy3775 2 жыл бұрын
you're just great...
@tspang1977
@tspang1977 2 жыл бұрын
Thanks for the video. It is very useful. I have a question, how does the Polly keeps track of number of failed requests to "open the circuit". I am just thinking the scenario, in which we have a round-robin load-balanced servers and let's imagine we only have 2 round-robin servers. The first few hits could hit Server 1 and Server 1 may pop open the circuit but when the subsequent hit, it may go to Server 2 and it is a successful call, then third hit, it goes back to Server 1 and it fails. So, in this case, the client application will behave weirdly?
@nickchapsas
@nickchapsas 2 жыл бұрын
You’d need to plug in distributed extensions with Redis to keep track of the state on scaled out systems
@viswanathanms1905
@viswanathanms1905 2 жыл бұрын
Hi Nick, which editor are you using ?
@Soliber
@Soliber 2 жыл бұрын
Couldn’t you have combined Polly’s cache policy with a circuit breaker policy, instead of using a memory cache manually?
@thegautamnayak
@thegautamnayak 2 жыл бұрын
If the application is having multiple instances, how we can manage the state of the circuit across instances?
@nickchapsas
@nickchapsas 2 жыл бұрын
You hook up Redis
@bscamba
@bscamba 2 жыл бұрын
@@nickchapsas Any chance you make a video demonstrating this?
@faheemhusain6116
@faheemhusain6116 2 жыл бұрын
@Nick Chapsas please make a video on communication between microservice
@PovilasPanavas
@PovilasPanavas 2 жыл бұрын
How come you declared circuit breaker policy as not static variable, but it's still able to keep track count of failed requests?
@nickchapsas
@nickchapsas 2 жыл бұрын
Because the class it is used in is a singleton
@PovilasPanavas
@PovilasPanavas 2 жыл бұрын
@@nickchapsas oh, i see now :) thanks for explaining
@theandrewharry
@theandrewharry 2 жыл бұрын
My only concern to raise around this example is that one bad actor or poor integration can lead to the circuit breaker blocking the API for everyone.
@shadowthehedgehog2727
@shadowthehedgehog2727 2 жыл бұрын
How is the shared across like pods for instance? is it per pod if this was deployed in kube? newbie here
@nickchapsas
@nickchapsas 2 жыл бұрын
You can use the extension points to use something like Redis to distribute the state
@KantiKiranBhupathi
@KantiKiranBhupathi 2 жыл бұрын
Hi Nick, I became patreon member but not able access the code for this corresponding video. Please let me know ASAP
@nickchapsas
@nickchapsas 2 жыл бұрын
The code is there if you search the repo for any of the final code snippets
@KantiKiranBhupathi
@KantiKiranBhupathi 2 жыл бұрын
@@nickchapsas Hi Nick, Can you Please tell me the Git Repository name along with root folder name where I can find the code for this corresponding video. Thanks
@rick2591
@rick2591 2 жыл бұрын
Do you have any recommendation for fallback scenarios for database calls when you are dealing with millions of records? Also, is this cache variable global or local to the process?
@PovilasPanavas
@PovilasPanavas 2 жыл бұрын
Local: each instance of your app would have a separate InMemoryCache
@rasimismatulin1400
@rasimismatulin1400 2 жыл бұрын
how we can use this in Scoped services?
@wilmararias2083
@wilmararias2083 2 жыл бұрын
Hi can you make a video about how to handle Stale cookies when authentication is done through an identity Provider like azure Ad 😄 thanks 🙏
@IMarvinTPA
@IMarvinTPA 2 жыл бұрын
I half expected the example near the end to show using the real site as a fall-back option.
@md.nafisurrahman166
@md.nafisurrahman166 2 жыл бұрын
When David Warner becomes Programmer :D
@mahesh_rcb
@mahesh_rcb 2 жыл бұрын
How can we use this in case of getting the access token from third party APIs and making request to their APIs and if the token is expired how can we continue to get new token and continue where it was stopped before token would be valid for an hr or 30 mins
@vkishan2089
@vkishan2089 2 жыл бұрын
I am still trying to understand why we need circuit breaker.
@nickchapsas
@nickchapsas 2 жыл бұрын
Because when you keep calling services that fail or are down, you can cause further damage and not let them recover and also your service will be degraded as a result of that.
@nayanc4353
@nayanc4353 2 жыл бұрын
Don't we need to dispose httpClient?
@nickchapsas
@nickchapsas 2 жыл бұрын
No
@angelmoralesb
@angelmoralesb 2 жыл бұрын
😱
@metaltyphoon
@metaltyphoon 2 жыл бұрын
I’m not sure this is useful at all when a microservice is using a reverse proxy side car, which already does this for you.
@jonasbarka
@jonasbarka 2 жыл бұрын
This is my thought as well, that this is better handled in the reverse proxy or API-gateway than added to every service you got.
@nickchapsas
@nickchapsas 2 жыл бұрын
It is very much useful even with a reverse proxy. There are limits to how much logic you can dump there and you need to be very careful to not leak business logic to your revere proxy’s configuration
@Denominus
@Denominus 2 жыл бұрын
This is my recommended approach as well. Let the infrastructure handle as much of the dumb retrying/circuit breaking as possible. All the service meshes/modern proxies have extensive retry/circuit breaker features built in. Doing it all inside your services leads down the road of creating shared libraries to avoid duplicating it in every service and before you know it, you now have a core platform set of libraries/clients that MUST be used by every service so that they behave correctly. Doing it in the service is still useful when you need more context and logic around specific retries/circuit breakers. However, that should be the exception and not the rule.
@gamercabin8675
@gamercabin8675 2 жыл бұрын
Waiting for datetime and datetimeoffset
@brandonlee7542
@brandonlee7542 2 жыл бұрын
Was it just me that noticed "Port:6969"?..🤭
@lost-prototype
@lost-prototype 2 жыл бұрын
Get that private variable underscore out of here!! Super cool though, will have to check that library out.
@maskettaman1488
@maskettaman1488 2 жыл бұрын
Some people like their code to look nice and be easily understandable by others
@lost-prototype
@lost-prototype 2 жыл бұрын
@@maskettaman1488 Those people shouldn't put arbitrary prefixes everywhere then. Use your IDE.
@maskettaman1488
@maskettaman1488 2 жыл бұрын
@@lost-prototype What IDE highlights/indicates private variables by default? What is the benefit of relying on an IDE feature?
@rapha5210
@rapha5210 2 жыл бұрын
polly again?
@nickchapsas
@nickchapsas 2 жыл бұрын
Yeap. Polly doesn’t only support one resilience policy.
@richardarielcruzcespedes9455
@richardarielcruzcespedes9455 2 жыл бұрын
First comment
@joeypompeo9526
@joeypompeo9526 2 жыл бұрын
Would this be beneficial to use with azure functions as well? We have a lot of http clients with retry policies set up in our startup.cs, but we’re just using the standard Polly library.
@nickchapsas
@nickchapsas 2 жыл бұрын
It would be harder to maintain the state of the circuit breaker in an Azure function so you’d need to be careful with that
@MaxHogan80
@MaxHogan80 2 жыл бұрын
I don't understand if the circuit is referred to a api call including the querystring or not. I mean, "endpoint/api/action?arg=1" and "endpoint/api/action?arg=2" are two different and independent circuit or just one circuit focusing on the response of "endpoint/api/action" regardless the input parameters?
@EvaldasNaujikas
@EvaldasNaujikas 2 жыл бұрын
It is a single circuit. Otherwise his examples would not have worked.
@MaxHogan80
@MaxHogan80 2 жыл бұрын
@@EvaldasNaujikas my fault 😅
The fastest way to iterate a List in C# is NOT what you think
13:42
Nick Chapsas
Рет қаралды 159 М.
The CORRECT way to implement Retries in .NET
17:01
Nick Chapsas
Рет қаралды 89 М.
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
8 await async mistakes that you SHOULD avoid in .NET
21:13
Nick Chapsas
Рет қаралды 316 М.
You are doing .NET logging wrong. Let's fix it
25:29
Nick Chapsas
Рет қаралды 175 М.
C#: The Heap and the Stack
9:50
Edward Tanguay
Рет қаралды 39 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 264 М.
The Right Way To Return API Errors in .NET
10:40
Nick Chapsas
Рет қаралды 67 М.
What is Span in C# and why you should be using it
15:15
Nick Chapsas
Рет қаралды 262 М.
Why all your classes should be sealed by default in C#
11:43
Nick Chapsas
Рет қаралды 93 М.
Settling the Biggest Await Async Debate in .NET
14:47
Nick Chapsas
Рет қаралды 148 М.
What's New in .NET 9 with Examples
25:02
Nick Chapsas
Рет қаралды 67 М.
How IEnumerable can kill your performance in C#
11:02
Nick Chapsas
Рет қаралды 120 М.
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН