迈向智能体规模的 Git 基础设施
原题The bridge to agent-scale Git infrastructure
推荐理由平台工程团队可从跨机房迁移与写入协调案例,理解智能体流量增长为何要求存储计算解耦,以及架构升级如何分步推进。
读前速览
GitHub 正将 Git 基础设施迁移至 Azure,并通过按引用序列化和虚拟副本,将存储与计算解耦,使读写操作能够独立扩展,以支持智能体驱动的开发。
按引用序列化
GitHub 将仲裁范围从整个仓库缩小到单个引用,使不同分支上的写入能够并行进行,从而大幅提升写入吞吐量,并降低互不冲突的操作所产生的延迟。
解耦存储与计算
引入虚拟副本后,读流量与写入仲裁机制分离,因此可以根据需求独立扩展读取操作,而不会影响写入性能。
迁移至 Azure
迁移至 Azure 可提供应对流量增长所需的可扩展性和冗余能力。迁移策略重点是先迁移数据,再逐步演进底层架构。
完整摘要
文章详细介绍了 GitHub 将 Git 仓库迁移至 Azure 的过程。此次迁移源于流量呈指数级增长,以及物理容量受限。文章提出按引用序列化,以提升写入吞吐量;并引入虚拟副本,将读流量与写入仲裁机制解耦,从而实现存储和计算资源的独立扩展。
目录 · 4 节
过去一年,随着 Git 流量呈指数级增长,GitHub 上 99.99999% 的 Git 仓库开始同时存放在两个地方:我们自己的数据中心和 Azure。其余仓库是平台上最繁忙的一批,而唯一限制它们的因素,就是 25 毫秒的往返延迟。Over the past year, while Git traffic grew exponentially, 99.99999% of the Git repositories on GitHub began living in two places at once: our own data centers and Azure. The rest are among the busiest on the platform, and they’re held back by just one thing: a 25ms round trip.
在此前的一篇博客文章中,我们阐述了支撑我们下一代存储架构的两项原则:In an earlier blog post, we laid out the two principles behind our next-generation storage architecture:
- 尽量减少协调工作Minimize coordination
- 将存储与计算解耦Decouple storage from compute
在这篇文章中,我们将看看旧设计与新设计之间的直接过渡。我们会讨论,如何通过改变仲裁组序列化写入的方式,让最繁忙的代码仓库也能迁移到 Azure,以及这同一步骤如何为不保留任何自身持久状态的副本铺平道路。In this post, we’ll look at the immediate bridge between our old design and our new one. We’ll talk about how a change to the way our quorum serializes writes gets the busiest repositories into Azure, and how that same step opens the door to replicas that keep no persistent state of their own.
我们是如何走到这一步的How we got here
此次迁移的时机和方式由智能体化转型所推动:流量迅速增长,我们数据中心及其所在地区的电力容量已达到上限,且实体供应链也受到限制。迁移开始时,所有可能的扩建方案所能提供的剩余容量,足以让我们安全地完成迁移,却不足以让我们慢慢来。The timing and shape of the move were driven by the agentic shift: rapidly growing traffic, a hard ceiling on the power capacity of our data centers and the surrounding geographical region, and physical supply chain constraints. At the beginning of our migration, the remaining capacity with all possible expansion gave us enough time to migrate safely, but not enough to do it slowly.
尽管我们已经针对如何在云基础设施上扩展 Git,试验过新的架构方案,但在业务增长的背景下,同时改变存储架构和托管平台,风险过高。考虑到我们的规模,以及这项服务对社区的重要性,我们需要谨慎安排工作的先后顺序:先迁移数据,等数据到位后再演进架构。While we had prototyped new architectural approaches for scaling Git on cloud infrastructure, changing the storage architecture and the hosting platform at the same time, under that growth, carried too much risk. Given our scale and how critical the service is to the community, we needed to sequence the work carefully: move the data first, then evolve the architecture once it arrived.
Git 操作是 Tier 0 服务:它们是 GitHub 的核心功能,而 GitHub 几乎所有功能都依赖仓库数据。这意味着数据、服务和所有依赖项都必须率先迁移。2025 年 8 月,第一个仓库副本落地于 Azure 的美国中部区域。如今,大多数仓库的五个副本中有两个位于 Azure,Azure 承载着约一半的 Git 流量。在这段时间的大部分时期里,Azure 吸纳了我们的业务增长,而我们自己的数据中心则保持稳定。Git operations are a Tier 0 service: they’re a core function of GitHub, and nearly everything in GitHub depends on the repository data. That meant the data, services, and every dependency had to move first. The first copy of a repository landed in Azure’s Central US region in August 2025. Today, most repositories have two of their five replicas in Azure, and Azure serves about half of Git traffic. For most of that time, Azure absorbed our growth while our own data centers held steady.
在迁移过程中,流量会跟随数据移动。大多数存储库都有五个副本,以平衡持久性、可用性和扩展能力。为最大限度地降低读取延迟,Spokes 采用优先路由,将流量导向与请求位于同一区域和可用性区域的副本。随着副本迁移到 Azure,可由 Azure 处理的流量占比逐步增加,直到最后一个副本迁入,此时旧区域将不再收到任何请求。每个存储库都会经历以下过程:During the migration, traffic follows the data. Most repositories have five replicas to balance durability, availability, and scale. To minimize read latency, Spokes uses preferential routing to direct traffic to a replica in the same region and availability zone as the request. As replicas move to Azure, the share of the traffic that can be served from Azure grows with each one, until the last replica arrives and the old region stops receiving requests entirely. Every repository goes through this process:
不让任何仓库掉队No repository left behind
那么,剩下的 0.00001% 的代码仓库呢?So, what about the remaining 0.00001% of repositories?
在我们当前的架构中,托管在多个区域的仓库,其写入吞吐量上限会更低。Spokes 的法定人数机制只需获得多数副本的响应即可提交写入,但它会等到所有健康副本都作出响应(最长等待至超时)后才继续,因此,响应缓慢的副本会拖慢每一次写入,而不是单纯地落后于其他副本。实际上,这意味着每次写入的延迟都由响应最慢的健康副本决定;由于每次写入在提交前都会持有整个仓库范围的锁,它也就决定了吞吐量上限。一旦某个副本位于目标 Azure 区域,它与我们的数据中心相距约 1,000 英里,每次网络往返大约需要 25 毫秒,而一次写入需要多次往返。已经接近吞吐量上限的仓库无法在每次串行写入时承受这样的开销;每次推送都会使它进一步落后。In our current architecture, a repository hosted in more than one region has a lower write throughput ceiling. Spokes’ quorum only needs a majority to commit a write, but it waits for every healthy replica to respond (up to a timeout) before moving on, so slow replicas delay every write rather than falling behind. In practice, that means the slowest healthy replica sets the latency of every write, and because each write holds a repository-wide lock until it commits, it also sets the throughput ceiling. Once a replica lives in the target Azure region, it’s about 1,000 miles from our data centers, making each network round trip around 25ms, and a write requires multiple round trips. A repository already near its throughput ceiling can’t absorb that on every serialized write; it would fall further behind with every push.
这正是我们的第一条原则——尽量减少协调——发挥作用的地方。具体到这个场景:不必串行处理的内容,就不要串行处理。Git 的一致性要求分别适用于每个引用。服务器一旦接受对某个引用的更新,此后任何客户端都不应再看到较旧的值,只能看到该值或更新的值。无论这次更新是快进、强制推送还是删除,这一点都成立。但在大多数情况下,不同引用的更新彼此并不依赖,因此可以独立应用。This is where our first principle, minimizing coordination, comes into play. Specifically for this case: don’t serialize what doesn’t need to be. Git’s consistency requirements apply to each reference individually. Once the server accepts an update to a reference, no client should see an older value afterward, only that value or a newer one. That holds whether the update is a fast-forward, a force push, or a delete. But in most cases, updates to different references don’t depend on each other and can be applied independently.
因此,我们将法定人数的范围从整个代码仓库调整为单个引用。So, we’re changing the scope of the quorum from the whole repository to individual references.
在整个引用更新期间(包括往返通信)持有仓库级锁,会使仲裁组变成一个单一的无序请求队列,并且同一时间只能有一次写入在处理中。队列中的每次写入耗时都取决于响应最慢的健康副本。随着写入速率提高,队列也会变长,每次写入的等待时间都比前一次更长。Holding a repository-wide lock for the entire reference update, round trips included, turns the quorum into a single, unordered request queue with one write in flight at a time. Each write in that queue takes as long as the slowest healthy replica. As the write rate grows, so does the queue, and each write waits longer than the one before it.
采用按引用分别序列化后,只有争用同一引用的写入才需要相互等待。实际上,写入仓库的大多数操作会涉及不同的引用——例如,代理和开发者分别推送到自己的分支——因此它们不再需要相互等待。每次写入仍会受到跨区域延迟的影响,但针对不同引用的写入可以同时进行。这样就消除了仓库中的单一瓶颈。我们可以在类似负载下并排比较这两种方式,直观地了解排队和超时是如何累积的:With per-reference serialization, only writes that contend on a shared reference must wait for each other. In practice, most writes to a repository touch different references—for example, agents and developers pushing to their own branches—so they no longer wait on each other. Each write still experiences the cross-region latency but writes to different references can be in flight at the same time. That removes the single bottleneck on the repository. We can visualize how queueing and timeouts build up by comparing the two approaches side by side under similar load:
这些更改可使仓库的写入吞吐量上限大致随着同时写入的引用数量成比例提升,并将最后剩余的仓库迁移到 Azure。在采用真实流量的内部测试中,对不同引用的写入吞吐量始终提升了 3–4 倍,同时延迟更低。These changes raise a repository’s write throughput ceiling roughly in proportion to how many references are being written at once, and get the last remaining repositories into Azure. In internal testing with realistic traffic, writes to different references consistently saw 3–4x higher throughput at lower latency.
单独扩展读取能力Scaling reads on their own
大多数仓库的读操作远多于写操作,每次写入对应约 100 到 1,000 次读取。目前,读写请求都由相同的副本处理,因此会争用相同的资源,且无法独立扩展。Most repositories are heavily read-skewed, with somewhere between 100 and 1,000 reads for every write. Today, reads and writes hit the same replicas, so they compete for the same resources and can’t be scaled independently.
将存储与计算解耦后,情况就会改变。一旦仓库数据被持久化存储在 Azure Blob Storage 中,并随每次传入写入而更新,我们就可以开始将读取流量与写入仲裁分离,并分别扩展各自所需的计算资源。例如,读取操作从更多内存缓存中获益,而我们目前分配给它们的缓存远远不够;但这些内存也需要用于压缩。将两者分离后,就可以分别配置。Decoupling storage from compute changes that. Once repository data is durably stored in Azure Blob Storage and updated with each incoming write, we can begin to decouple read traffic from the write quorum, and independently scale the compute needed for each. For example, reads would benefit from far more in-memory cache than we give them today, but that memory is also needed for compaction. Once they’re separated, each gets its own configuration.
第一步是让对象存储成为仲裁组的一员,不过它是一个特殊成员,我们称之为虚拟副本。代表它的计算节点是我们的第一个完全临时节点。它充当通往对象存储的桥梁,将传入的写入流式传送到对象存储,并且不处理任何读取请求。由于它是仲裁组的成员,只有当写入数据已持久化到对象存储后,写操作才会得到确认。The first step is making object storage a member of the quorum, but a special one that we call a virtual replica. The compute that represents it is our first fully ephemeral node. It serves as a bridge to object storage, streaming incoming writes and serving no reads. Because it’s a member of the quorum, a write isn’t acknowledged until it’s durable in object storage.
这会给每次写入增加少许延迟,但与跨区域往返一样,按引用串行化可避免它成为吞吐量瓶颈。虚拟写入副本还会将针对互不相交引用的事务合并为一组发往对象存储的网络 I/O,因此繁忙的存储库可以让多次并发写入共用一次往返,而不是每次写入都各自往返一次。目前,虚拟写入副本也负责压实,而读副本会继承压实后的状态。That adds a little latency to each write, but just like the cross-region round trip, per-reference serialization keeps it from becoming a throughput bottleneck. The virtual write replica also coalesces transactions on disjoint references into a single set of network I/Os to object storage, so a busy repository pays for one round trip across many concurrent writes instead of one per write. For now, the virtual write replica also handles compaction, and read replicas inherit the compacted state.
有了虚拟写副本后,我们就可以按需扩展任意数量的虚拟读副本,以满足仓库的需求。每个读副本都会从 Azure Blob Storage 预热缓存,并在不加入仲裁组的情况下开始处理读流量;它以对象存储为事实来源,并在后台将本地状态与之协调一致。With the virtual write replica in place, we can scale out as many virtual read replicas as a repository needs, on demand. Each read replica warms its cache from Azure Blob Storage and starts taking read traffic without joining the quorum, using object storage as the source of truth and reconciling its local state against it in the background.
此步骤显著提升了读取扩展能力。在内部测试中,我们的分布式负载测试工具经常触及当前架构的性能上限。面对虚拟只读副本时,测试工具本身反而先达到了极限。此外,它也带来了一些挑战,我们将在后续步骤中解决:This step unlocks significant read scale. In internal testing, our distributed load testing harness routinely found ceilings in the current architecture. Against virtual read replicas, the harness hit its own limits first. It also comes with a few challenges that are solved in subsequent steps:
- 虚拟只读副本最初会在后台与对象存储进行协调,因此适合某些读取工作负载,但并非所有工作负载。要支持各种类型的读取,需要将这种协调移至请求处理流程中,只获取引用状态以及自该副本上次同步完成以来发生变化的数据。Virtual read replicas start out reconciling with object storage in the background, which makes them a good fit for some read workloads but not all of them. Serving every kind of read requires moving that reconciliation in-line, fetching only the reference state and data that changed since the replica last caught up.
- 虽然我们通过转向按引用进行的模型逐步提高了写入吞吐量,但法定人数仍是进一步提升的限制因素。While we’ve incrementally increased write throughput by shifting to a per-reference model, the quorum remains the bounding factor for increasing further.
我们如何进一步提升写入吞吐量?How can we push write throughput further?
接下来是什么What comes next
如今的 GitHub 建立在 Spokes 仲裁集群之上。多年来,Spokes 的功能早已远不止仲裁协调器:它还是一个智能路由与负载均衡层、一个供内部客户端使用的统一 API,使其每天能够对仓库数据执行超过 1000 亿次操作;此外,它还包含一系列后台系统,我们称之为“清扫器”,负责在存储节点之间进行仓库放置、修复和重新均衡。The GitHub of today was built on the Spokes quorum, and over the years Spokes has become much more than a quorum coordinator. It’s also an intelligent routing and load balancing layer, a unified API that internal clients use to access and transact repository data at well over 100 billion operations per day, and a collection of background systems we call “sweepers” that handle repository placement, repair, and rebalancing between storage nodes.
Spokes 服务体系涵盖的绝大多数内容,同样适用于新架构和现有架构。不过我们也意识到,助力 GitHub 达到十亿个仓库的提交协议,无法带领它迈向下一个十亿乃至更远。The vast majority of what lives under the Spokes service umbrella applies just as well to the new architecture as it does to the existing one. But we also recognize that the commit protocol that has taken GitHub to a billion repositories won’t take it to the next billion and beyond.
我们还没完成。有了这些步骤,接下来的瓶颈就是写入吞吐量。每次写入仍然要等待那些各自保存着完整仓库副本的副本节点,但实际上,写入中只有很少一部分需要排序。Git 对象不可变,并且以其内容命名,因此无需任何人就它们达成一致,也可以直接存储。剩下的部分很小,难点在于尽可能快地对其排序,同时不把瓶颈转移到别处。在白板上为此设计方案是一回事;让它在开发者和代理全天候写入的十亿个仓库之下运行,则是另一回事。要实现这一点,我们还必须重新思考二阶影响,例如持久化引用状态应存放在哪里,以及如何扩展压缩和垃圾回收的能力。We’re not done yet. With these steps in place, the next limit is write throughput. Every write still waits on replicas that each hold a full copy of the repository, yet very little of a write actually needs to be ordered. Git objects are immutable and named by their contents, so they can be stored without anyone agreeing on them. What’s left is small, and the hard part is ordering it as fast as possible without moving the bottleneck somewhere else. Designing for that on a whiteboard is one thing. Doing it underneath a billion repositories that developers and agents are writing to around the clock is another. Getting there forced us to rethink the second-order effects too, like where durable reference state lives and how compaction and garbage collection scale.
智能体流量并未放缓,而这些步骤每落地一步,都会为代码仓库提供更多余量,无需等到最终形态。Agent traffic isn’t slowing down, and each of these steps gives repositories more headroom as it lands, without waiting for the end state.
下周推出:在 GitHub Universe 大会上,以及本系列的最后一篇文章中,我们将带你了解这一最终状态、它对写入吞吐量的提升、为实现这一目标必须解决的次生问题,以及为什么整个技术栈中仍有一个(小型)共识组。Coming next week: At GitHub Universe and in the final post in this series, we’ll take a tour through that end state, what it does for write throughput, the second-order problems we had to solve to get there, and why there’s still a (small) consensus group somewhere in the stack.
感谢 Brian Celenza 对本文的贡献。Thanks to Brian Celenza for their contributions to this post.