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.

Document message in a CDC pipeline: Orders DB streams row changes through a CDC Connector as entity snapshots into a Document Topic, which syncs a Search Index and an Analytics Store Document message in a CDC pipeline: Orders DB streams row changes through a CDC Connector as entity snapshots into a Document Topic, which syncs a Search Index and an Analytics Store
Document messages in a Change Data Capture (CDC) pipeline syncing downstream read stores · Made with Akriti

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_42 arrive out of order, a monotonic version field 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).
Why use Change Data Capture (CDC) with document messages instead of querying the database directly? Letting other services query or read your database directly creates common coupling and competes for database CPU/IO. Streaming document messages through a broker isolates the operational database and lets search, caching, and analytics consumers scale independently.
Are document messages only used in asynchronous queues? They are most commonly discussed in asynchronous messaging (Kafka topics, RabbitMQ queues, SQS), though the same concept applies whenever a reply message carries a data payload back to a requester.