Command (Request) Message in Messaging Systems

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.

How Command Messages Work

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.

Order Service sends a CREATE_SHIPMENT command to a command queue, and Delivery Service takes it from the queue Order Service sends a CREATE_SHIPMENT command to a command queue, and Delivery Service takes it from the queue
Fire-and-forget command: Order Service puts CREATE_SHIPMENT on a command queue and carries on; Delivery Service executes it, and no reply is expected · Made with Akriti

Example Command Payload

{
  "type": "CREATE_SHIPMENT",
  "orderId": "order_42",
  "recipient": "Asha Rao",
  "address": {
    "street": "14 MG Road",
    "city": "Bengaluru",
    "postalCode": "560001"
  },
  "items": [
    { "sku": "BOOK-01", "qty": 2 }
  ]
}

Types of Commands

Commands generally fall into two categories:

  • Write Command: Changes the state of the receiver service (for example, 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.
  • Query (Read) Command: Asks the receiver to return data without mutating state (for example, GET_ORDER or CHECK_STOCK). Query commands almost always expect a document message back on a reply channel.

Common Usage Patterns

  1. Fire-and-forget decoupling: In an order workflow, the Order Service sends a CREATE_SHIPMENT write command to a delivery queue and immediately confirms the order to the customer — removing temporal coupling between Order and Delivery.
  2. Asynchronous request-reply: As an alternative to synchronous HTTP calls, the sender publishes a request message with a replyTo queue and correlationId in the header, and the receiver sends back a document message carrying the result or acknowledgement.
  3. Orchestration-based Sagas: A central saga orchestrator drives a multi-step business transaction by sending explicit commands (RESERVE_STOCK, CHARGE_PAYMENT, CREATE_SHIPMENT) and sending compensating commands (RELEASE_STOCK, REFUND_PAYMENT) if any step fails.
Order Service sends a CHECK_STOCK request to a request queue; Inventory Service takes it and sends a stock document to a reply queue, which carries it back to Order Service Order Service sends a CHECK_STOCK request to a request queue; Inventory Service takes it and sends a stock document to a reply queue, which carries it back to Order Service
Asynchronous request-reply: a CHECK_STOCK query goes out on a request queue, and Inventory Service's answer, a document message, comes back on the reply queue the request named in replyTo · Made with Akriti

Command vs. Request: Which Name Makes More Sense?

Naming matters because it sets expectations between teams:

  • Names like CREATE_ORDER sound like an unconditional command.
  • Yet once you account for service autonomy, the receiver is always free to refuse the action based on its own business rules (out of stock, failed fraud check, invalid address) — which makes it behave like a request.

A clean rule of thumb from the sender’s point of view:

  • Call it a Command in fire-and-forget workflows, where the sender delegates the work to a queue and does not wait for an immediate response.
  • Call it a Request in request-reply workflows, where the sender explicitly expects an acknowledgement, result, or rejection back on a reply channel.

Command Message vs. Event Message

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

FAQs

When should I send a command message instead of an event message? Use a command message when you want explicit control over which service executes the next step (for example, an orchestration saga or a dedicated worker queue). Use an event message when multiple independent services may need to react without the sender knowing about them.
Why do write commands need idempotency? Because asynchronous messaging brokers typically provide at-least-once delivery. If a network glitch prevents an acknowledgement from reaching the broker, the broker redelivers the command. Checking messageId or a natural business key (like orderId) ensures the receiver does not create duplicate shipments or double-charge a customer.
Can a command message have multiple consumers? A command queue can have multiple worker instances of the same service competing to share load, so each command is delivered to one worker at a time. Redeliveries can still happen (see above), so handlers must be idempotent. It should not be broadcast to multiple different services — that is what an event message on a topic is for.