Messagingmedium3-5 years

A topic named `SendInvoiceEmail` is consumed by both the `email` service and an `audit` service. What's wrong with this design, and how do you tell an event from a command in general?

An event is a past-tense fact — InvoiceIssued — that any number of consumers can react to, with the producer indifferent to who's listening. A command is a request to do something — SendInvoiceEmail — addressed to exactly one handler, with the sender expecting that specific work to happen. SendInvoiceEmail on a topic with two consumers is a command pretending to be an event: the name is an imperative instruction, but two services are subscribed to it, and if audit ever "helps" by acting on it too, the customer gets two emails. The tell is in the name — an imperative verb with more than one consumer is the specific shape of this bug.

The lesson behind it →