~/notes/anti-corruption-layer

Anti-Corruption Layer

A translation layer that maps between your clean domain model and the "corrupt" (messy, foreign) model of a legacy or third-party system.

Aug 20, 2026

diagram
Legacy or Third-party ServiceAnti-Corruption LayerOur Domain ServiceForeign response modelTranslate names, types, and meaningClean domain objectDomain commandTranslate to foreign contractForeign request model
Legacy or Third-party ServiceAnti-Corruption LayerOur Domain ServiceForeign response modelTranslate names, types, and meaningClean domain objectDomain commandTranslate to foreign contractForeign request model

Pros

  • Keeps the domain model separate from old systems or third-party terms and names.
  • Limits the impact of changes in external contracts to just the translation layer.
  • Clearly states integration assumptions and allows them to be tested on their own.

Drawbacks

  • Requires extra mapping code to deal with differences in meaning, not just changes in field names.
  • May lead to having the same data models and validation rules on both sides of the integration.
  • If the translation is incomplete, it can quietly lose important details or cause inconsistent behaviour.