The Attachment Pipeline

The brief covers why I built the attachment pipeline at GitHub, the designs I weighed, and how the work went. This page shows how it works, with diagrams you can play with.

A security config is a bundle of security feature settings, like Dependabot alerts and secret scanning. Putting a config on a repo is called attaching it. Press Attach:

That's quick. But big enterprises have tens of thousands of repos. At about a second each, 30,000 repos would take more than 8 hours one at a time. So GitHub does the work in the background, many repos at once.

The old way

To attach a config to every repo in an org, a fan-out job enqueued one attachment job per repo, all at once. Enterprises got the same ability by stretching the fan-out: enterprise → orgs → repos. Below, each repo's attachment job is drawn as a ticket.

For the typical org, this simple design worked fine. For the long tail of large customers, it had two problems.

Problem 1: Nothing throttled the fan-out

Every customer shared one queue and one pool of workers. A big enough request filled the queue, and everyone behind it waited:

Large Inc attaches a config to 30,000 repos. A moment later, Small LLC attaches one to 20, and its 20 wait behind all of Large Inc's. Drag the slider: the bigger Large Inc's request, the longer Small LLC waits. The same flood spiked database replication lag and load on downstream consumers.

Problem 2: Nothing kept changes in order

Picture a painting company. You order every house on your street painted teal, then order three of them painted purple. If painters work on both orders at once, a house might get purple first and teal second, and end up the wrong color. Configs work the same way: whichever ticket finishes last wins. Here's what happens when nothing keeps them in order:

To prevent that race, the old system used a lock. While a bulk request ran, every other request in that org, and in every other org in the same enterprise, was turned away. Try it:

Admins got Another enablement event is in progress. Please try again later. Nothing warned them until they tried, and nothing told them when to try again. And some changes, like new repos and repo transfers, never went through the lock, so races still happened.

Four goals

I set four goals for the new design:

  1. Bulk attachment work must not spike load on shared infrastructure.
  2. Admins must not be blocked from requesting bulk attachment.
  3. Attachment work must be processed in request order.
  4. One customer's bulk attachment work must not delay the start of another customer's.

The brief compares the designs I weighed against these goals. Only one met all four: a planner that meters work onto an event stream. That's the attachment pipeline.

A queue instead of a lock

The pipeline swaps the lock for a queue. Every request is accepted right away and waits its turn as a single record. Then it's worked through a few minutes at a time, so no one customer can swamp the system. Four parts do the work:

Step through one request:

Each step saves its progress in the database, so if any part crashes, the next one picks up where it left off. Here's the same enterprise as before, on the pipeline:

No one is blocked. Requests in the same org wait their turn and run in order. Requests in different orgs run side by side.

The planner

The planner runs every minute, and right away when a new request comes in. It hands out work in limited amounts: each customer can have up to 5,000 repos in progress, and everyone together up to 20,000. A customer is the enterprise, or the org if it isn't in one.

Think of each customer's limit as a glass filled to a line. Consumers drain it as they finish repos, and every minute the planner tops it back up:

Why 5,000? It's about five minutes of work for a customer's consumers: enough to keep them busy until the planner's next run, but not enough to build a long queue. And if everyone together reaches 20,000, no one gets topped up until work finishes. That global cap is what keeps bulk work from spiking shared infrastructure.

The planner also runs each org's requests one at a time, in the order they came in. A request starts only after the one before it has completely finished.

The stager

The stager goes through the request's repos a page at a time, writing a ticket for each, until it uses up the planner's budget. After each page, it moves a bookmark, so the next stager knows where to start. Try crashing one:

Because the bookmark only moves after a whole page, a crash means the next stager redoes that page, so a few tickets get sent twice. That's fine: when a consumer gets a ticket that's already done, it skips it.

Partitions

Tickets don't go into one big queue. They go onto a Kafka topic with 64 partitions. Each partition has one consumer, which handles its tickets one at a time, first come, first served.

Each customer only gets 16 of the 64 partitions, picked by shuffling the partitions with the customer's ID, so it's always the same 16. This is shuffle sharding. Two customers' partitions overlap a little, so busy customers share a few consumers, but never all of them. Here's the same rush as before, scaled down to 16 partitions with 4 per customer:

Most of Small LLC's repos land in partitions Large Inc isn't using, and finish in seconds. A few share a partition with Large Inc and wait, but only about 5 minutes, because the planner never lets Large Inc queue more than about five minutes of work.

Partitions also fix the race. Every ticket for a repo goes to the same partition, so one consumer handles them in the order they were requested:

The consumers

A consumer takes one ticket at a time. First it checks that the ticket is still waiting and marks it as working. If it isn't waiting, say because it's already done, the consumer skips it. That's why a ticket sent twice is harmless. Then it attaches the config and marks the ticket done, failed, or skipped. If something flaky fails, like a call to another service, it tries again, up to 5 times.

What a consumer does with a repo depends on the request's strategy and the config the repo already has. Back to painting: Attach only paints bare houses. Reapply only touches up houses that are already this color. Override paints every house. Pick one:

When things break

Every minute, the planner also sweeps for work that's stuck:

When all of a request's tickets are finished, the planner marks the request complete, and the progress bar in the UI reaches 100%.

Milestones

I ordered the work so each milestone shipped visible, valuable progress. Here's where things stood when I handed off the rollout in November 2026:

  1. M1 Foundational refactor Done One shared way to attach a config, tickets saved in the database, and config versions.
  2. M2 Streaming attacher Done New repos, unarchived repos, and repos that change visibility get their configs through partitions and consumers.
  3. M3 Throttled bulk attachment Mostly done Applying a config across an org goes through the planner, stager, and consumers.
  4. M4 Durable detachment Handed off Removing configs moves to the pipeline too.
  5. M5 Enterprise fan-out Handed off Enterprise-wide requests split into one request per org.
  6. M6 Reliability hardening Handed off Recovery, cleanup, controls for on-call, and SLOs.

Until M4 and M5 ship, detaching configs still uses the old path, and enterprise-wide requests still reach each org through an old job. Once all of that runs on the pipeline, the lock goes away for good.