DEV Community

Cover image for Difference Between Message vs Event vs Command
Muhammad Ilham hidayat
Muhammad Ilham hidayat

Posted on • Updated on

Difference Between Message vs Event vs Command

Recently, I'm relearning event-driven architecture and publisher-subscriber systems. I often found words like message, event, and command. Those words can be confusing for someone who want to learn event-driven architecture. Even though they have many common elements, they have different purposes and different properties.

Message

Message is a request from one system to another contain a payload of all data required for processing. It can use a different format based on a contract that exists between two systems. A message has no special intent that makes it generic but also less meaningful. That's why we can use two more concepts on top of the messages.

Alt Text

Message is a generic form for command and event

Command

Command is a message from one system to another for an action to be taken. It represents a possible future and can be validated, approved, rejected, processed, and replied.

Alt Text

Sender send a command to receiver

Example:

Alice asked Bob to purchase an iPhone.

The key command is: Buy an iPhone

Event

An event is a message to inform something has already happened in the past. An event represents the past, and it never changes once it's happened. It's immutable, and we can't approve or reject events in the past.

Alt Text

Receiver send an event to notify sender

Example:

After receive a command from Alice, Bob go to Apple store and buy a new iPhone. Bob inform Alice he already purchased an iPhone.

The key event is: iPhone already purchased

Conclusion

  • Message is a generic request.
  • Command is a message to perform an action.
  • Event is a message to inform an action has been performed.

Source

Top comments (0)