2026-08-15
每日一文 · 长文精读

Cloudflare Migrates JavaScript CDN Serving 9B Requests a Day to Its Developer Platform

Cloudflare 将每日处理 90 亿次请求的 JavaScript CDN 迁移至其开发者平台

作者:Leela Kumili · InfoQ 原文

摘要:Cloudflare 将其开源 JavaScript/CSS CDN 服务 cdnjs 完全迁移至自家开发者平台,用 Workers、R2、Workflows 等组件替换了原先分散在 Cloudflare 和 Google Cloud Platform 上的基础设施。迁移使 R2 成为包文件的权威数据源,同时保留原有 URL 和 SRI 哈希。cdnjs 现日均处理约 90 亿次请求,缓存命中率 98.6%,被约 12% 的网站使用。此次迁移是 Cloudflare 大规模自用开发者平台的实例。

Cloudflare has migrated cdnjs, its open source CDN for JavaScript and CSS libraries, entirely to its Developer Platform, replacing publishing infrastructure spread across Cloudflare and Google Cloud Platform with Workers, R2, Workflows, Queues, Durable Objects, KV, and Containers.
Cloudflare 已将其开源 JavaScript 和 CSS 库 CDN 服务 cdnjs 完全迁移至自家开发者平台,用 Workers、R2、Workflows、Queues、Durable Objects、KV 和 Containers 替换了原先分散在 Cloudflare 和 Google Cloud Platform 上的发布基础设施。
The migration also moved R2 into the role of source of truth for published package files while preserving existing URLs, package contents, and Subresource Integrity (SRI) hashes.
迁移还将 R2 定位为已发布包文件的权威数据源,同时保留了现有 URL、包内容及子资源完整性(SRI)哈希。
Cloudflare said cdnjs now serves approximately 9 billion requests per day, averaging 108,000 requests per second across more than 330 Cloudflare data centers.
Cloudflare 表示,cdnjs 现在每天处理约 90 亿次请求,在 330 多个 Cloudflare 数据中心中平均每秒处理 108,000 次请求。
The service reports a 98.6% cache hit rate and is used by approximately 12% of websites.
该服务的缓存命中率为 98.6%,大约 12% 的网站使用它。
Cloudflare described the migration as an example of dogfooding its Developer Platform at the scale of a widely used public service.
Cloudflare 将此次迁移描述为在其开发者平台上自用(dogfooding)的一个实例,规模达到广泛使用的公共服务级别。
The migration builds on a 2020 architectural change in which Cloudflare moved cdnjs file serving to Workers and Workers KV, replacing dedicated origin machines for normal traffic while retaining an external origin as a fallback.
此次迁移建立在 2020 年的架构变更之上,当时 Cloudflare 将 cdnjs 文件服务移至 Workers 和 Workers KV,用它们替代专用源服务器处理正常流量,同时保留外部源作为备用。
Cloudflare also introduced precompressed Brotli and gzip assets to improve delivery efficiency.
Cloudflare 还引入了预压缩的 Brotli 和 gzip 资源,以提升传输效率。
The publishing path, however, remained distributed.
然而,发布路径当时仍然是分布式的。
Google Cloud Functions periodically checked npm for package releases, Google Cloud Storage held packages, Pub/Sub handled messaging, and a virtual machine running git-sync synchronized repository content.
Google Cloud Functions 定期检查 npm 上的包新版本,Google Cloud Storage 存储包,Pub/Sub 处理消息传递,一台运行 git-sync 的虚拟机同步仓库内容。
The system used 26 Cloud Functions divided into alphabetic shards to monitor package updates.
该系统使用了 26 个 Cloud Functions,按字母分片来监控包更新。
At the same time, the GitHub repository had grown beyond 1.1 TB of packed storage, while published files were represented in both GitHub and KV.
与此同时,GitHub 仓库的打包存储量已超过 1.1 TB,而已发布文件同时存在于 GitHub 和 KV 中。
Previous cdnjs publishing and serving architecture (Source: Cloudflare Blog Post)
先前的 cdnjs 发布和服务架构(来源:Cloudflare 博客文章)
The new architecture makes Cloudflare R2 the source of truth for published files.
新架构让 Cloudflare R2 成为已发布文件的权威数据源。
KV stores package metadata, versions, and SRI hashes, while a Worker handles requests and Workers Cache provides the caching layer.
KV 存储包元数据、版本和 SRI 哈希,Worker 处理请求,Workers Cache 提供缓存层。
Published content is additionally mirrored to DigitalOcean Spaces as a fallback if R2 cannot serve a file.
已发布内容还会额外镜像到 DigitalOcean Spaces,作为 R2 无法提供文件时的备用方案。
Package ingestion is now orchestrated through Cloudflare Workflows.
包的接收现在通过 Cloudflare Workflows 进行编排。
A scheduled workflow checks npm and GitHub for releases, downloads packages into R2, and launches processing workflows for individual files.
一个定时工作流会检查 npm 和 GitHub 上的新版本,将包下载到 R2,并为每个文件启动处理工作流。
The processing pipeline extracts package contents, minifies and compresses assets, stores the resulting files in R2, updates metadata in KV, and refreshes the Algolia search index.
处理管线会提取包内容、压缩资源、将结果文件存储到 R2、更新 KV 中的元数据,并刷新 Algolia 搜索索引。
Workflow state allows processing to resume from the last completed step after a failure.
工作流状态允许在失败后从最后一个完成的步骤恢复处理。
New cdnjs architecture using R2, Workers, KV, and Workflows. (Source: Cloudflare Blog Post)
使用 R2、Workers、KV 和 Workflows 的新 cdnjs 架构。(来源:Cloudflare 博客文章)
Compression presented a constraint because the existing processing algorithms require an entire library to be buffered in memory.
压缩带来一个限制,因为现有处理算法需要将整个库缓冲在内存中。
Cloudflare therefore uses Containers for compression rather than running the processing directly in Workers.
因此,Cloudflare 使用 Containers 进行压缩,而不是直接在 Workers 中运行处理。
Cloudflare said it is exploring streaming support that could eventually allow this processing to move to Workers.
Cloudflare 表示正在探索流式处理支持,最终可能使该处理迁移到 Workers 上。
Preserving package bytes was critical because changes to minification or compression could alter SRI hashes.
保持包的字节精确性至关重要,因为对压缩方式的更改可能会改变 SRI 哈希。
The migration also exposed platform limits, prompting Cloudflare to raise Worker subrequests from 1,000 to 10 million and Workflow steps from 1,024 to 10,000, with up to 25,000 configurable.
迁移还暴露了平台限制,促使 Cloudflare 将 Worker 子请求数从 1000 提高到 1000 万,将 Workflow 步骤数从 1024 提高到 10000,最高可配置至 25000。
The resulting architecture uses R2 for artifacts, KV for metadata, Workers for delivery, and Workflows for publishing.
最终架构使用 R2 存储工件,KV 存储元数据,Workers 进行交付,Workflows 负责发布。

阅读理解

1. What was the primary role of Cloudflare R2 after the migration of cdnjs?

2. Why did Cloudflare use Containers for compression instead of Workers?

3. What change did Cloudflare make to platform limits as a result of the migration?

温故复习 →每日一句 →