Clean, modern business objects
Backend & Runtime / Knowledge library
Anti-Corruption Layer
Translates between a domain model and an external or legacy model
Why learn Anti-Corruption Layer?
It prevents foreign concepts from distorting the local design
The problem it solves
It isolates semantic mismatch across system boundaries
Where it came from
Anti-Corruption Layer is a software design pattern that translates between a domain model and an external or legacy model. Its guarantees and tradeoffs depend on the concrete implementation and operating context.
Build your understanding
Work through these exercises in order. Try the task before opening a reference.
- Define Anti-Corruption Layer and distinguish it from a neighboring concept.
- Choose a realistic task where Anti-Corruption Layer is appropriate.
- Identify a failure mode caused by misusing Anti-Corruption Layer.
- Interpret a small design or result involving Anti-Corruption Layer.
- Explain one tradeoff or limitation of Anti-Corruption Layer.
Documentation and sources
- Patterns of Enterprise Application Architecture (martinfowler.com)
Connect the ideas
Explore next
Real World Example
Legacy Logistics Integration
A modern e-commerce platform transitioning to a microservices architecture.
The business problem
The new order management system must integrate with a legacy mainframe logistics provider that uses proprietary, rigid data formats, threatening to pollute the clean domain model of the new system with legacy constraints.
How this topic solves it
An Anti-Corruption Layer (ACL) acts as a protective boundary, translating the legacy system's complex, non-standard data structures into the clean, domain-specific objects required by the new order management system.
- Define a clean domain interface that represents the order requirements without legacy baggage.
- Implement a facade or adapter that communicates with the legacy logistics API.
- Create a translation layer that maps legacy data fields into the domain objects.
- Route all interactions through the translation layer so the domain model remains isolated from the legacy system.
The flow shows how the Domain Model interacts with the Legacy System through the ACL.
Translation and mapping logic
Proprietary mainframe logistics
- Domain Model → Requests via clean interface → Anti-Corruption Layer
- Anti-Corruption Layer → Translates to legacy protocol → Legacy System
- Legacy System → Returns raw legacy data → Anti-Corruption Layer
- Anti-Corruption Layer → Maps to domain objects → Domain Model
Expected business outcome
The core domain model remains decoupled from the legacy system, allowing for easier future migrations or replacements of the logistics provider.
Limitations and checks
The ACL introduces a maintenance overhead because any change in the legacy system's schema requires a corresponding update to the translation logic, which can be verified by monitoring the mapping layer's unit test coverage.