Anti-Corruption Layer
A translation layer that isolates a bounded context from external or legacy systems, preventing their models from contaminating the internal domain model.
Also known as: ACL, Translation Layer, Isolation Layer
Category: Software Development
Tags: domain-driven-design, software-design, architecture, patterns, integration
Explanation
The Anti-Corruption Layer (ACL) is a strategic Domain-Driven Design pattern that creates an isolating layer between a bounded context and an external system whose model differs from or would negatively influence the internal domain model. It translates between the two models, ensuring that the clean domain model remains uncontaminated by external concerns.
**When to use:**
- Integrating with legacy systems that have a different (often messier) domain model
- Consuming third-party APIs whose data structures don't match your domain
- Migrating from an old system to a new one incrementally
- Protecting your domain model from an upstream system you don't control
**How it works:**
The ACL sits at the boundary of a bounded context and performs three functions:
1. **Translation**: Converts data from the external model to the internal model and vice versa (e.g., mapping a legacy 'CUST_REC' to a domain 'Customer' entity)
2. **Facade**: Presents a clean, domain-appropriate interface that hides the complexity of the external system
3. **Adapter**: Handles protocol and format differences (REST to SOAP, XML to JSON, synchronous to asynchronous)
**Implementation patterns:**
- **Service layer**: A set of services that wrap external system calls and return domain objects
- **Translators/Mappers**: Dedicated classes that convert between external and internal representations
- **Gateway pattern**: An object that encapsulates access to an external system or resource
- **Event translation**: Converting external events into internal domain events
**Benefits:**
- **Model integrity**: Your domain model stays clean and focused on your business needs
- **Change isolation**: When the external system changes, only the ACL needs updating
- **Testability**: The ACL provides a natural seam for testing—you can mock the external system at the ACL boundary
- **Incremental migration**: When replacing a legacy system, the ACL allows gradual transition
**The cost of NOT having an ACL:**
Without an anti-corruption layer, external models leak into your domain code. Over time, your domain model becomes a hybrid that serves no context well—cluttered with fields, translations, and workarounds for external system quirks. This is a form of technical debt that compounds rapidly.
Related Concepts
← Back to all concepts