Anti-Corruption Layer
Put a translation layer between a new system and a legacy or external one, so the old system's model and quirks don't leak into the new design.
Description
When a new service has to talk to a legacy ERP, a mainframe or a partner's API, the easy path is to use their data model directly: their field names, status codes and odd rules. Soon the new service is shaped like the old one. An anti-corruption layer stops that.
The layer belongs to the new side. It speaks the new system's clean model on one side and the legacy system's protocol and model on the other, translating requests, responses and errors both ways. It's the Adapter pattern at the scale of whole systems, and a key tool when migrating away from legacy piece by piece.
System design
Anti-Corruption Layer system design diagram
- Billing service (service): clean model.
- Anti-corruption layer (gateway): translates both ways.
- Legacy ERP (external service): KUNDNR, FAKT_HDR….
- Step 1: Billing service → Anti-corruption layer: createInvoice(customer).
- Step 2: Anti-corruption layer → Legacy ERP: SOAP: FAKT_CREATE.
- Step 3: Legacy ERP → Anti-corruption layer: status code 07.
- Step 4: Anti-corruption layer → Billing service: Invoice { status: "sent" }.
- The billing service asks for an invoice using its own clean model: a Customer and an Invoice.
- The layer translates that into the ERP's protocol and field names.
- The ERP answers in its own terms, such as status code 07.
- The layer translates the answer back into the billing model. Nothing about the ERP leaks past it.
- AWS
- A dedicated service on Lambda or ECS; API Gateway with mapping templates for simple cases.
- Azure
- API Management policies or a Functions/Container Apps service; Logic Apps connectors.
- Google Cloud
- Apigee or API Gateway with a Cloud Run translation service.
When to use it
Use it when
- A new system must integrate with a legacy or third-party system whose model you don't want to adopt.
- You're migrating gradually (Strangler Fig) and old and new must coexist for a while.
- Two teams' bounded contexts use the same words to mean different things.
Avoid it when
- The other system's model is already a good fit. Translation adds latency and code for nothing.
- The integration is tiny and temporary. A small adapter in code may be enough.
Pitfalls
- The layer becoming a bottleneck or single point of failure. Scale and monitor it like any service.
- Business logic creeping into the translation layer. Keep it to mapping.
- Translating only the happy path. Map legacy errors and odd status codes deliberately, too.
- Keeping the layer forever after the migration. Plan to remove it when the legacy system goes.
Alternatives
Adapter
Choose it when the mismatch is one class or library inside a single codebase.
Strangler Fig
Choose it when you're replacing the legacy system feature by feature; an ACL often sits beside it.
Conformist
Choose it when the upstream model is fine and you deliberately adopt it to save translation effort.