← Lessons

quiz vs the machine

Platinum1800

System Design

The Anti Corruption Layer

Translating a foreign model so it cannot leak inward.

6 min read · advanced · beat Platinum to climb

Keeping Models Clean

When your service integrates with a legacy system or a third party API, its data model is rarely the one you want. If you let that foreign model flow straight into your code, its quirks corrupt your clean domain. An anti corruption layer is a translation boundary that converts between the two models.

What It Does

  • Maps the external schema to your internal domain types.
  • Hides external quirks such as odd status codes or naming.
  • Provides a stable interface so your core code never references the foreign system directly.

Why It Pays Off

If the external API changes, only the anti corruption layer changes; your domain stays untouched. It also lets you swap one provider for another by writing a new translator behind the same interface.

Cost

The layer is extra code and an extra mapping to maintain, so reserve it for integrations whose model genuinely clashes with yours rather than wrapping every call.

Key idea

An anti corruption layer translates a foreign model into your domain at the boundary, so external quirks and changes stay contained and never corrupt your core code.

Check yourself

Answer to earn rating on the learn ladder.

1. What does an anti corruption layer protect?

2. When the external API changes, what ideally needs to change?