GitHub工程复盘:通过参考级序列化与存算分离突破Agent时代Git扩展瓶颈
The bridge to agent-scale Git infrastructure
GitHub官方深度工程复盘,详细拆解了在高并发场景下通过引用级序列化和存算分离解决性能瓶颈的具体做法,参数与取舍清晰,对做大规模分布式系统的开发者极具参考价值。
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.
在过去的一年中,随着 Git 流量的指数级增长,GitHub 上 99.99999% 的 Git 存储库开始同时存在于两个地方:我们自己的数据中心和 Azure。其余的存储库是平台上流量最繁忙的一部分,而它们一直受到单一因素的制约:25ms 的往返延迟。
In an earlier blog post, we laid out the two principles behind our next-generation storage architecture:
在上一篇博客文章中,我们阐述了下一代存储架构背后的两大原则:
- Minimize coordination
- Decouple storage from compute
- 最小化协调
- 将存储与计算解耦
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.
在本文中,我们将探讨连接旧设计与新设计的即时桥梁。我们将讨论对法定人数序列化写入方式的更改如何将最繁忙的存储库迁移至 Azure,以及这一步骤如何为无需维护自身持久状态的副本打开大门。
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.
迁移的时机和形态由代理(agentic)转变所驱动:流量迅速增长、我们数据中心及其周边地理区域的电力容量达到硬性上限,以及物理供应链的限制。在迁移初期,所有可能扩展方案下的剩余容量为我们提供了足够的时间进行安全迁移,但不足以让我们缓慢推进。
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 的原型设计了新的架构方法,但在如此巨大的增长压力下,同时更改存储架构和托管平台会带来过高的风险。鉴于我们的规模以及该服务对社区的重要性,我们需要仔细安排工作顺序:先迁移数据,待数据到位后再演进架构。
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.
Git 操作属于 Tier 0 级服务:它是 GitHub 的核心功能,GitHub 中的几乎所有内容都依赖于存储库数据。这意味着数据、服务以及每一个依赖项都必须首先迁移。第一个存储库副本于 2025 年 8 月落地到 Azure 的美国中部区域。如今,大多数存储库在 Azure 中拥有五个副本中的两个,Azure 承担了约一半的 Git 流量。在大部分时间里,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:
在迁移过程中,流量跟随数据移动。大多数仓库拥有五个副本,以平衡持久性、可用性和扩展性。为了最小化读取延迟,Spokes 使用优选路由将流量引导至与请求位于同一区域和可用区的副本。随着副本迁移到 Azure,能够从 Azure 服务的流量比例随着每个副本的到达而增加,直到最后一个副本抵达且旧区域完全停止接收请求。每个仓库都会经历此过程:
No repository left behind
没有遗留任何仓库
So, what about the remaining 0.00001% of repositories?
那么,剩下的 0.00001% 的仓库怎么办?
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.
在我们当前的架构中,托管在多个区域的仓库具有较低的写入吞吐量上限。Spokes 的法定人数(quorum)只需要多数派即可提交写入,但在继续之前,它会等待所有健康副本响应(直至超时),因此慢速副本会延迟每次写入,而不是落后于进度。在实践中,这意味着最慢的健康副本决定了每次写入的延迟,并且由于每次写入在提交前都会持有仓库范围的锁,它还设定了吞吐量上限。一旦某个副本存在于目标 Azure 区域,它距离我们的数据中心约 1,000 英里,使得每次网络往返大约需要 25ms,而一次写入需要多次往返。一个已经接近其吞吐量上限的仓库无法在每次串行写入中吸收这种延迟;它会在每次推送时进一步落后。
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.
这正是我们的第一原则——最小化协调——发挥作用的地方。具体针对这种情况:不要对不需要序列化的内容进行序列化。Git 的一致性要求适用于每个引用(reference)。一旦服务器接受了对某个引用的更新,此后没有任何客户端能看到旧值,只能看到该值或更新的值。无论更新是快进(fast-forward)、强制推送(force push)还是删除,这一原则都成立。但在大多数情况下,对不同引用的更新彼此不依赖,可以独立应用。
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:
在基于每个引用的序列化机制下,只有争用共享引用的写入操作才需要相互等待。在实际场景中,对存储库的大多数写入操作涉及不同的引用——例如,代理和开发人员向各自的分支推送代码——因此它们不再相互等待。每次写入仍会经历跨区域延迟,但针对不同引用的写入可以同时进行。这消除了存储库上的单一瓶颈。我们可以通过在相似负载下并排比较这两种方法,来可视化排队和超时是如何累积的:
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.
这些变更将存储库的写入吞吐量上限大致按同时写入的引用数量比例提升,并将最后剩余的存储库迁移至 Azure。在具有真实流量的内部测试中,针对不同引用的写入始终实现了低延迟下 3–4 倍的更高吞吐量。
Scaling reads on their own
独立扩展读取能力
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.
大多数存储库的读取操作占主导地位,每进行一次写入就有大约 100 到 1,000 次读取。目前,读取和写入操作命中相同的副本,因此它们竞争相同的资源,无法独立扩展。
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.
将存储与计算解耦改变了这一状况。一旦存储库数据持久化存储在 Azure Blob Storage 中,并在每次传入写入时得到更新,我们就可以开始将读取流量从写入法定人数中解耦,并独立扩展各自所需的计算资源。例如,读取操作将从比当前分配更多的内存缓存中受益,但这些内存也用于合并(compaction)。一旦它们被分离,每一项都将拥有自己的配置。
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.
第一步是让对象存储成为法定人数的一员,但作为一个特殊的成员,我们称之为虚拟副本(virtual replica)。代表它的计算节点是我们第一个完全临时的节点。它作为通往对象存储的桥梁,流式传输传入的写入操作,并不服务任何读取请求。由于它是法定人数的一员,直到写入在对象存储中确保持久后,才会确认该写入。
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.
这会给每次写入增加一点延迟,但就像跨区域往返一样,基于每个引用的序列化防止其成为吞吐量瓶颈。虚拟写入副本还将针对不相交引用的事务合并为对对象存储的一组网络 I/O 操作,因此一个繁忙的存储库只需为许多并发写入支付一次跨区域的往返费用,而不是每次写入都支付一次。目前,虚拟写入副本还负责合并(compaction),读取副本继承合并后的状态。
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.
有了虚拟写入副本,我们可以根据仓库的需求按需扩展任意数量的虚拟读取副本。每个读取副本从 Azure Blob Storage 预热其缓存,并在后台以对象存储为真相源(source of truth),将其本地状态与之进行协调,从而在不加入法定人数(quorum)的情况下开始承接读取流量。
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.
- 虚拟读取副本最初会在后台与对象存储进行协调,这使得它们适合某些读取工作负载,但并不适用于所有场景。要支持所有类型的读取操作,就需要将协调过程移至在线流程中,仅获取参考状态以及自副本上次同步以来发生变化的数据。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力