Overview
Eric Evans introduced the Anti-Corruption Layer (ACL) in Domain-Driven Design as the pattern for protecting a well-designed domain model from the influence of a foreign model it must integrate with. In most established enterprises, that foreign model is a legacy system of record: a mainframe application or packaged core platform — core banking, insurance policy administration, telecoms billing, an ERP, a government registry — whose internal message structures, field naming conventions, error codes, and date formats reflect decades of COBOL history rather than any modern domain design. Without an ACL, the legacy model bleeds into every downstream service that integrates with it. Within two or three integration cycles, teams find themselves debating whether AMT01 and AMT02 mean the same thing or not — and discovering that the answer depends on which release of the legacy core is running in which environment.
An ACL does three things: it translates (maps the legacy model to the domain model and back), it isolates (changes in the legacy message structure do not propagate to domain services), and it versions (multiple releases of the legacy core can coexist in a migration window). What it does not do is add business logic. Translation is mechanical and reversible. Any business rule that belongs in the system of record stays there; any rule that belongs in the domain service stays there. The ACL contains only mappings, format conversions, and protocol translations.
In a typical IBM integration stack, the ACL is implemented as an IBM ACE 12 message flow that sits on the boundary between IBM MQ queues (the legacy core’s communication mechanism) and either REST APIs or Kafka topics (the domain service communication mechanisms). The same shape works with Apache Camel, Kafka Connect or any other mediation runtime. The ACL owns neither the system of record nor the domain service — it is owned by the integration team and versioned independently of both.
An ACL is defined by the bounded context it protects, not by the number of services it serves. If five domain services all consume payment events from the same legacy queue, there is one ACL for the payment domain — not five adapters. Those five services consume from a translated internal event topic; they never touch the legacy message format. Duplication of translation logic is the fastest way to end up with five subtly incompatible interpretations of the same legacy field.
The examples below use a payment notification because it exercises amounts, dates, statuses and identifiers in one message. Nothing in the pattern is payment-specific: the same translation applies to a policy event from an insurance administration system, a usage record from a telecoms billing platform, an order update from a retail ERP, or a case change from a government registry. All queue names, field names and codes are invented for illustration.
Why ACL, Not an Adapter
The vocabulary distinction matters in practice. An adapter converts between two interfaces without changing the model. A legacy adapter that exposes the legacy core’s own message model as a REST API is not an ACL — it just wraps the protocol. The calling service still sees AMT01, VALDT, and six-character codes that mean different things depending on record type. The domain model is polluted.
An ACL translates the model. The calling service sees amount, valueDate, and accountId in a canonical format that matches the domain’s ubiquitous language. The legacy core’s internal field names, record lengths, and encoding conventions exist only inside the ACL flow and are invisible to the domain services that sit upstream.
Some DDD practitioners implement ACLs inside the domain service itself (a translation class at the entry point of the service). This works for small integrations but creates a maintenance problem: every domain service that integrates with the legacy core must maintain its own translation. A single change to the legacy message format requires updates to every service independently. When several domain services consume from the same legacy queue, a shared ACL flow is maintained in one place and all services benefit from the update simultaneously.
Canonical Model Design
Before writing a line of ACE ESQL, define the canonical model — the internal representation that the ACL translates to and that domain services consume from. The canonical model is a JSON Schema (for REST/event consumers) or an AsyncAPI schema (for Kafka consumers). It is not a copy of the legacy message structure and it is not a copy of an industry standard — though it should be mappable to the relevant standard without data loss: ISO 20022 for payments (most clearing schemes now require it), ACORD for insurance, TM Forum’s information model for telecoms.
Canonical model rules that hold up in production:
- Field names are in camelCase English and describe the business concept, not the technical container.
creditAmountnotCdtAmtand notTxnAmtCr. - Monetary amounts are strings with explicit decimal notation (e.g.
"12345.67"), not floating-point numbers. This is non-negotiable: floating-point monetary amounts cause rounding errors that accrue across millions of transactions. - Dates use ISO 8601 (
2026-11-21for dates,2026-11-21T14:32:00Zfor timestamps). Legacy cores typically useYYYYMMDDor Julian dates; the conversion is in the ACL, not in the consumer. - Identifiers are strings, not integers, even when the legacy core sends them as fixed-width numeric fields. Legacy identifiers carry leading zeros that are semantically significant; treating them as integers loses those zeros.
- Status codes are domain enumerations, not legacy numeric codes.
PENDINGnot01. The legacy-code-to-domain-enum mapping table is maintained in the ACL and version-controlled alongside it.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://schemas.example.com/payments/PaymentCompletedEvent/v2",
"title": "PaymentCompletedEvent",
"type": "object",
"required": ["eventId", "eventTime", "paymentId", "status", "creditAmount"],
"properties": {
"eventId": { "type": "string", "format": "uuid" },
"eventTime": { "type": "string", "format": "date-time" },
"paymentId": { "type": "string" },
"endToEndId": { "type": "string", "maxLength": 35 },
"status": {
"type": "string",
"enum": ["ACCEPTED", "PENDING_SETTLEMENT", "SETTLED", "REJECTED", "RETURNED"]
},
"creditAmount": { "type": "string", "pattern": "^[0-9]+\\.[0-9]{2}$" },
"currency": { "type": "string", "minLength": 3, "maxLength": 3 },
"debtorIban": { "type": "string" },
"creditorIban":{ "type": "string" },
"valueDate": { "type": "string", "format": "date" },
"sourceReference":{ "type": "string",
"description": "Original system-of-record ref; not used by domain consumers but carried for audit"
}
},
"additionalProperties": false
}
Note sourceReference: the original system-of-record reference is carried through the canonical event for audit and reconciliation, but it is not part of the domain model. Domain services must not use it as a primary key or reference. Its presence in the schema makes the traceability requirement explicit and prevents it from being quietly stripped during a later refactoring.
ACE Translation Layer
The ACE translation flow has three responsibilities: read the legacy message from the input queue, translate it to the canonical model, and publish the translated event. The flow does not call any other system and does not hold state. It is designed to be as thin as possible — any complexity that cannot be eliminated goes into an ESQL subflow that can be unit-tested in isolation.
Structure the ACE project as: one BAR file per domain boundary (not per queue), one main flow per message type, one ESQL module per translation concern. This keeps the deployment unit coherent: a change to the payment domain ACL deploys the payment BAR, not a monolithic integration BAR that touches all domains.
CREATE COMPUTE MODULE LegacyEventTranslator_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
-- Input: fixed-width bytes from MQ, parsed by a DFDL model (LegacyEventNotify_v3.xsd)
DECLARE srcMsg REFERENCE TO InputRoot.DFDL.LegacyEventNotify;
-- Translate status code: legacy 2-digit numeric → domain enum
DECLARE domainStatus CHARACTER;
SET domainStatus = CASE srcMsg.StatusCd
WHEN '01' THEN 'ACCEPTED'
WHEN '02' THEN 'PENDING_SETTLEMENT'
WHEN '03' THEN 'SETTLED'
WHEN '04' THEN 'REJECTED'
WHEN '05' THEN 'RETURNED'
ELSE NULL
END;
-- Unknown status: route to dead-letter with enrichment, never swallow silently
IF domainStatus IS NULL THEN
SET OutputRoot = InputRoot; -- keep the original bytes for replay
SET OutputLocalEnvironment.Destination.MQ.DestinationData[1].queueName = 'ACL.PAYMENT.DLQ';
SET Environment.Variables.DLQ_REASON = 'UNKNOWN_STATUS:' || srcMsg.StatusCd;
PROPAGATE TO TERMINAL 'out1';
RETURN FALSE;
END IF;
-- Translate date: legacy YYYYMMDD → ISO 8601 string
DECLARE valueDateStr CHARACTER
CAST(SUBSTRING(srcMsg.ValueDt FROM 1 FOR 4) AS CHARACTER)
|| '-'
|| CAST(SUBSTRING(srcMsg.ValueDt FROM 5 FOR 2) AS CHARACTER)
|| '-'
|| CAST(SUBSTRING(srcMsg.ValueDt FROM 7 FOR 2) AS CHARACTER);
-- Translate amount: 15-digit integer in minor units → "NNNNN.NN" string
DECLARE amtWhole CHARACTER CAST(srcMsg.Amt01 / 100 AS CHARACTER);
DECLARE amtFrac CHARACTER RIGHT('0' || CAST(MOD(srcMsg.Amt01, 100) AS CHARACTER), 2);
DECLARE creditAmt CHARACTER amtWhole || '.' || amtFrac;
-- Write canonical JSON output
SET OutputRoot.JSON.Data.eventId = CAST(UUIDASCHAR AS CHARACTER);
SET OutputRoot.JSON.Data.eventTime = CAST(CURRENT_TIMESTAMP AS CHARACTER FORMAT 'yyyy-MM-dd'T'HH:mm:ss'Z'');
SET OutputRoot.JSON.Data.paymentId = TRIM(srcMsg.BizRef);
SET OutputRoot.JSON.Data.endToEndId = TRIM(srcMsg.E2ERef);
SET OutputRoot.JSON.Data.status = domainStatus;
SET OutputRoot.JSON.Data.creditAmount = creditAmt;
SET OutputRoot.JSON.Data.currency = TRIM(srcMsg.CcyCd);
SET OutputRoot.JSON.Data.debtorIban = TRIM(srcMsg.DrAcctId);
SET OutputRoot.JSON.Data.creditorIban= TRIM(srcMsg.CrAcctId);
SET OutputRoot.JSON.Data.valueDate = valueDateStr;
SET OutputRoot.JSON.Data.sourceReference = TRIM(srcMsg.HostRef);
RETURN TRUE;
END;
END MODULE;
Three implementation details above that frequently cause production bugs if missed: TRIM on character fields (legacy fixed-width fields carry trailing spaces that corrupt downstream string comparisons), implied-decimal handling (legacy cores commonly send amounts as integers in minor units — the value times 100 for a two-decimal currency; the ACL is responsible for the decimal point, not the consumer), and null-safe status mapping (every unmapped status code must be caught explicitly and routed to the DLQ with the original code preserved — swallowing unknown codes silently is how money goes missing in reconciliation).
MQ Wire-Protocol Isolation
The ACL’s MQ topology is as important as the ESQL translation logic. The goal is complete wire-protocol isolation: domain services never connect to legacy queues, and legacy processes never connect to domain queues. The ACL is the only component that holds connections to both.
The enquiry bridge is a request-reply flow: a domain service sends a canonical REST request to the ACL, the ACL translates it to a legacy MQ message, sends it to LEGACY.ENQ.REQ with a correlation ID and a reply-to queue, waits for the reply on LEGACY.ENQ.REPLY, translates the reply, and returns the canonical REST response. Set a bounded waitInterval on the ACE MQGet node (not a Java sleep) so the flow gives up deterministically and returns a canonical timeout, rather than holding a worker thread for however long the legacy core takes to answer.
Version Negotiation
Legacy message formats change. The team that owns the system of record publishes a new version of a notification message; some fields are renamed, one is removed, two new fields are added. The ACL must handle both the old format (while some nodes or regions still run the old release) and the new format (once the upgrade completes). This is the version negotiation problem, and it is more common than it should be: large enterprises routinely run two or more releases of the same legacy core at once across production, DR, and regional or subsidiary environments.
Implement version negotiation in the ACL using the MQMD Format field, a custom SourceSchemaVersion property in the MQRFH2 header, or — most reliably — a version discriminator within the message body itself (a HeaderVersion field that the system-of-record team agrees to maintain). The ACE flow reads the version discriminator and routes to a versioned ESQL submodule:
CREATE COMPUTE MODULE SchemaVersionRouter_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
DECLARE schemaVer CHARACTER
InputRoot.MQRFH2.usr.SourceSchemaVersion;
-- Route to the correct versioned translator subflow
IF schemaVer = '3' OR schemaVer IS NULL THEN
-- v3 is current and the default if the header is absent
PROPAGATE TO TERMINAL 'out1';
ELSEIF schemaVer = '4' THEN
-- v4 is the new format; run in parallel during the legacy upgrade window
PROPAGATE TO TERMINAL 'out2';
ELSE
-- Unknown version: DLQ with the version value for diagnosis
SET Environment.Variables.DLQ_REASON = 'UNKNOWN_SOURCE_SCHEMA_VERSION:' || schemaVer;
PROPAGATE TO TERMINAL 'out3';
END IF;
RETURN FALSE;
END;
END MODULE;
Maintain version-specific translator submodules until the old source version is fully decommissioned and the DLQ has been quiet for 30 days. Only then remove the old submodule. Keep the version routing table in the ACL, not in a property file or a database — it is part of the integration contract and must be version-controlled alongside the ESQL.
Error Isolation
The ACL’s error handling policy directly determines whether a legacy-side failure becomes visible to domain services and their downstream consumers. The goal is complete error isolation: a processing error on the legacy side should never propagate as an unhandled exception into the domain services’ event stream. What reaches the domain is either a valid canonical event or nothing — never a half-translated message, never a raw legacy error code.
An ACE ESQL exception during translation (a legacy field that does not conform to the expected format, a null field that the mapping code did not anticipate) must route the original message to the DLQ, not the partially-translated output to the domain topic. A domain service consuming a partially-translated event and writing it to its own database creates a data quality problem that takes days to diagnose in production. The ACL must be transactional: either a fully valid canonical event is published, or the original legacy message goes to the DLQ and an alert fires. Never both, never neither.
Implement the error boundary in ACE using the message flow’s exception list node with a DLQ MQOutput node on the failure terminal. The DLQ message must carry: the original message bytes (for reprocessing), the exception text, the timestamp of the failure, and the source schema version. These four fields are the minimum needed by the operations team to diagnose and replay a DLQ backlog without involving the application team.
Every message in the ACL DLQ represents a source transaction that was not propagated to the domain. If the payment reconciliation service is consuming from the domain Kafka topic, those DLQ messages are payment events that the reconciliation service has not seen. Set an IBM MQ queue depth alert at a threshold of 10 messages — not the operational default of 80% queue capacity. At 10 DLQ messages, an on-call engineer investigates; at 1000, the reconciliation job may have already produced incorrect reports.
Testing the ACL
The ACL’s translation logic is deterministic: the same legacy message always produces the same canonical output. This makes it unusually testable. The standard testing approach is a data-driven contract test suite: a table of legacy message examples (covering every status code, every edge case in the amount or date format, and each source schema version) paired with the expected canonical output. Run this suite in CI on every commit to the ACL project.
-
Collect production message examples
Run the ACL in production with a message-capture tap (a monitoring MQ queue that receives a copy of every inbound legacy message). Collect 1000 messages across a 2-week window. This sample will cover real field values, real edge cases, and real status codes that the WSDL or message catalogue did not document. The collected messages become the test fixture.
-
Define the expected canonical output for each sample
Run each sample through the ACL and validate the output manually. Store each (input, expected-output) pair in a JSON test fixture file under version control. Flag any message where the translation produces an unexpected result — that is a defect in the current ACL, not a test to be skipped.
-
Write the contract test harness
Use the IBM ACE unit test framework (or a lightweight test runner that invokes ACE flows programmatically via the embedded runtime API) to replay each fixture input and assert exact equality with the expected output. The test must fail on any change to the canonical output for an existing input. This is the regression safety net: a source schema upgrade is only safe to deploy when the existing contract tests still pass and the new version-4 tests also pass.
-
Test error handling paths explicitly
Fabricate legacy messages with unknown status codes, truncated fields, null mandatory fields, and amounts exceeding the expected range. Assert that each routes to the DLQ terminal with the correct DLQ reason code. The DLQ path must be tested; it is never covered by the happy-path fixture.
-
Test version routing
Provide inputs with MQRFH2 headers for each supported source schema version and assert that the correct versioned translator is invoked. Provide an unknown schema version and assert that the DLQ terminal fires. Provide a message with no schema version header and assert that the default (current) version is used.
-
Performance baseline in CI
Run a throughput test in the CI pipeline: 10,000 messages processed sequentially, measuring end-to-end translation time. Record the p99 latency. Any commit that increases p99 by more than 10% fails the build. Translation latency is a production constraint: legacy cores emit notifications in bursts (end-of-day batches, month-end runs); the ACL must drain the queue faster than the legacy core fills it.
Observability
The ACL has two key operational metrics: translation throughput (messages translated per second, with a threshold alert if it falls below the legacy burst rate) and DLQ depth (the number of messages that could not be translated). Both are emitted as IBM MQ PCF events and scraped by the monitoring stack. Add a third metric specific to the ACL: translation lag, the difference between the timestamp in the source message header and the timestamp of the published canonical event. For notifications that feed real-time customer-facing products, translation lag above 500ms is an operational incident.
# Custom ACL metrics emitted via ACE user-defined statistics
metrics:
- name: acl_translations_total
type: counter
labels: [domain, source_version, outcome]
description: Total ACL translation attempts; outcome is 'ok' or 'dlq'
- name: acl_translation_lag_seconds
type: histogram
labels: [domain]
buckets: [0.05, 0.1, 0.25, 0.5, 1.0, 2.5]
description: Time from source message creation to canonical event publish
- name: acl_dlq_depth
type: gauge
labels: [domain, queue_name]
description: Current DLQ depth; alert at >10
alerts:
- name: AclDlqDepthHigh
condition: acl_dlq_depth{domain="payments"} > 10
severity: critical
message: "Payment ACL DLQ has {{$value}} messages. Check source message format for a version change."
- name: AclTranslationLagHigh
condition: histogram_quantile(0.99, sum by (le) (rate(acl_translation_lag_seconds_bucket{domain="payments"}[5m]))) > 0.5
severity: warning
message: "Payment ACL p99 translation lag is {{$value}}s. Legacy queue may be backing up."
Deployment Checklist
-
Define and version the canonical model schema
Publish the JSON Schema (or AsyncAPI schema for event-based contracts) to the internal schema registry with a semantic version. All domain service teams must acknowledge the schema before the ACL is deployed. The canonical schema is the contract between the ACL and its consumers; it must be reviewed and agreed before the ACL goes live.
-
Implement and test the ESQL translation module
Write the ESQL translation following the patterns above: TRIM all character fields, explicit CASE for status codes, string representation for all monetary amounts and identifiers, ISO 8601 for all date and datetime fields. Run the full contract test suite. All tests must pass, including DLQ routing tests and version negotiation tests.
-
Configure MQ topology with strict zone separation
Create ACL-specific MQ queue names that domain services cannot resolve (name them in the legacy-zone namespace). Grant the ACL service account read access to legacy queues and write access to domain queues. Domain service accounts must have no access to legacy queues. Validate the access control model in a non-production environment before deploying to production.
-
Deploy DLQ and configure depth alerting
Create the domain-specific DLQ (
ACL.{DOMAIN}.DLQ) before deploying the ACL. Configure IBM MQ queue depth alerts at threshold 10. Configure the DLQ message format to include the original message bytes, exception text, timestamp, and source schema version. Validate the DLQ alert in a test environment by deliberately injecting a message with an unknown status code. -
Deploy in shadow mode alongside the existing adapter (if replacing one)
If the ACL is replacing an existing direct adapter, deploy it in shadow mode first: both the existing adapter and the ACL receive the same legacy messages; compare their outputs for 48 hours before cutting over. Any discrepancy is a defect in the ACL translation logic, not an expected difference. The shadow period is non-negotiable.
-
Establish translation lag baseline
After go-live, measure the p99 translation lag over the first 24 hours. This becomes the baseline for the ongoing alert threshold. If the initial p99 is 120ms, the alert threshold is 500ms (a 4× buffer before escalation). Record the baseline in the runbook.
ACL approach comparison
| Approach | Domain model isolation | Legacy version tolerance | Testability | Operational complexity |
|---|---|---|---|---|
| IBM ACE shared ACL flow | Full: domain services have no legacy knowledge | Built-in: version routing in the flow, all consumers benefit from updates | High: deterministic ESQL is straightforward to unit-test | Low: one BAR per domain; central DLQ; single deployment unit |
| Per-service adapter (direct legacy access) | None: each service translates its own legacy fields | Fragmented: each service handles legacy versions independently | Low: translation logic embedded in service business code | High: N services must each handle the legacy version upgrade |
| ACL inside domain service (DDD in-process) | Partial: translation code isolated within the service, but schema tied to it | Poor: each service independently updates for a legacy schema change | Medium: easier to unit-test than adapter pattern, harder to test cross-service | Medium: no shared deployment, but each service team owns the mapping |
| ETL / data pipeline (batch) | Full for query scenarios; none for real-time event scenarios | Good for batch windows; unacceptable for real-time notifications | High: SQL or Spark transformations are testable | Low for batch; high for maintaining both real-time and batch paths |