Create a CDN with Google Cloud and Image Optimization
D

1

13

I have many websites and also websites made by clients which I would like to optimize. I am currently using different CDN providers but I would like to simplify my workflow and hopefully also lower the costs.

I would like to have a CDN with a Pull Zone, and that CDN would also optimize the images (while not modifying the other static resources).

Ideally, I would also have access to statistics for each Pull Zone (since I would like to charge my clients for this service instead of guessing).

What are the different ways to do this with the Google Cloud? Is there a way to do this only using Google Functions, CDN, and Google Storage? Of course, I guess that having a little NodeJS app running to optimize the images would be needed as well. I just wonder about the general architecture and if it is even possible (I know it is with Azure and AWS but I am already running a few things on the Google Cloud).

Thanks a lot :)

Driftage answered 6/12, 2018 at 7:32 Comment(0)
T
2

In GCP a pull zone can be created by associating a HTTP(S) Load Balancer to a Cloud Storage Bucket and enabling Cloud CDN.

Having a different bucket for every client will break down the logs on your project, but not the billing for it.

To be able to separate billing you can always export the logs to a BigQuery and use it to break down the billing costs per client based on their use.


Regarding the optimization of the images, Google CDN will not perform any operation, neither GCS Bucket.

The only operation available in this direction is when using and serving GZip-compressed files.

I suggest you to dedicate one Instance to be able to prepare the images before storing or to add/replace the optimized versions of the images already inside the bucket.

Trifolium answered 7/12, 2018 at 16:47 Comment(9)
Thanks for your reply. But then, it would be the same as using MaxCDN or any other CDN service. How could I optimize the images, as well, in this flow?Driftage
The content can be server in gzip format even from the Cloud CDN, please check Transcoding of gzip-compressed files. The behavior of Cloud CDN is similar to all large cache providers, but I would read concepts page for a better understanding.Trifolium
Actually, I was thinking of a bit more of just gzipping. I am thinking of really optimizing those images, downsizing them and running them through an optimizer (npmjs.com/package/sharp). That's why I ask the question actually because I do not know how to integrate this process. Without it, it is much easier of course :)Driftage
Unfortunately, not. This setup is designed to serve the content, any action to prepare the files should be done prior to adding to the bucket. Also, modifying the files when already in the bucket will incur in operation charges.Trifolium
By unfortunately not, you mean that it is not possible? I don't mind the operation charges, I just would like to know the best way to do it, at least architecturally speaking.Driftage
The bucket is literally just for storage purposes, you can optimize the images before or after adding to it. The only difference is if you optimize before storing, there is no extra cost for modifying the files. In any case you need an Instance that can process the images before adding to the bucket.Trifolium
Thanks. But what I would like to do, is to make a CDN that optimizes the image automatically, when the CDN is hit, it should return the optimized image. It goes back to my original question basically :)Driftage
Editing my answer accordinglyTrifolium
Thanks, that's indeed helpful :) Not the solution I was hoping for, but it might be a bit simpler and might also cost less. Your solution brings, however, another issue, it's about the HTTP headers used for caching. How would you recommend doing it? On the first request, the image will be downloaded from the source and shared directly; however, later it will be optimized and that image should be used instead (so we should avoid that proxies/devices use the image that was not optimized). Any idea about this?Driftage

© 2022 - 2024 — McMap. All rights reserved.