Quick revision
The short answer
I would start with the interface the domain needs, in its own terms, such as InventoryAvailability returning domain types, and implement it in a separate integration module that holds the ERP client, DTOs that mirror the ERP exactly, and translators from those DTOs to domain objects. ERP codes map to domain enums explicitly and unknown codes fail loudly, ERP errors are normalised into a few domain-meaningful failures, and the translators are tested with real recorded ERP payloads, including odd cases. Finally, ERP types are kept out of every other module, enforced with architecture tests.
What to remember
In this answer, we designed an anti-corruption layer for a legacy ERP. We defined the interface the domain needs in its own terms, such as InventoryAvailability with domain types, and implemented it in an integration module with an ERP client, DTOs that mirror the ERP, and translators. ERP codes map explicitly to domain enums with loud failures on unknown codes, ERP errors are normalised into a few domain-meaningful failures, translators are tested with real recorded payloads including odd cases, and ERP types are kept out of other modules with architecture tests.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would start with the interface the domain needs, in its own terms, such as InventoryAvailability returning domain types, and implement it in a separate integration module that holds the ERP client, DTOs that mirror the ERP exactly, and translators from those DTOs to domain objects. ERP codes map to domain enums explicitly and unknown codes fail loudly, ERP errors are normalised into a few domain-meaningful failures, and the translators are tested with real recorded ERP payloads, including odd cases. Finally, ERP types are kept out of every other module, enforced with architecture tests.
Why this question is asked
Legacy ERP systems are a rite of passage for enterprise developers. Their fields are named like MATNR and LGORT, status codes are single letters whose meaning depends on another field, an error may arrive as HTTP 200 with a message in a text field, and nobody who designed it is still at the company. Interviewers ask this design question because it tests whether we can protect a clean domain from such a system in a way that survives years of maintenance. In this answer, we will define the domain interface, structure the integration module, translate codes and overloaded fields, normalise errors, test with recorded payloads, and enforce the boundary.
1Start With the Interface the Domain Needs
The first decision is made without looking at the ERP. We ask what our domain actually needs from it, and we write that as an interface in the domain layer, using our language and our types. For an order service, the need might be: how many units of this product can we promise from this warehouse, and when?
Notice that the interface is narrow and shaped by our use case, not by the ERP's API, which probably offers fifty fields. That narrowness is what makes the rest of the design manageable: we only translate what we need.
2Structure the Integration Module
The implementation lives in its own module, for example erp-integration, which depends on the domain module and not the other way round. Inside it there are three kinds of classes. The ERP client knows how to call the ERP, whether over SOAP, a REST gateway or a file drop. The ERP DTOs mirror the ERP's payloads exactly, with the ERP's own field names and types, so that mapping errors are never hidden in the parsing step. The translators turn DTOs into domain objects and back.
- Domain module
InventoryAvailability, Availability,StockStatus - ErpInventoryAvailabilityimplements the domain interface
- Translatorscodes to enums, overloaded fields, errors
- ERP DTOsMATNR, LGORT, STAT: exact mirror of the payload
- ERP clientSOAP or HTTP, timeouts and retries
5 layers, from the top down. Step through them one at a time.
3Translate Codes and Overloaded Fields Explicitly
ERP codes are mapped to domain enums with an explicit table, not with clever parsing, and an unknown code fails loudly instead of falling back to a default. The reason is safety: if the ERP adds status 'Q' next year and we silently treat it as IN_STOCK, we may sell stock we do not have. A loud failure, an exception and an alert, makes someone look at the new code and add a mapping deliberately.
Overloaded fields need the same care. Suppose LABST, the stock quantity, holds a negative number to mean a backorder, and the MSG field sometimes holds a restock date in ddMMyyyy format when STAT is 'R'. The translator is where those rules are written down, once, with comments and tests.
4Normalise ERP Errors Into Domain Failures
Legacy systems report errors inconsistently: a SOAP fault, an HTTP 500, a 200 response with STAT 'E' and a message such as 'MAT NOT FOUND', or a timeout. The domain should not care about any of these forms. The ACL turns them into a few domain-meaningful failures, for example ProductUnknownInErp, InventoryTemporarilyUnavailable and ErpDataInvalid, each with the original details kept for logs.
Choosing the categories by what the caller can do is the useful rule. If the product is unknown, the order service can reject the line. If the ERP is temporarily unavailable, it can fall back to a cached value or show 'availability unknown'. If the data is invalid, it should alert someone. Transient categories are also where the ACL applies timeouts and retries with backoff, so the domain never waits on a hung ERP call.
| What the ERP returns | Domain failure | What the caller does |
|---|---|---|
| 200 with STAT E and MSG MAT NOT FOUND | ProductUnknownInErp | Reject the order line |
| HTTP 503, timeout, SOAP fault | InventoryTemporarilyUnavailable | Use cached value or show unknown |
| Unparseable quantity or unknown code | ErpDataInvalid | Alert, do not guess |
5Test With Real Recorded Payloads
The translators are the code most likely to be wrong, because they encode undocumented rules. So we test them with real payloads recorded from the ERP's test or production environment, anonymised where needed, rather than with hand-written examples that reflect what we think the ERP sends. The set should include the odd cases we have seen: padded strings, negative quantities, empty dates, unexpected codes and error messages in success responses. Each new production surprise becomes another recorded file and test, so the ACL's knowledge of the ERP grows over time instead of living in someone's memory.
6Keep ERP Types Out of Every Other Module
The whole design fails if ERP DTOs start appearing in other modules, because then the ERP's model is back in the domain. Module dependencies help: if the domain module does not depend on erp-integration, it cannot import its classes. Architecture tests make the rule explicit and catch violations in other modules too.
The implementation class itself is wired in by Spring through the domain interface, so the rest of the application only ever sees InventoryAvailability, and the rule can stay strict. If a few configuration classes must reference it, they can be listed as explicit exceptions.
7Follow-up questions
Should the ACL cache ERP responses?
Often, yes, because legacy ERPs are slow and sometimes unavailable. Caching belongs in the ACL or just behind the domain interface, with a clear time to live, so the domain can choose between fresh and cached data through its own API rather than knowing about the ERP's performance.
How do you learn what the cryptic codes mean?
From ERP experts, configuration tables and observed data. Every mapping gets a comment with its source and a test with a recorded payload. Building this knowledge into the translator is one of the most valuable things the ACL does.
What if the domain needs to write to the ERP?
The same structure works in reverse: a domain command such as reserveStock goes through a translator that builds the ERP request, and the ERP's response is mapped back to a domain result or failure.
8Conclusion
In this answer, we designed an anti-corruption layer for a legacy ERP. We defined the interface the domain needs in its own terms, such as InventoryAvailability with domain types, and implemented it in an integration module with an ERP client, DTOs that mirror the ERP, and translators. ERP codes map explicitly to domain enums with loud failures on unknown codes, ERP errors are normalised into a few domain-meaningful failures, translators are tested with real recorded payloads including odd cases, and ERP types are kept out of other modules with architecture tests.
Open with
I would design it from the domain side first. I write the interface my domain needs, in my language, say InventoryAvailability with a check method that takes a Sku and a WarehouseId and returns an Availability record with a domain StockStatus enum, and I keep it narrow, only what the use case needs.
Then, if they want more
Then I implement it in a separate integration module that depends on the domain, never the other way round. Inside, there is an ERP client that handles the transport, timeouts and retries; DTOs that mirror the ERP payloads exactly, field names like MATNR and STAT included, so parsing stays dumb; and translators that hold all the knowledge.
Codes go to enums through an explicit map, and an unknown code throws and alerts rather than defaulting, because silently treating a new status as in stock could sell stock we do not have. Overloaded fields, like a negative quantity meaning backorder or a date hidden in a message field, are handled once in the translator with comments and tests.
Errors, whether a SOAP fault, a 503, a timeout or a 200 with an error code, are normalised into a few domain failures chosen by what the caller can do: product unknown, temporarily unavailable, data invalid. I test the translators with real recorded ERP payloads, including the weird ones, and add each production surprise as a new case.
Finally, an ArchUnit test makes sure no class outside the integration package depends on ERP types, so the ERP model can never leak back in.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your Spring service must integrate with a legacy ERP that uses cryptic codes, overloaded...": https://scrivio-interview-library.netlify.app/java/domain-driven-design/58cf69fe92/