Reviewing My nginx and Cloudflare Settings Cut Cloud Run Data Transfer Costs by 96%

How Optimizing Nginx and Cloudflare Configuration Reduced Cloud Run Data Transfer Costs by 96%

How Optimizing Nginx and Cloudflare Configuration Reduced Cloud Run Data Transfer Costs by 96%

The author of a personal blog hosted on Google Cloud Run discovered significant cost savings by reviewing and optimizing their nginx and Cloudflare configurations. Previously, their monthly Google Cloud bill had exceeded ¥1,000 for about a year, but after implementing two key changes, it dropped to ¥72 in October. The primary issue was that nginx gzip compression was disabled, causing Cloud Run to send uncompressed data to Cloudflare, which was then billed as data transfer. By enabling gzip compression, the size of the index.xml feed (which accounted for over 90% of data transfer) was reduced from 5.4 MB to 1.27 MB. Additionally, the author configured Cloudflare to cache HTML content and the index.xml feed, which reduced the number of requests to Cloud Run. Before the changes, Cloud Run data transfer costs were ¥556 in September, but after optimization, they dropped to ¥24 in October, representing a 96% reduction. The author also implemented a cleanup policy for Artifact Registry storage, which contributed to the overall cost reduction. The blog post details the technical steps taken, including modifying nginx configuration, setting cache rules in Cloudflare, and using Terraform for management. The author emphasizes that these changes were simple once identified, and encourages others using Cloud Run to review their request logs to identify potential cost-saving opportunities. The total monthly savings amounted to ¥953, with ¥532 coming from data transfer optimization and ¥401 from Artifact Registry cleanup. The author notes that Cloudflare’s CDN is on the Free plan, so it remains cost-free. The post concludes with a historical reference to a similar data transfer issue faced by 2channel in 2001, highlighting the enduring relevance of optimizing data transfer efficiency.

Leave a Reply

Your email address will not be published. Required fields are marked *