Shotgun Surgery: What It Costs and How to Fix It
A single logical change requires small edits scattered across many different classes or files.
What It Is
Shotgun Surgery is the inverse of Divergent Change. Where Divergent Change means one class changes for many reasons, Shotgun Surgery means one reason causes changes in many classes. For example, adding a new user field requires editing the User model, the database migration, the API controller, the serialiser, the form component, the validation logic, and the test fixtures. Each edit is small, but missing any one creates an inconsistency. The scattered nature of the change makes it easy to forget a location and hard to verify completeness.
Why It Costs Money
Incomplete changes are the primary cost. When a change requires touching 8 files and a developer updates 7, the missed file creates a bug that may not surface until production. These partial-change bugs are expensive because they pass all automated tests for the files that were updated.
Change effort is multiplied. A conceptually simple change (add a field, rename a status) requires opening, understanding, modifying, and testing many files. Developer time scales linearly with the number of scattered edit sites.
Knowledge requirements are unreasonable. The developer making the change must know all the places that need updating. This knowledge is rarely documented and lives in the heads of senior team members, creating a bus factor risk.
Specific Cost Mechanisms
- ●Partial-change bugs: each missed edit site has to be diagnosed and fixed after it reaches production
- ●Multiplied effort: each scattered change has to be found, made and tested in every class it touches
- ●Knowledge dependency: only senior developers who know all the edit sites can safely make changes
Estimated Annual Cost
Cost of one instance a year by team size, from our model at $180K fully-loaded cost per engineer. Low and high use the bottom and top of the High inputs; mid is halfway. See full methodology.
| Team Size | Low | Mid | High |
|---|---|---|---|
| 3 devs | $3K | $7K | $11K |
| 5 devs | $4K | $10K | $16K |
| 8 devs | $6K | $15K | $24K |
| 10 devs | $7K | $19K | $30K |
| 20 devs | $14K | $35K | $57K |
These are model outputs, not measurements. Every input is on the cost model page, and the same model produces the figures on the 22 smells page. Put in your own team and cost in the smell profile calculator.
How to Detect It
Specific rules and thresholds for automated detection. See full tool comparison.
High coupling between classes indicates scattered responsibilities
Repeated patterns across files suggest shotgun surgery
Files that always change together in commits indicate shotgun surgery
Identifies files with high co-change frequency
Refactoring Patterns
Proven techniques to eliminate this smell. See all refactoring patterns.
Move Method/Field
Behaviour scattered across classes belongs in a single class
Inline Class
A class exists only to hold one piece of a scattered concern
Extract Class (centralise)
The scattered edits all serve a concept that deserves its own class