API / Microservices Design Patterns Interview Questions
What is the Anti-Corruption Layer (ACL) pattern in microservices?
The Anti-Corruption Layer (ACL) is a translation boundary placed at the edge of a service to prevent an external model — typically from a legacy system or a foreign bounded context — from contaminating the service's own domain model. Without it, the consuming service must adopt the vocabulary, data shapes, and assumptions of the external system, gradually corrupting its clean internal design.
The ACL consists of three collaborating components:
- Facade — presents a clean interface to the internal domain, hiding the existence of the external system entirely.
- Adapter — calls the external system's API, reads its events from a message broker, or queries its data store on behalf of the facade.
- Translator/Mapper — converts between the external model and the internal domain model in both directions. For example, a legacy ERP might call a product a "SKU Item" with a flat
unitPriceinteger field; the translator converts this into the internalProductaggregate with a properMoneyvalue object.
Key use cases:
- Integrating with a legacy monolith during a Strangler Fig migration — the new service has its own clean model while the ACL handles translation to/from the old system.
- Consuming a third-party SaaS API without exposing its schema to your core domain model.
- Bridging two bounded contexts that use overlapping but divergent concepts of the same entity.
The ACL ensures that internal domain objects evolve independently of whatever is outside the boundary. When the external system changes its model, only the ACL needs updating — not the core domain logic. This is especially valuable during long-running migrations where the legacy system remains in use for months or years.
More Related questions...