The Wild

Hard Abstraction Rules After a Brutal System Migration?

· 7 min read · Mammals

In this article
  1. Why Migrations Leave You Vulnerable
  2. What Makes an Abstraction “Hard”?
  3. How to Implement Hard Abstraction Rules Post-Migration
  4. Common Problems and How to Avoid Them
  5. Hard vs. Soft Abstraction: What's the Difference?
  6. Costs and Benefits of Hard Abstraction Rules
  7. Alternatives to Hard Abstraction Rules
  8. Frequently Asked Questions

Yes, hard abstraction rules are the correct approach after a brutal system migration, because they prevent the new system from inheriting the old one's messy dependencies and make future changes safer and faster. A hard abstraction is a strict interface that hides implementation details and forbids direct access to underlying data or services. After a migration, you need these rules to enforce the boundaries you just spent so much effort creating, otherwise the old system's habits will creep back in and undo the benefits of the move.

Why Migrations Leave You Vulnerable

Migrations are disruptive. Teams often rush to move data, rewrite services, or switch platforms, and in that rush, shortcuts get taken. Code that was once temporary becomes permanent. Direct database queries from the frontend, hardcoded API endpoints, or business logic scattered across controllers are common post-migration smells. The system works, but it's fragile. Without hard abstraction rules, every new feature becomes a minefield: you change one thing, and something unrelated breaks because the dependency graph is tangled.

Hard abstraction rules are the guardrails that keep the new system clean. They force all interactions to go through defined interfaces, so the internal implementation can evolve without affecting the rest of the codebase. This is especially important after a migration because the migration itself often reveals how brittle the old system was. You don't want to repeat that pain.

What Makes an Abstraction “Hard”?

A hard abstraction is more than just a design suggestion. It's an enforced rule. In practice, this means:

  • No direct access to data stores – all reads and writes go through a repository or data access layer.
  • No bypassing the service layer – controllers and UI code cannot instantiate domain objects or call internal methods directly.
  • Stable interfaces – the public API of a module is fixed; changes require versioning or explicit approval.
  • Dependency rules are enforced by tooling – linters, architecture tests, or build checks fail if someone violates the boundary.

For example, after migrating from a monolithic PHP app to microservices, you might have a rule that all inter-service communication must use a shared message contract. A hard abstraction would require that contract to be versioned and that no service can directly query another service's database. Tools like ArchUnit (Java), Dependency-Check, or even simple CI scripts can enforce these rules.

How to Implement Hard Abstraction Rules Post-Migration

Implementing hard rules after a migration is a matter of discipline and tooling. Here are the steps that work:

  1. Define the boundaries – map out the modules and services, and decide what each one owns. Write down the allowed dependencies.
  2. Create the interfaces – for each boundary, define a clear API that hides internal details. This is the contract that everyone must use.
  3. Add automated enforcement – use architecture tests, linters, or CI jobs that check for violations. For example, a test that scans the codebase for direct SQL queries outside the data layer.
  4. Refactor existing code – systematically move code that violates the rules into the correct layer. This may take time, but it's essential.
  5. Make it part of the definition of done – any new feature or bug fix must not introduce new violations. Code reviews should check for this.

Common Problems and How to Avoid Them

Hard abstraction rules are not without their own challenges. One common problem is over-abstraction: creating so many layers that simple tasks become cumbersome. This often happens when teams overreact to a messy migration and try to isolate everything. The result is a system that's hard to navigate and slow to develop in.

Another issue is that rules are only as good as their enforcement. If the rules are documented but not checked, they'll be ignored. That's why automated enforcement is critical. A rule that isn't enforced is just a suggestion.

There's also the risk of “abstraction leakage” – where the abstraction is supposed to hide a dependency, but the implementation leaks details through exceptions, return types, or configuration. For example, a repository that returns a raw database cursor defeats the purpose. Make sure the abstraction is complete.

Hard vs. Soft Abstraction: What's the Difference?

Soft abstraction is when you have interfaces and layers, but they're not strictly enforced. Developers can bypass them “just this once” for convenience. That works fine in a small project, but after a migration, the system is often large and complex, and those bypasses accumulate quickly. Soft abstraction is a slippery slope: one direct query leads to two, then ten, and soon you're back to the mess you just migrated away from.

Hard abstraction, on the other hand, is non-negotiable. The rules are enforced by tooling and culture. The trade-off is that it requires more upfront discipline and can feel restrictive. But after a brutal migration, that restriction is exactly what you need to keep the system stable and maintainable.

Costs and Benefits of Hard Abstraction Rules

Implementing hard abstraction rules has a cost. It takes time to define boundaries, write interfaces, and refactor existing code. It also adds a layer of ceremony to development – you can't just hack something together quickly. However, the benefits usually outweigh the costs, especially after a migration:

  • Reduced risk of regression – changes are isolated, so you don't break unrelated parts of the system.
  • Faster onboarding – new developers can understand the architecture because the rules are clear and enforced.
  • Easier testing – you can mock interfaces instead of dealing with concrete implementations.
  • Future migrations are easier – if you ever need to move to another platform, you only change the implementation behind the abstraction.

The cost is real, but the alternative – a system that slowly decays into a tangled mess – is often more expensive in the long run.

Alternatives to Hard Abstraction Rules

If hard abstraction rules seem too heavy, there are alternatives. One is to use soft abstraction and rely on code reviews and team discipline. This works for small teams or short-lived projects, but it's risky after a migration because the codebase is likely large and the team may be stressed.

Another alternative is to use a microservices architecture with strict API contracts, but that's essentially hard abstraction at the service level. You could also use a modular monolith with enforced module boundaries – that's a middle ground. Or you could adopt a data-centric approach where the database schema is the contract, but that often leads to tight coupling.

In practice, most teams benefit from at least some hard rules around the most critical boundaries – like data access and external integrations – even if they keep other parts softer.

Frequently Asked Questions

What if we already have direct database queries everywhere?

You'll need to refactor, but you can do it incrementally. Start by wrapping the most critical tables in a repository, then gradually move other queries. Use automated tests to catch violations as you go. It's a lot of work, but it's necessary to prevent future pain.

Can hard abstraction rules slow down development?

Initially, yes, because you have to write interfaces and follow strict patterns. But in the long run, they speed things up because you spend less time debugging tangled dependencies and more time adding features. The key is to keep the abstraction layers thin and pragmatic.

How do we enforce the rules without making the build fail constantly?

Start with a baseline: run the enforcement tool, fix all current violations, then add the check to CI. New violations will fail the build, but existing ones are already fixed. You can also allow a temporary whitelist for legacy code, but with a plan to remove it.

Is it okay to have a “back door” for emergencies?

It's tempting, but a back door defeats the purpose. If you need to bypass the abstraction for a hotfix, you'll do it under pressure, and the violation will stay. Instead, design the abstraction to handle emergencies – for example, a bulk operation API or a debug endpoint that's clearly marked and time-limited.

What about third-party libraries that force us to access their internals?

Wrap third-party libraries in your own interface. That way, if you need to replace the library later, you only change the wrapper. This is a classic adapter pattern and it's a form of hard abstraction that isolates external dependencies.

Do hard abstraction rules apply to frontend code too?

Yes, especially after a migration. For example, if you migrated from a server-rendered app to a single-page application, you should have a strict API client layer that all frontend code uses. No direct fetch calls to arbitrary endpoints – only through the API service.