LOAD-BEARINGfree
High-level designTier 5 · unit 4 of 5 · 12 min read

Anti-corruption layers

Some of the systems you must integrate with are not yours and never will be: a payment provider, a KYC vendor, a courier's tracking API, the mainframe that has run settlement since 1998. You do not get to fix their model. The only question is how far into your codebase their model is allowed to travel.

Left alone, the answer is: all the way. It starts with one convenient decision — the vendor's response object is almost what you need, so you pass it through. Six months later your domain objects carry statusCode: 'PND_AUTH_2', your business logic branches on the vendor's enum, their notion of "customer" is your notion of customer, and their four-value status field has quietly become the state machine of your product. The integration stopped being at the edge; it is now load-bearing structure.

The layer, and what it actually does

An anti-corruption layer is a translation boundary between your model and theirs. Inside it: their vocabulary. Outside it: yours, exclusively. Nothing of theirs crosses — not a type, not a field name, not an enum value, not an error code.

You have met the shape before. Tier 2's dependency inversion said business logic should define the interface it needs and let the detail implement it. That is exactly this, at architecture scale:

your domain          ┃  ACL             ┃  vendor
Payment.authorised   ┃  'PND_AUTH_2' →  ┃  vendor JSON
Money(₹, minor)      ┃  "1250.00" str → ┃  their decimals
PaymentDeclined      ┃  HTTP 200 + err→ ┃  their taxonomy

The interface — PaymentGateway, with authorise(Money) → Result — is yours. You wrote it to say what your domain needs, before you read the vendor's documentation. The adapter behind it is where the vendor lives, and it is the only file in the codebase that imports their SDK.

Four things it must translate, not just one

Teams build the first of these and stop, which is why so many "anti-corruption layers" corrupt anyway.

  • Names and types. The easy one. cust_ref becomes customerId; their stringly-typed "1250.00" becomes your Money in minor units. Mostly mechanical.
  • Semantics. The one that matters. Their CANCELLED may cover both "the user cancelled" and "we refunded it", which in your domain are different events with different accounting. If your mapping is a lookup table of names, you have not translated meaning — and meaning is where the bugs are. Expect this mapping to be lossy in one direction, and write down which.
  • Errors. Vendors return HTTP 200 with {"error": ...} in the body. They use one code for "card declined" and "our database is down" — one of which you must never retry and one of which you must. The ACL owns that classification, converting their taxonomy into your two categories that actually matter: a business outcome versus a technical failure.
  • Time and identity. Their timestamps are in their timezone, from their clock, which Tier 6 will remind you is not your clock. Their ids are theirs — store them as an opaque external reference on your entity, never as your primary key. The moment a vendor's id is your key, changing vendors becomes a data migration.

Where it lives, and what it costs

An ACL can be its own service or a module inside yours, and the choice is less important than the discipline. Separate service when the vendor needs its own credentials, rate limits and blast radius, or when several of your services integrate with the same vendor and you refuse to write the mapping three times. In-process module otherwise — a directory nobody else imports from is a real boundary if the team treats it as one.

And it is not free. You pay a mapping layer to write and maintain, an extra place for bugs to hide, and a genuine debugging cost: when something is wrong, there are now two representations to compare. Skip it when the integration is throwaway, when you are reading data you will never act on, or in the rare case where the vendor's model genuinely is your domain — some standards, like an ISO message format, are the domain, and inventing a parallel vocabulary for them is invention for its own sake.

The two payoffs

Vendor replacement stops being a rewrite. A second adapter behind the same interface, run both against production traffic, cut over per-merchant. With the vendor's model spread through your code, that same project is a quarter of archaeology. The ACL is the mechanism that turns exit cost from unbounded into estimable — which is what makes it an argument you can take to a procurement conversation, not just a code review.

It is how you strangle a legacy system. Tier 14's strangler fig pattern needs somewhere to put the translation while new and old coexist — and they coexist for years. The new service speaks its own clean model; the ACL talks to the legacy database, the SOAP endpoint, or the nightly file drop. Each migrated slice deletes a piece of the ACL. When the last piece is gone, so is the legacy system, and your domain model never once bent to accommodate a thing you were in the process of deleting.

The trap

The thin wrapper that renames fields and passes the vendor's object through. It has a folder called adapters, it has an interface, it reviews well — and it translates nothing, because the vendor's structure survived intact. The test is not "is there a layer?" but "if this vendor doubled their status values or restructured their response, how many files change?" If the answer is more than the adapter, the corruption already happened; the layer is just where it passes through on the way in.

The tradeoff sheet

Problem solved
A legacy or third-party model leaking into your domain, so that their rename becomes your refactor and their nulls become your special cases.
Rejected, and why
Using their model directly is genuinely simpler and correct when the relationship is small and stable. A shared library couples you to their release cycle instead of their schema, which is not obviously better.
The trade
A translation layer to write and maintain, plus a mapping that goes stale silently when the upstream adds a field you never learn about.
First to break at 10x
The mapping, under change velocity rather than load. At 10x the traffic it is fine; at 10x the rate of upstream change it is a full-time job.
What it does to the bill
Near zero in infrastructure and real in engineering time. This is a boundary you pay for in salary, not compute.
Day-2 operations
Log and alert on translation failures rather than swallowing them — an unmapped enum value silently becoming a default is the bug this layer was supposed to prevent.