1

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.

imnotiam
  • 94
  • 8
  • What are you using Cloud CDN for? Is it to cache your App Engine app or to cache static assets? My recommendation is to study how caching works, and how the services are connected together. Once you configure a load balancer and caching, your App Engine app becomes just one of many supported backend resources. The primary resource is the load balancer, not App Engine. – John Hanley Jun 19 '23 at 16:53
  • @JohnHanley I'm using cloud CDN for caching my static assets. I understand how caching works. I cannot relate how load balancer and cdn work together. can you attach any reference link. And If possible can you explain me how both of these services are connected together? and since app-engine itself is serverless, it already has a load-balancer, right? why do I need to add one more layer of loadbalancer? – imnotiam Jun 20 '23 at 10:30
  • If you are caching static assets in Cloud Storage, then you must configure a load balancer. That is how Google designed it. You do not need to configure a load balancer for App Engine. Just use a subdomain for your static assets in Cloud Storage. For example, your App Engine app is `example.com` and `www.example.com`. Static assets are `static.example.com`. One of the reasons you must configure a load balancer and CDN for Cloud Storage is to provide CPU power. Cloud Storage offers no data processing. – John Hanley Jun 20 '23 at 15:44
  • What benefits do you expect from a CDN? Unless your site receives a lot of global traffic, the benefits might be negligible. Cloud Storage does not need a CDN. It is very fast all by itself. Make sure you are not over-designing your system. Simple is often the best choice. – John Hanley Jun 20 '23 at 15:47
  • @JohnHanley thank-you so much, your inputs are valuable. – imnotiam Jun 21 '23 at 05:17

2 Answers2

2

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_files entry in your app.yaml. Both of those options are simpler and work well.

Alex
  • 5,141
  • 12
  • 26
  • thanks mate, this clears the doubt I had, so when I enable cloud load balancer it replaces the default load balancer for app engine. I also have one more doubt, Forget about statics, If want to enable edge compute for app engine, is cloud CDN the only way for it? – imnotiam Jul 01 '23 at 03:29
  • `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.` what do you mean by Cloud CDN on different subdomain? Do I have to create another project or to have Cloud CDN for App Engine I need to go any other different procedures? – imnotiam Jul 03 '23 at 07:08
  • I believe you had to specify a region when you setup app engine, and thus app engine will only serve out of that region. I don't think there is a way to have app engine operate in a multi-region way. And I would think that Cloud CDN is just for static assets, not computing, but I'm not super familiar with Cloud CDN. For the different subdomain question, when I setup cloud load balancer, I followed these instructions: https://cloud.google.com/load-balancing/docs/https/setting-up-https-serverless My cloud LB was on a static IP, I added an A record in my DNS to point to it, and setup the cert – Alex Jul 05 '23 at 03:51
  • You probably setup a custom domain for app engine (in app engine's default load balancer). One option is to leave that alone and point a different subdomain to the new Google Cloud LB you'd setup for Cloud CDN and not put app engine behind Google Cloud LB. You don't need to setup another GCP project. You can have multiple subdomains point to a single GCP project. That's what I did. – Alex Jul 05 '23 at 03:59
1

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.

Sai Chandini Routhu
  • 750
  • 1
  • 3
  • 13
  • I understand, but I still have some doubts why does google cloud tightly coupled cloud load balancer and cloud cdn? when app engine itself can handle all the request why does a load balancer required? – imnotiam Jun 20 '23 at 10:47