Document Message in Messaging Systems
A document message is a type of message whose primary job is to transfer a structured data representation (a snapshot of an entity, record, or result) from one service to another. Unlike a command message, a document message does not dictate what the receiver must do with the data — it simply delivers the data cleanly and lets the receiver decide how to use it.
How Document Messages Work
In Enterprise Integration Patterns, a document message is the messaging equivalent of passing a data transfer object (DTO) or JSON/Avro record between systems. The sender guarantees the structure of the data; the receiver owns the business logic that reacts to it.
Example Document Message Payload (CDC Snapshot)
{
"entity": "Order",
"operation": "UPDATE",
"version": 4,
"before": {
"orderId": "order_42",
"status": "CONFIRMED",
"totalAmount": 49.90
},
"after": {
"orderId": "order_42",
"status": "SHIPPED",
"totalAmount": 49.90
},
"updatedAt": "2026-11-25T16:12:00Z"
}Common Use Cases for Document Messages
1. Change Data Capture (CDC) Pipelines
Tools like Debezium read a database’s write-ahead log (WAL) or binlog and emit a document message for every inserted, updated, or deleted row. Downstream systems — such as an Elasticsearch search index, a Redis cache, or an analytics data warehouse — consume those document messages to stay in sync without directly querying the source database (avoiding common coupling).
2. Responses in Asynchronous Request-Reply
When a service sends a query request message (such as GET_ORDER) over a broker, the answering service replies on the replyTo queue with a document message carrying the requested order details (tagged with the same correlationId from the message header).
3. Carrying State Inside an Event Message
In an Event with Detail (Event-Carried State Transfer), the embedded body of the event is effectively a document message representing the entity at the moment the event occurred — letting consumers update their local state without making synchronous callbacks back to the producer.
Document Message vs. Command vs. Event
| Dimension | Document Message | Command Message | Event Message |
|---|---|---|---|
| Primary focus | Data (entity state or query result) | Action (perform a task) | Occurrence (something happened) |
| Who decides what to do? | Receiver | Sender | Receiver |
| Timing sensitivity | Usually low (syncing state / replies) | Medium–high (workflow step) | Low (asynchronous reaction) |
| Typical example | CDC order row snapshot, GET_ORDER reply |
CREATE_SHIPMENT |
OrderCreated |
Best Practices and Pitfalls
- Version your document schemas: Because CDC tools can mirror raw database tables, renaming a column can silently break downstream consumers. Use a Schema Registry (Avro or Protobuf) or project rows into a dedicated public contract table/outbox rather than exposing raw internal tables directly.
- Include a version or timestamp: If two updates for
order_42arrive out of order, a monotonicversionfield lets receivers keep only the newer snapshot. - Avoid coupling to internal storage models: Exposing raw database tables directly via CDC can leak private columns and turn into a form of data-contract coupling. Publish only the fields downstream consumers actually need.
FAQs
How is a document message different from an event message?
An event message emphasizes that a domain occurrence happened (OrderShipped) and may carry only an ID. A document message emphasizes the data itself — transferring a complete record or query result (such as a CDC row snapshot or a reply to a GET_ORDER request).