I am currently using App Engine in gcp,I want is use cloud CDN for my application. In the google cloud docs it is mentioned that i need to enable load balancer to use Cloud CDN for App Engine. Why should I enable load balancer when I am using app engine which is serverless. can someone explain.
Why do I need to enable LoadBalancer to enable Cloud CDN for App Engine in GCP?
726 Views Asked by ramsey AtThere are 2 best solutions below
On
As per this official doc
Cloud CDN (Content Delivery Network) uses Google's global edge network to serve content closer to users, which accelerates your websites and applications. Cloud CDN works with the global external HTTP(S) load balancer or the global external HTTP(S) load balancer (classic) to deliver content to your users.
The external Application Load Balancer provides the frontend IP addresses and ports that receive requests and the backends that respond to the requests.
When a user requests content from an external Application Load Balancer, the request arrives at a GFE that is at the edge of Google's network as close as possible to the user.
If the load balancer's URL map routes traffic to a backend service or backend bucket that has Cloud CDN configured, the GFE uses Cloud CDN
You can use the HTTP(S) Load Balancer to route static traffic to your Cloud Storage bucket and your web users or API clients to your serverless backend. This allows you to make the CDN quickly serving regularly accessed content, closer to users.
As explained above, in order to use Cloud CDN with your serverless origin you can simply enable Cloud CDN on the backend service that contains your serverless NEG. So you need to configure LoadBalancer to enable Cloud CDN for App Engine in GCP.
The other answers/comments are good, but you're asking 'why' so I'm going to try to answer that.
So why do you need to do this?
Because you need to tell GCP how to route traffic between your GCP services and in GCP that configuration lives in Google Cloud Load Balancer.
You were correct that many of GCP's services like App Engine come with a load balancer, think of it as a simplified version of Google Cloud Load Balancer. It comes configured with a bunch of reasonable default settings and lets you get up and running without needing to think about it. There are some basic settings you can set from within App Engine's settings / yaml files, but anything beyond that then you need to go through the process of setting up Google Cloud Load Balancer yourself. It seems that Cloud CDN doesn't come with a default load balancer.
I believe that when you setup Google Cloud Load Balancer for App Engine, that it takes the place of App Engine's default load balancer. I had to setup Google Cloud Load Balancer for my App Engine service and I didn't notice a slow down. But also, I don't think you necessarily need to have your App Engine traffic route through Google Cloud Load Balancer, as long as Cloud CDN is on a different subdomain.
I do believe that John Hanley was correct about Cloud CDN probably being overkill. You can serve static assets directly out of a Google Cloud Storage bucket or by specifying a
static_filesentry in your app.yaml. Both of those options are simpler and work well.