What to do when two teams own the same code path

Two teams making changes to the same code path is a common situation and a destructive one. The failure mode is usually invisible until it has done months of damage: the code accumulates inconsistent patterns, the test suite covers each team's cases but not the interaction, and the architecture that one team thinks the code has is different from the architecture the other team thinks it has.
The underlying problem is not that two teams share code. Teams need to share code. The problem is that shared ownership, treated as a collaborative state, is actually the absence of a decision. Nobody is accountable for the whole, so no part of the whole gets the attention it needs.
The three ways shared code decays
Shared code decays along three axes at once. Each is manageable alone and devastating together.
Design drift. Each team makes changes that make sense locally. Team A adds a feature by extending a class. Team B adds a different feature by introducing a parallel helper function that duplicates part of what the class does but handles it differently. Over six months, the file has three different patterns for doing roughly the same thing, because three different engineers chose them at different times with no overall design in mind.
Review gaps. A pull request from team A gets reviewed by team A. The reviewer sees the change in the context of team A's work, not team B's. A subtle assumption gets through that breaks something team B relies on, and the breakage shows up two weeks later when team B's next deploy fails for a reason that was never discussed.
Quality decay. Nobody owns the health of the file as a whole. Team A thinks team B should refactor the file; team B thinks the same of team A. Technical debt accumulates because fixing it is not clearly anyone's job. By the time someone takes an interest, the debt is large enough that the fix becomes a project.
Each of these happens slowly. The team is usually not aware of the compounding until a specific incident forces them to look at the file and discover what it has become.
Pattern one: one owner, one contributor
The first pattern for resolving shared ownership is to pick one team as the owner and make the other team a contributor. The owner team is responsible for the code's design, sets the standards, and reviews every change. The other team contributes through pull requests that go through the owner's review.
This works when one team has a stronger claim to the code than the other. That claim can be about historical work, about which team's work the code more centrally supports, about which team has more engineers who know the code well, or about which team is better organised to own additional responsibility.
The decision needs to be clear. "Mostly team A owns it" or "it is primarily team A's area" is not the same as team A owning it. The second team needs to know that they contribute through team A's review, and team A needs to accept that they review every change.
The pattern fails when the ownership assignment is contested. If team B thinks they should own the code and team A does not fully accept the responsibility, the shared ownership comes back in disguise: team B pushes changes with minimal review from team A, team A does not catch them because they do not feel accountable, and the drift resumes under a thin veneer of ownership.
For this pattern to work, the ownership decision needs to be made explicitly, written down, and honoured by both teams even when it is inconvenient.
Pattern two: split along the hidden boundary
The second pattern is to split the shared code into two separate pieces, one owned by each team. The split works when the shared code is actually serving two different purposes that have been combined, often because they were small enough to combine when the code was first written and never separated as they grew.
The split surfaces the boundary that was always there. Each team owns a piece that is clearly theirs. The two pieces communicate through an interface that is explicitly designed, usually a small number of well-named functions or a narrow data contract.
The payoff is that each team's area is clean and the interaction between them is in one visible place that both teams review together. The failure mode is a bad split: a split that does not line up with the actual separation of concerns just moves the shared ownership problem from inside a file to the interface between two files, and the interface becomes the new place where drift and review gaps happen.
Signs that a split would work: the code has two kinds of changes being made to it, one kind by each team, and the two kinds rarely touch the same lines. Signs that a split would not work: both teams make all kinds of changes, the code handles a single coherent concept, and the proposed boundary is artificial.
The cost of a split is the one-time design and implementation effort to separate the pieces, plus the ongoing cost of maintaining the interface. For code that will be modified for years, this is usually a bargain. For code that is nearly done evolving, it may not be worth it.
See how to choose between a monorepo and multiple repos for a related discussion on code separation at a larger scale.
Pattern three: platform team
The third pattern is to create a dedicated team whose job is the shared code. The other teams are customers of the platform team, consuming its output as a service with a defined interface.
This is the most expensive pattern. It requires staffing a new team and setting up the organisational structure to support it. It also creates a new failure mode: the platform team becomes a bottleneck if it is understaffed, and both the other teams get slowed down waiting for changes.
Platform teams make sense when the shared code supports more than two teams, when the volume of change in the shared code is high enough to justify dedicated staffing, and when the shared code is strategically important to the organisation. Common examples: an authentication service used by every product, a data pipeline many teams rely on, a shared UI component library.
The structural trap is treating a platform team as a service team with no autonomy. A platform team that just takes requests from other teams and implements them becomes a bottleneck. A platform team that owns its direction and treats requests as inputs rather than orders can scale. The organisational question of how to structure a platform team well is larger than this piece, but the choice to create one is itself a response to the shared-ownership problem.
Enforcement through tooling
Any of the three patterns is easier to maintain when the review structure is enforced mechanically. Most repository hosts support an ownership file that automatically assigns reviewers to pull requests based on which files were changed. This is a CODEOWNERS file in GitHub, approvers in GitLab, and similar in other hosts.
With shared code, every pull request that touches the shared path gets a reviewer from each owner team. The reviewer from the other team catches the changes that would break their assumptions. Without this, each team reviews only its own changes and the review gap is permanent.
The tool only works if the teams honour the review assignment. A reviewer who stamps approvals without reading is not providing review. But the mechanical enforcement at least surfaces the responsibility: the review is a visible action in a visible place, and patterns of inadequate review are easier to spot than patterns of informal neglect.
For broader context on code review, see what good code review looks like.
How to pick between the patterns
The three patterns suit different situations. The question is which situation you are in.
Pick the owner-and-contributor pattern when the shared code has a defensible primary owner, the volume of change is moderate, and the organisational cost of staffing a platform team would be too high. This is the lowest-cost resolution and the most common one in practice.
Pick the split when the code has a hidden boundary you can locate with confidence, both teams make changes on different sides of it, and the interface between the two pieces is designable without needing to be renegotiated constantly. This is the most durable resolution when it fits.
Pick the platform team when the shared code supports more than two teams, the strategic importance justifies the staffing, and you can resource the team at a level where it is not a bottleneck. This is the most expensive resolution and the most powerful when it fits.
Picking the wrong one is worse than picking a decent one. A split that does not fit the code creates permanent interface friction. A platform team that is understaffed becomes universally hated. A single owner for code that genuinely belongs to two teams creates resentment and hidden workarounds.
What AI-generated code changes
Agents working in shared code paths make the drift problem faster. The engineer directing an agent is focused on the feature being built, not on the conventions of code they did not write. The agent, given a feature to implement, picks a pattern that works locally and does not necessarily match what another team has chosen in the same file.
The response is to tighten the ownership and the review. A clear owner means the agent-generated change goes through a reviewer who knows the conventions. A split means the agent is working in a defined area with known patterns. A platform team means someone is accountable for consistency across what multiple feature teams contribute.
The temptation to treat agent-generated code as lower-stakes because it is cheap to produce makes the drift problem worse. The cost is the same as human-written code once it is in the system; the shortcut is in the writing, not the maintenance. See why code ownership still matters when agents write it for more on this.
The pattern to avoid
The pattern to avoid is the default: shared ownership without structure. Both teams make changes. Each team reviews its own. The file evolves without an owner. The problems appear in six months rather than six weeks, which makes the default feel safer than it is.
Picking a pattern deliberately is almost always better than letting the current state continue. Even an imperfect choice gives the code an owner, forces the review gaps to close, and makes the design decisions explicit. The three patterns are not the only options, but they are the three that tend to work. The one that does not work is the one most organisations are in by default.


