Disposable architecture is the idea that you design a module for replacement from the start: the business capability stays, and the implementation behind it can go. AI made rewriting cheap, so I wanted to sort out which parts of a system you can really throw away and which you can't. In this article, we look at what has to survive a replacement, five principles for designing replaceable modules, and how to switch to a new implementation safely.
Software doesn't get hard to change because the code is old. It gets hard when too many parts of the system depend on how that code works inside.
What is disposable architecture?
Disposable architecture is a way of designing a system so that replacing an implementation is a controlled engineering decision. You expect some implementations to become obsolete, and you put boundaries where that replacement will be cheap.
Martin Fowler described the closest idea as sacrificial architecture in 2014: build software knowing it has a limited lifespan, and keep it modular so the replacement is possible. He also noted that you can sacrifice a young system whole, but as it grows, it's more effective to sacrifice individual modules. This article takes that second part and turns it into a repeatable practice.
As an example, eBay started as Perl scripts in 1995, moved to C++ in 1997, and to Java in 2002. Each version served the business of its time.
Disposable architecture overlaps with several ideas you may already use, but each one has a different goal:
| Concept | Main goal |
|---|---|
| Disposable architecture | Make replacing an implementation an acceptable, planned option |
| Modular architecture | Reduce coupling and organize responsibilities |
| Hexagonal architecture (ports and adapters) | Isolate application logic from external dependencies |
| Evolutionary architecture | Support incremental architectural change |
| Strangler pattern | Gradually replace existing functionality |
| AI-generated code | Reduce the effort of writing an implementation |
What should survive a replacement?

A new implementation can change almost everything inside the module. It must keep what other people and systems rely on:
- Business data and its meaning. The prices, discounts, and order history the old code wrote must still mean the same thing.
- Business invariants. A discount never makes a price negative. A gold customer always gets 10%. These rules don't disappear because the code did.
- Observable behavior. Callers depend on results, not only on shapes. A new pricing engine that returns the same JSON but rounds half-cents differently isn't compatible.
- Contracts. The operations, queries, and events other modules call or subscribe to.
- Side effects that already happened. Emails sent, payments captured, and files shipped to partners stay done.

Everything else is free to change: the internal schema, the persistence technology, the algorithm, the libraries, and the framework. A replacement can move Pricing from SQL Server to PostgreSQL or from tables to a rules engine, as long as the data migrates under control and the invariants hold.
I left infrastructure out. Disposable servers and containers are a different topic.
5 Principles for designing replaceable modules:
A module isn't replaceable because it has an interface. It's replaceable when it has all five properties.

1. Define boundaries around business capabilities
Draw the module around one business responsibility, not around a technical layer. An online store has Pricing, Orders, Payments, and Notifications. Replacing Pricing shouldn't require a change to the Orders database or a rewrite of Payments.
A "Services" project or a "Data" layer isn't a boundary you can replace, because every feature runs through it. A capability is: it has high cohesion inside (all pricing rules live together) and low coupling outside (other modules only ask for a price).

That boundary doesn't need a network. Fowler was wary of microservices for a sacrificial architecture, because distribution and asynchrony add complexity, and he called a monolith "often a good sacrificial architecture". I wouldn't split a system into microservices just to make its parts disposable. Module boundaries inside a monolith are enough for that. As I wrote in AbstractLess, I'd start with a monolith and split a part out when it needs its own scaling or release cycle.
2. Hide implementation details behind contracts

Other modules depend on the module's public contract, never on its internal classes, tables, or persistence models. This holds for an HTTP API, an internal .NET interface, and an event alike. A replaceable module may expose several operations, queries, and events. What matters is that no consumer depends on how they're implemented.
A contract includes behavior, not only request and response types: rounding rules, which discounts stack, what happens with an unknown SKU. Write those down as tests (principle 4 and the next section), because a type signature can't hold them.
Prefer backward-compatible changes when the contract evolves. Adding an optional field is usually safe. Adding an enum value, tightening validation, or adding a field to an event can still break a strict consumer, so check who reads the contract before you call a change additive. When a break is unavoidable, version that operation or event. For schema changes in events and stored data, see Data Versioning and Schema Evolution Patterns.
3. Isolate state and data ownership

The module owns its data, and only the module reads and writes it. When Checkout joins on the pricing tables, Pricing can't change its schema without breaking Checkout, so the module isn't replaceable anymore.
Ownership is what lets a replacement change the physical schema. The business data and its meaning must survive. The table layout doesn't. A new implementation can restructure the data or move it to another store, as long as you migrate it under control and the invariants still hold after the move.
4. Separate business rules from infrastructure

Keep the pricing rules apart from the database, the tax API, and the cache. Ports and adapters (dependency inversion at the module edge) do this: the rules depend on a small port such as ITaxRates, and an adapter implements it for the real tax provider. Consumers of Pricing see neither the rules nor the adapters.
Put those ports only at meaningful edges: external systems, storage, and the module boundary itself. I still wouldn't wrap every library in an interface to make it replaceable. I put the boundary around a module that does one business job. An IMyLogger that forwards every call to Serilog doesn't make anything replaceable. It only adds a layer to maintain.
5. Plan for replacement and coexistence

Real systems rarely switch implementations in one step. Plan from the start how the old and new versions will run side by side: a configuration switch or routing rule that picks the implementation, a way to compare their results, a plan for migrating state, and a way back if the new version misbehaves. Without this, a "replaceable" module still turns into a big-bang release on the day you replace it.
Example: replacing a Pricing module
Here is the Pricing module before anyone designed it for replacement.

Before. Orders and Checkout read the Prices and Discounts tables directly. Checkout also applies the gold-customer discount itself, because it was faster than asking Pricing. Reports join on the discount table. To replace the pricing engine, you have to change three modules and their queries in one release.
After. Orders and Checkout call one contract. Only Pricing touches its tables. The discount rule lives in one place.
public interface IPricingService
{
Task<PriceQuote> QuoteAsync(PriceRequest request, CancellationToken ct);
}
public sealed record PriceRequest(string CustomerId, IReadOnlyList<CartLine> Lines, string Currency);
public sealed record CartLine(string Sku, int Quantity);
public sealed record PriceQuote(decimal Subtotal, decimal Discount, decimal Total);Now you can write PricingServiceV2, for example, a rules engine instead of hand-written if statements, and pick the implementation in configuration. Orders and Checkout don't change:
builder.Services.AddScoped<PricingServiceV1>();
builder.Services.AddScoped<PricingServiceV2>();
builder.Services.AddScoped<IPricingService>(sp =>
sp.GetRequiredService<IConfiguration>()["Pricing:Engine"] == "v2"
? sp.GetRequiredService<PricingServiceV2>()
: sp.GetRequiredService<PricingServiceV1>());The algorithm inside V2 can be completely different. The business rules can't: if V1 gives gold customers 10% and rounds to cents, V2 must too, until the business decides otherwise. That decision is a product change, and it should ship separately from the replacement.
How to replace a module safely

1. Capture the current behavior. Before you write V2, write characterization tests: tests that record what V1 does today, including the odd cases, whether or not anyone documented them. Turn every known production fix into a test. A fix that lives only in V1's code is lost in V2.
2. Run the same tests against both versions. The tests talk to IPricingService and nothing else. In this example, TestPricing builds each version with an in-memory price list where SKU-1 costs 9.99 and gold-1 is a gold customer:
public abstract class PricingContractTests
{
protected abstract IPricingService CreateService();
[Fact]
public async Task Gold_customer_gets_ten_percent_rounded_to_cents()
{
var quote = await CreateService().QuoteAsync(
new PriceRequest("gold-1", [new CartLine("SKU-1", 3)], "EUR"),
CancellationToken.None);
Assert.Equal(29.97m, quote.Subtotal);
Assert.Equal(3.00m, quote.Discount);
Assert.Equal(26.97m, quote.Total);
}
}
public class PricingV1Tests : PricingContractTests
{
protected override IPricingService CreateService() => TestPricing.CreateV1();
}
public class PricingV2Tests : PricingContractTests
{
protected override IPricingService CreateService() => TestPricing.CreateV2();
}As I wrote in Top 10 Unit Testing Anti-Patterns in .NET, if I can rewrite the internals completely and keep behavior the same, my tests should stay green. A test that mocks the repository and checks which method was called fails on V2 even when the price is right.
3. Shadow the new version in production. Call V2 with the same input, compare its result with V1, log any difference, and return V1's result. Pricing is a good candidate because a quote has no side effects:
public sealed class ShadowPricingService(
PricingServiceV1 current, PricingServiceV2 candidate, ILogger<ShadowPricingService> log)
: IPricingService
{
public async Task<PriceQuote> QuoteAsync(PriceRequest request, CancellationToken ct)
{
var result = await current.QuoteAsync(request, ct);
try
{
var shadow = await candidate.QuoteAsync(request, ct);
if (shadow != result)
log.LogWarning("Pricing mismatch for {Customer}: v1 {V1}, v2 {V2}",
request.CustomerId, result, shadow);
}
catch (Exception ex)
{
log.LogWarning(ex, "Pricing v2 failed for {Customer}", request.CustomerId);
}
return result;
}
}The records compare by value, so shadow != result catches a one-cent difference. This version doubles the latency of every quote, so in production you'd sample a share of requests or run the candidate in the background. Never shadow an operation with an irreversible side effect, such as capturing a payment or sending an email, because the shadow would run it twice.
4. Roll out gradually. Switch a small share of traffic to V2 with the configuration flag, watch the mismatch log and the business metrics, and widen the share. Rollback is a configuration change, as long as V1 and its data are still there.
5. Migrate state and retire V1. If V2 uses a new schema, migrate the data while V1 still serves traffic, and keep both in sync until the switch is complete. Then delete V1, its tables, and the shadow code. A replacement that never removes V1 leaves you maintaining two pricing engines.
The Strangler pattern follows the same steps at the scale of a whole system.
When disposable architecture makes sense
It pays off for modules that change often or are likely to be replaced: pricing and recommendation algorithms, integrations with vendors you may switch, and features you're still validating with users. Fowler suggests the same for new features: build them in a sacrificial way for a subset of users until you know they're worth full investment.

Note: if the boundary is right and only the code inside is messy, refactor instead of replacing. Replacement makes sense when the design inside the boundary can't carry the new requirements.
Where AI changes the economics
AI reduces the cost of writing V2. A coding agent can draft a new implementation behind IPricingService quickly, and that makes replacement an option in more places than before. It doesn't reduce the cost of the other steps: capturing behavior, checking compatibility, migrating state, and rolling out.
So the design work above matters more with AI, not less. The checks that decide whether a change ships should be deterministic: the build, the contract tests, the shadow comparison. The agent writes the code, and the pipeline judges it, the same rule as in What to Build Before You Give Agents Write Access.
I'm not sure how far this goes for core business logic. There I'd still review generated code line by line.
Conclusion
- Keep the business capability, replace the implementation. Design each module so its responsibility, data meaning, and contract outlive the code behind them. The schema, the algorithm, and the libraries can change.
- Capture behavior before you replace code. The old implementation holds rules nobody wrote down. Characterization tests and a shadow run turn them into something you can check V2 against.
- Replace only when the benefit pays for the cost. A replaceable design makes the switch cheaper, not free. Refactor when the boundary is sound, and replace when the design inside it has run out.
Comments (0)