Message Translator
A Message Translator converts messages between incompatible formats or schemas so systems with different data models can communicate without changing each other. It belongs at integration boundaries and underpins anti-corruption layers.
A Message Translator transforms a message from the format expected by the sender into the format expected by the receiver. It is the integration equivalent of an adapter: it lets two systems with different data models, schemas, or encodings exchange information without either having to change.
The problem it solves is representation mismatch. Independently built systems rarely agree on field names, structure, data types, or encoding. Rather than couple them by forcing a shared model, a translator sits between them and rewrites each message so it conforms to the recipient's expectations.
How It Works
The translator reads an incoming message, maps its fields and structure to the target model, and emits the converted message. Translation can operate at several levels: data type (string to date), data structure (flat to nested), data representation (XML to JSON, Avro to Protobuf), and transport encoding. A complex transformation may chain several translators, each handling one level.
Declarative tools — XSLT, JSONata, mapping DSLs in Camel or MuleSoft — express transformations as configuration. The translator must not embed business decisions about routing or content selection; those belong to other patterns.
{ "first":"A", "last":"B" } --> [Translator] --> { "name":"A B" }
When to Use It
Use it whenever a producer and consumer disagree on format, when integrating legacy systems with modern services, when adapting third-party APIs, or when migrating between protocols such as REST to GraphQL or WCF to gRPC. It is essential at integration boundaries and in anti-corruption layers.
Avoid scattering translation logic; concentrate it at boundaries so internal models stay clean.
Trade-offs
Translation adds a processing step and a maintenance point that must track both schemas; when either side changes, the mapping may break, so version schemas and test mappings thoroughly. Lossy transformations can silently drop data. Centralized translation aids clarity but can become a bottleneck. The benefit is strong decoupling: each system keeps its natural model.
Related Patterns
A Content Enricher adds missing data during translation; a Content Filter removes unwanted fields; a Normalizer translates many input formats into one canonical form. The Anti-Corruption Layer uses translators to protect a domain model from foreign concepts.
Example
An integration receives partner orders as XML and must call an internal JSON REST service. A message translator implemented in XSLT plus a JSON mapping converts each order, renaming fields and restructuring nested elements, so neither the partner nor the internal service needs to know about the other's format.