If you use yarp like load balancer like this, you can optimize this even further - yarp app does not have to be web api. Web apis today are lightweight, but if you want to push it to extremes, you can just make a console app and configure kestrel for your load balancer. Then your yarp will be available as a url, but is as lightweight as possible. If you only want to do load balancing with yarp, there's no need to have the whole machinery of web api behind yarp, configuring kestrel will be enough.
A few comments: - Health checks are meant for your destination boxes. To identify if they are alive and using configured logic re-route traffic to a healthy box. - Another benefit of having LB is to build highly available infra, but here you need to add another LB node. Not sure if YARP supports it - When your API will get a request thru the reverse proxy it will see the proxy IP address (not the client). I believe you need to configure additional headers For small projects might be that is OK to have a LB like this, but for the >=mid\prod apps I would prefer to have something that is optimized for this particular task.
There are many YARP config settings I left out that cover the topics you mentioned. I will check about running YARP in a HA setup, that piqued my curiosity.
Hi @MilanJovanovicTech, Again, another insightful video, thanks for sharing it. I know that this is a simple intro to how to start with a load balancer using yarp. In order to let us know that you were not lying us 😅 you showed the links attribute of the products endpoint. Here, I kept thinking that if you want to protect your APIs through the API Load Balancer/Gateway, the real path or domain of the application will be exposed, so I wonder if it's something that it has to be configured in Yarp or in the application (eShop) in order to transform those links or any other response that involves the application URL? Thanks again for your videos, they are really interesting and insightful!
Yeah, you'd have to forward the Load balancer address in a header - typically X-Forwarded-For - and fix the LinksService which generates the HATEOAS links to use the correct address
Awasome video.. Now bring us a Series of videos about YARP... Let me ask you something, can YARP request client certificates for authentication and forward them to apis via headers?
How does it compare to Ocelot? Seems like Ocelot supports more features than YARP, I mean, YARP seems a "pure" load balancer and Ocelot has other features (like Kubernetes integration) than a "pure" load balancer. Is there any specific reason to choose one over another?
YARP is used in Microsoft internally, for Azure App Service for example. It can also work as a Kubernetes ingress controller. It's not just a load balancer, it's mainly a reverse proxy. It can also be an API gateway. It has auth, rate limiting, etc.
Thank you for explaining this topic. I just have a question. If the service is deployed on server1 and server2, we can use application where yarp is used to route the requests. So, ideally this has to be on some other server say server3. What if the server3 is down. How can we handle this situation.
@@MilanJovanovicTech Okay. I have an issue, where I have a .NET Core web api application hosted in IIS, and also running the same application through VS 2022 Kestrel server (http), and have configured the IIS url in my appsettings.json file against the cluster destination address. So I want to call the Kestrel server api url but want YARP to reroute the request to the IIS api url. How do I know if YARP is forwarding the request from the Kestrel url to the IIS one correctly or not, as every time my 'HttpContext.Request.GetDisplayUrl()' is returning the Kestrel server url (using Round Robin LoadBalancingPolicy) instead of the IIS one. Any help will be great. Thanks.
@@MilanJovanovicTech If YARP is not routing the requests to the url defined in the cluster destination address, how to fix that? I am returning the value of 'HttpContext.Request.GetDisplayUrl()' in my api endpoint, which is always returning the original url, instead of the one I have mentioned in the appsettings.json cluster destination address.
If we setup our application (web api) on 3 different servers having unique IP-addresses.. say server1, server2 and server3. And Yarp is been setup on server1 as guided in your video. So by just configuring appsettings.json with their host address it should work?
I am having trouble finding performance metrics for YARP. Do you have any resources? I am interested in using this to route SignalR connections between a client and a SignalR server.
Yes, works great with Docker. Not sure about Kubernetes, but I found this: github.com/microsoft/reverse-proxy/blob/main/docs/docfx/articles/kubernetes-ingress.md
I assume YARP sends an X-Forwarded-For or something so you can adjust your HATEAOS links to point to the reverse proxy rather than directly into your API since usually you wouldn't use public ports on your API instances to force all traffic through the proxy/load balancer.
It's built in .NET and integrates with .NET Core... And it's faster than nginx
Год назад
@@MilanJovanovicTech Ok, but it is not reccomended to put kestrel directly to open world, as i know at least. But if you think that yarp hosted on kestrel can be exposed directly it make sense.
It's like you read my mind. I just have a use case where I need this. Thank you very much! Kind of random, but one thing I'm concerned about is your eyebrow raising. I feel like you might end up with forehead like Gordon Ramsay. Not trying to be mean, but helpful :) thanks again for the awesome content!
In your example, api is running on 3 ports and yarp is used as load balancer. Is there a way for yarp to know if any of those instances are down. So that yarp will stop sending the requests to it.
Great video but I came to find out a way where a custom implementation of ILoadBalancingPolicy actually works...? I'm trying to implement a custom fail-over policy but I don't know what I missing...
I don't get it how this can be used in real world scenario. In a real scenario, the instances will be dynamic, so you can't know what ports or how many instances will there be. How can I configure YARP to support dynamic scaling?
You can populate the Routes/Clusters at runtime, so you'd need a way to discover the services dynamically. In other words, you'd end up implementing service discovery. YARP config can do live-reloads at runtime, so that makes it a bit easier. I'll see if I can come up with a practical solution for this and demo it.
Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
Milan how does this applies to automatic scaling on Azure all service?
Just learned yarp last week, and I'm in love with it
Awesome stuff!
If you use yarp like load balancer like this, you can optimize this even further - yarp app does not have to be web api. Web apis today are lightweight, but if you want to push it to extremes, you can just make a console app and configure kestrel for your load balancer. Then your yarp will be available as a url, but is as lightweight as possible. If you only want to do load balancing with yarp, there's no need to have the whole machinery of web api behind yarp, configuring kestrel will be enough.
very helpful thank u
@@MsMagician0 you're welcome :)
Awesome! Are there any guidelines on this in the docs? 🤔
from dotnet core and above web apis are actually a console apps with krestel configuered so there is no difference I think
So, what's the difference if I use nginx, and config as reverse proxy and load balancer, instead of yarp?
A few comments:
- Health checks are meant for your destination boxes. To identify if they are alive and using configured logic re-route traffic to a healthy box.
- Another benefit of having LB is to build highly available infra, but here you need to add another LB node. Not sure if YARP supports it
- When your API will get a request thru the reverse proxy it will see the proxy IP address (not the client). I believe you need to configure additional headers
For small projects might be that is OK to have a LB like this, but for the >=mid\prod apps I would prefer to have something that is optimized for this particular task.
There are many YARP config settings I left out that cover the topics you mentioned. I will check about running YARP in a HA setup, that piqued my curiosity.
Simple and helpful. Thank you for such a great video.
Glad you enjoyed it!
Such a great video! 🤘
Glad you think so! I've another one for API gateways coming out soon
Hi @MilanJovanovicTech,
Again, another insightful video, thanks for sharing it.
I know that this is a simple intro to how to start with a load balancer using yarp. In order to let us know that you were not lying us 😅 you showed the links attribute of the products endpoint.
Here, I kept thinking that if you want to protect your APIs through the API Load Balancer/Gateway, the real path or domain of the application will be exposed, so I wonder if it's something that it has to be configured in Yarp or in the application (eShop) in order to transform those links or any other response that involves the application URL?
Thanks again for your videos, they are really interesting and insightful!
Yeah, you'd have to forward the Load balancer address in a header - typically X-Forwarded-For - and fix the LinksService which generates the HATEOAS links to use the correct address
@@MilanJovanovicTech thanks. I will check how to do it.
Awasome video.. Now bring us a Series of videos about YARP... Let me ask you something, can YARP request client certificates for authentication and forward them to apis via headers?
Yes, you can use YARP to handle authentication
Excellent video
Glad you liked it
Very interesting content. Thank you Milan.
Glad it was helpful!
Very useful video!
Glad to hear that!
Thank you
You're welcome!
Can you show us an example, in case we had 2 replicas on different servers, while loading the config from netflix eureka ? Making it more dynamic
Great idea!
Very helpful, thank you!!!
Glad it was helpful!
How does it compare to Ocelot?
Seems like Ocelot supports more features than YARP, I mean, YARP seems a "pure" load balancer and Ocelot has other features (like Kubernetes integration) than a "pure" load balancer.
Is there any specific reason to choose one over another?
YARP is used in Microsoft internally, for Azure App Service for example. It can also work as a Kubernetes ingress controller. It's not just a load balancer, it's mainly a reverse proxy. It can also be an API gateway. It has auth, rate limiting, etc.
@@MilanJovanovicTech which one do you prefer?
Me encanto el video. Muy, pero muy bueno
Thank you so much!
Thank you for explaining this topic. I just have a question. If the service is deployed on server1 and server2, we can use application where yarp is used to route the requests. So, ideally this has to be on some other server say server3. What if the server3 is down. How can we handle this situation.
imo this is not a coding problem
@@ibrahimb6791 It is a Yarp problem though. Yarp would need to handle the failing health checks. The question is, how to configure/achieve this?
You can run YARP in a HA setup, to improve availability. But if your gateway is down, so is your app
Great video.. Wanted to know, if YARP can be applied with a .NET Core Web API which is hosted in IIS over multiple VMs.
Yes
@@MilanJovanovicTech Okay. I have an issue, where I have a .NET Core web api application hosted in IIS, and also running the same application through VS 2022 Kestrel server (http), and have configured the IIS url in my appsettings.json file against the cluster destination address. So I want to call the Kestrel server api url but want YARP to reroute the request to the IIS api url.
How do I know if YARP is forwarding the request from the Kestrel url to the IIS one correctly or not, as every time my 'HttpContext.Request.GetDisplayUrl()' is returning the Kestrel server url (using Round Robin LoadBalancingPolicy) instead of the IIS one.
Any help will be great.
Thanks.
@@MilanJovanovicTech If YARP is not routing the requests to the url defined in the cluster destination address, how to fix that?
I am returning the value of 'HttpContext.Request.GetDisplayUrl()' in my api endpoint, which is always returning the original url, instead of the one I have mentioned in the appsettings.json cluster destination address.
Great video! 😊
Glad you liked it!
Great video
Glad it was valuable
If we setup our application (web api) on 3 different servers having unique IP-addresses.. say server1, server2 and server3. And Yarp is been setup on server1 as guided in your video. So by just configuring appsettings.json with their host address it should work?
Yes
I am having trouble finding performance metrics for YARP. Do you have any resources? I am interested in using this to route SignalR connections between a client and a SignalR server.
Here, page 13
msit.powerbi.com/view?r=eyJrIjoiYTZjMTk3YjEtMzQ3Yi00NTI5LTg5ZDItNmUyMGRlOTkwMGRlIiwidCI6IjcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI0NyIsImMiOjV9
@@MilanJovanovicTech Thanks a ton! I found this resource when I was looking on my own but I didn't know there were pages so I was very confused.
Hi Milan, So YARP can be easily implemented with Docker and Kubernetes?
Yes, works great with Docker. Not sure about Kubernetes, but I found this: github.com/microsoft/reverse-proxy/blob/main/docs/docfx/articles/kubernetes-ingress.md
@@MilanJovanovicTech thanks good sir! thank you I'll check it out
How would you configure a health check on the instances, and forward requests only to the healthy instances?
Here's how: microsoft.github.io/reverse-proxy/articles/dests-health-checks.html
I assume YARP sends an X-Forwarded-For or something so you can adjust your HATEAOS links to point to the reverse proxy rather than directly into your API since usually you wouldn't use public ports on your API instances to force all traffic through the proxy/load balancer.
Of course, I only left the original implementation in place to make the load balancing obvious.
Has yarp any advantages over use nginx as reverse proxy?
It's built in .NET and integrates with .NET Core... And it's faster than nginx
@@MilanJovanovicTech Ok, but it is not reccomended to put kestrel directly to open world, as i know at least. But if you think that yarp hosted on kestrel can be exposed directly it make sense.
It's like you read my mind. I just have a use case where I need this. Thank you very much!
Kind of random, but one thing I'm concerned about is your eyebrow raising. I feel like you might end up with forehead like Gordon Ramsay. Not trying to be mean, but helpful :) thanks again for the awesome content!
The eyebrows just mean he is a very interesting person
Can't fight it. The eyebrows have a mind of their own 🤣
What about Orleans? Have you tried it before?
Not yet
In your example, api is running on 3 ports and yarp is used as load balancer. Is there a way for yarp to know if any of those instances are down. So that yarp will stop sending the requests to it.
You can set this up: microsoft.github.io/reverse-proxy/articles/dests-health-checks.html
Will YARP work, if I set my application multiple instances on the same IIS server?
Yes, as long as they are on different ports
@@MilanJovanovicTech It is using the same CPU, and memory as the same computer. Will it work properly?
Great video but I came to find out a way where a custom implementation of ILoadBalancingPolicy actually works...? I'm trying to implement a custom fail-over policy but I don't know what I missing...
Did you explore health checks? microsoft.github.io/reverse-proxy/articles/dests-health-checks.html
@@MilanJovanovicTech I will investigate the matter. Thanks so much
What happens if a user has logged in against one of that API servers?
Proxy will pass the Authorization header to the API
using the load balancing of an apigateway like ocelot is not enough?
Sadly Ocelot is discontinued
YARP is a competitor.
I don't get it how this can be used in real world scenario. In a real scenario, the instances will be dynamic, so you can't know what ports or how many instances will there be. How can I configure YARP to support dynamic scaling?
You can populate the Routes/Clusters at runtime, so you'd need a way to discover the services dynamically. In other words, you'd end up implementing service discovery. YARP config can do live-reloads at runtime, so that makes it a bit easier. I'll see if I can come up with a practical solution for this and demo it.
Can it route the SignalR requests??
Good question, will have to check
Where I can download the source code in this video please
Check my github
❤
👋
Hi, how to make yarp show swager of all endpoints with which it works ?
YARP is a proxy, it doesn't really know which endpoints are defined behind the services
@@MilanJovanovicTech thanks for the answer!
Curious to know, why do you want to do that?