Problem
A new service must integrate with a legacy system or third-party API whose model is awkward or inconsistent. Letting those concepts leak in pollutes the new domain model and couples it to the foreign system.
Also known as: acl, translation-layer
Isolate a new model from a legacy or external system by translating between their models at a boundary.
A new service must integrate with a legacy system or third-party API whose model is awkward or inconsistent. Letting those concepts leak in pollutes the new domain model and couples it to the foreign system.
An Anti-Corruption Layer (ACL), from domain-driven design, protects a clean model from an external one. The new system speaks its own language internally; the ACL translates at the border so legacy concepts never spread.
The ACL has three parts: a facade the domain calls, translators that convert between models, and adapters that talk to the foreign protocol (SOAP, flat files, a vendor SDK).
Domain --> CustomerGateway (facade)
|
Translator: LegacyCust -> Customer
|
Adapter --> legacy CRM (SOAP)
For example, the legacy CRM returns a status code of "A", "I" or "X" and a combined name field. The translator maps these to an enum ACTIVE, INACTIVE, CLOSED and splits the name into first and last. Writes flow the opposite way. The ACL can be a library inside the service or a standalone service when several consumers share it.
Low - library or small service
Medium - keep mappings in sync
Medium - requires domain-modelling discipline
Translator silently drops or mistranslates fields
Layer grows into a business-logic dumping ground
Foreign types leak past the facade