Designing an Integration Layer for Legacy Systems
Engineering

Designing an Integration Layer for Legacy Systems

A worked mapping table, a comparison of legacy connection points, and the timeout, retry, circuit-breaker and contract-testing rules that keep an old system's quirks out of new code.

Short answer

An integration layer for a legacy system, often called an anti-corruption layer, is a separate component that translates every request and response between the old and new systems, so new code never depends on legacy tables, codes or quirks. Design it around meaning rather than field names, keep business rules out of it, contain legacy failures with timeouts and circuit breakers, and give it a retirement plan.

What is an integration layer for legacy systems, and when do you need one?

An integration layer is a dedicated piece of software that sits between a new system and a legacy one and translates every request and response, so the new code never has to adopt the old system's data model, codes or quirks. In domain-driven design this is called an anti-corruption layer. Microsoft's description of the pattern puts it plainly: when a new application has to keep working with a legacy system, supporting the old system's convoluted schemas or obsolete APIs can corrupt an otherwise clean design, so you isolate the two and put the translation logic in one place. The layer can be a component inside the new application or an independent service.

You need one when a migration will run in stages and the new and old systems must keep exchanging data in the meantime, or when two systems that must talk to each other use the same words to mean different things. The warning signs are familiar: a new service reading legacy tables directly "just for now", single-letter status codes appearing in a modern user interface, and each new team writing its own copy of the same mapping. Microsoft also notes when the pattern may not be worth it: when the two systems have no significant semantic differences. And it is explicit that the layer should hold translation logic, not business rules or orchestration.

What exactly should the layer translate?

It should translate meaning, not just field names. A column called STATUS holding K may mean "invoiced" in the finance module and "shipped" in the warehouse module; renaming the field does not resolve that. Work through these categories with people who use the old system every day:

  • Identifiers: legacy customer numbers with leading zeros, reused numbers, composite keys. Keep a mapping table rather than re-deriving IDs in code.
  • Amounts, units and currencies: integers holding kuruş or cents, quantities in boxes in one module and pieces in another.
  • Dates and time zones: local times stored without an offset, and placeholder dates that mean "not set".
  • Empty values: blanks, zeros, -1 or 1900-01-01 used instead of null.
  • Character encoding: older Turkish systems may store text in a legacy code page, so characters such as ğ, ş and İ must round-trip correctly.
  • States and transitions: which legacy combinations map to which new state, and which transitions the old system allows.
  • Commands and errors: one new command may need several legacy calls, and every legacy error code needs a defined meaning on the new side.

Write the result as a mapping table that is versioned with the code. Here is a hypothetical excerpt for orders in an old ERP:

Legacy valueWhat it means in the old systemNew model
STATUS='K' and invoice number filledClosed by finance after invoicingInvoiced
STATUS='K' and invoice number emptyClosed by the warehouse after shipmentShipped
STATUS='I'Cancelled; reason held in a separate tableCancelled with a reason
DLV_DATE='1900-01-01'Delivery not yet scheduledNo delivery date (null)
AMOUNT=1250075Integer kuruş in Turkish lira12,500.75 TRY as a decimal with currency
Any other statusUnknownExplicit error and an alert, never a default

The last row matters most. Silently mapping an unexpected code to "Other" or "Open" is how corrupted data spreads into the new system.

Where should the layer connect to the legacy system?

Use the most stable integration point the old system offers, and choose synchronous or asynchronous communication per operation. The options, roughly from most to least preferable:

Integration pointWhen it fitsMain risk
Existing service or APIThe legacy system exposes one that is still maintainedLimited operations, slow responses
Database triggers or change data captureLogic lives in stored procedures and the application cannot be changedCoupling to the schema, ordering of changes
Read-only database accessNo API exists and only reads are neededLocks, schema changes; never write around the old system's rules
File exchangeThe old system already works in nightly batchesLatency, partially written files
Screen automationLast resort, for a short transitionBreaks whenever a screen changes

Microsoft's Strangler Fig guidance mentions the database route for database-centric applications: the database itself can send messages to new services, or change data capture can read the transaction log, without changing application code. For communication style, keep calls synchronous when the new side needs an answer immediately, such as a credit-limit check. For propagating changes, the anti-corruption layer can also work asynchronously through a message broker, which decouples the new domain from the legacy system's throughput limits. Either way, budget for what Microsoft lists as the pattern's costs: extra latency, another service to run and scale, and the work of keeping data consistent across both sides.

How do you stop legacy failures from spreading?

Give every call a timeout, retry only what is safe to retry, and stop calling a system that is clearly down. Reads can usually be retried. Writes cannot, unless the operation is idempotent. If the old system has no idempotency support, the layer should generate a request ID, store it where it can be read back (an unused reference field is often available), and after a timeout check whether the write happened before trying again. An order or payment whose outcome is unknown should be marked as such and reconciled, not blindly resent.

When failures pile up, a circuit breaker stops the layer from hammering a struggling system. In Microsoft's description, the breaker counts recent failures while closed, opens once a threshold is reached so that calls fail immediately, and after a timeout lets a limited number of trial calls through in a half-open state before closing again. Retries and breakers can be combined, but the retry logic should stop when the breaker reports a non-transient fault. While the circuit is open, the new side can show cached data or a clear "temporarily read-only" message instead of hanging.

Finally, make failures diagnosable. Microsoft recommends correlation IDs and structured logging at this boundary, and input validation because the two sides may have different trust levels. Log the contract version, the mapping rule applied, the legacy response code and the duration, without logging personal data or secrets. Count translation errors separately from legacy outages: one means your mapping is wrong, the other means the old system is down.

How do you test an integration layer?

Test the translation rules in isolation and the real connection end to end. Pact's contract testing documentation describes the idea: check each application in isolation against a shared contract that records the requests and responses they exchange, generated from the consumer's tests so that only what consumers actually use is checked. That works well between the new services and the layer. The legacy side usually cannot run provider tests, so record real responses from a non-production copy and use them as fixtures that pin down the old system's behaviour.

  1. Every row of the mapping table has a test in both directions.
  2. An unknown status produces an explicit error and an alert, not a default value.
  3. A write that times out and is retried creates exactly one record in the old system.
  4. Text containing ğ, ü, ş, ı, ö, ç and İ survives a full round trip.
  5. Placeholder dates, negative amounts, duplicate customer numbers and overlong text from real history are handled.
  6. With the legacy system stopped, the circuit opens and the new interface degrades as designed.
  7. A deliberately dropped update is found by the reconciliation job.
  8. A short end-to-end run against a representative non-production legacy instance, because recorded fixtures miss timing and undocumented behaviour.

Hypothetical example: a customer portal on top of an old ERP

Suppose a distributor wants a customer portal for order history and repeat orders, while orders still live in an ERP that offers a read-only service and a stored procedure for order entry. The portal never sees ERP structures. It asks the layer for GET /orders and receives orders in the new model, with statuses mapped by the table above. Responses are cached for a short, agreed period to protect the ERP during peak hours.

A repeat order goes through the layer as one command. The layer validates it, generates a request ID, calls the stored procedure and writes the ID into the order's reference field. If the call times out, the order is shown to the customer as "processing", and a reconciliation job looks up the request ID a few minutes later instead of submitting it again. If the ERP fails repeatedly, the circuit opens, the portal switches to read-only history with a banner, and new orders are blocked rather than lost. The team watches translation errors by mapping rule, ERP response times, minutes with the circuit open, commands with an unknown outcome and reconciliation mismatches.

When should the integration layer be retired?

Decide at the start whether the layer is permanent or temporary, and give each mapping its own retirement condition. Microsoft's pattern asks exactly this question. The authors of Patterns of Legacy Displacement call such components transitional architecture: software installed to ease the displacement of a legacy system and intended to be removed when the displacement is complete, whose risk-reduction value should be weighed explicitly against its cost. Keep a register of each mapping, its consumers, its owner and its removal condition: no calls across a full business cycle including month-end and year-end, historical data migrated, reconciliation signed off. An adapter that nobody owns and nobody plans to remove becomes the next legacy system. For moving functions across one route at a time, see our strangler-fig migration plan.

Common mistakes

  • Putting pricing, approval or other business rules into the translation layer.
  • Letting a new service read legacy tables directly "just this once".
  • Mapping unknown values to a default instead of failing visibly.
  • Retrying writes after a timeout without checking whether they succeeded.
  • Building one shared layer for every system with no owner and no retirement plan.

API and integration work and the staged modernisation of existing systems are both within the scope of our custom software development service; the first discovery call is free.

Key takeaways

  • Translate meaning, not field names, and version the mapping table with the code.
  • Turn unknown legacy values into explicit errors and alerts, never defaults.
  • Never retry a legacy write blindly: use a request ID, read back the result and reconcile unknown outcomes.
  • Use timeouts and a circuit breaker so a struggling old system degrades the new one gracefully.
  • Test every mapping row in both directions with fixtures recorded from the real system.
  • Give each mapping an owner and a removal condition that covers a full business cycle.

Frequently asked questions

What is an anti-corruption layer?

It is a pattern from domain-driven design: a facade or adapter between two systems that do not share the same meaning for their data. It translates requests and responses in both directions, so the new system keeps its own model while still using the old system's data and functions.

Is an anti-corruption layer the same as an API gateway?

No. A gateway handles cross-cutting concerns such as exposure, authentication and throttling, while an anti-corruption layer translates between data models and meanings. They are often used together: the gateway exposes the API, and the layer behind it maps the new model to the legacy one.

Should the integration layer read the legacy database directly?

Only when no API exists, and preferably only for reads. Direct reads couple you to the schema, can cause locking and break when the old system changes. Writing directly to legacy tables bypasses the old system's own validation and is rarely safe.

How do you test an integration with a system you cannot change?

Record real responses from a non-production copy and turn them into fixtures that pin down its behaviour, including errors and odd historical records. Contract-test the new services against the layer, and keep a short end-to-end run against a representative legacy instance to catch timing and undocumented behaviour.

When can the integration layer be removed?

When no consumer has called a mapping across a full business cycle, including month-end and year-end jobs, historical data has been migrated and reconciliation has been signed off. Decide at the start whether the layer is temporary, and track each mapping's owner and removal condition.

All articles