Title here
Summary here
A command message is a type of message that asks a specific receiver service to perform an action — such as CREATE_ORDER, RESERVE_STOCK, or CREATE_SHIPMENT. Its payload carries all the inputs the receiver needs to execute that action, much like the body of an HTTP API call, except delivered through a message broker.
Unlike an event message (which broadcasts a past fact to whoever is interested), a command message is directed at one target service and expresses future intent in the imperative mood.
{
"type": "CREATE_SHIPMENT",
"orderId": "order_42",
"recipient": "Asha Rao",
"address": {
"street": "14 MG Road",
"city": "Bengaluru",
"postalCode": "560001"
},
"items": [
{ "sku": "BOOK-01", "qty": 2 }
]
}Commands generally fall into two categories:
CREATE_ORDER, DEBIT_ACCOUNT, INITIATE_DELIVERY). Write commands should be paired with an idempotency key (messageId or orderId) so retries never execute the mutation twice.GET_ORDER or CHECK_STOCK). Query commands almost always expect a document message back on a reply channel.CREATE_SHIPMENT write command to a delivery queue and immediately confirms the order to the customer — removing temporal coupling between Order and Delivery.replyTo queue and correlationId in the header, and the receiver sends back a document message carrying the result or acknowledgement.RESERVE_STOCK, CHARGE_PAYMENT, CREATE_SHIPMENT) and sending compensating commands (RELEASE_STOCK, REFUND_PAYMENT) if any step fails.
Naming matters because it sets expectations between teams:
CREATE_ORDER sound like an unconditional command.A clean rule of thumb from the sender’s point of view:
| Dimension | Command Message | Event Message |
|---|---|---|
| Intent | Tell a receiver to do something (CREATE_SHIPMENT) |
Announce something that already happened (OrderCreated) |
| Target | One specific owning service (point-to-point queue) | Zero, one, or many subscribers (pub/sub topic) |
| Coupling | Sender knows which downstream capability it is invoking | Sender has no knowledge of who listens (lower domain coupling) |
| Can be rejected? | Yes — receiver validates and may reject | No — an event is a historical fact |
| Saga style | Orchestration sagas | Choreography sagas |
messageId or a natural business key (like orderId) ensures the receiver does not create duplicate shipments or double-charge a customer.