.NET Architecture & System Design Interview Question #119

What is the difference between an event and a command?

Microservices, API Gateway, Service Communication & Event-Driven Architecture Mid-Level Intermediate

Quick Interview Answer

A command expresses a request or intention for a specific action to occur, such as ChargePayment. An event describes a fact that has already occurred, such as PaymentCharged.

Detailed Explanation

A command expresses a request or intention for a specific action to occur, such as ChargePayment. An event describes a fact that has already occurred, such as PaymentCharged.

Commands usually have an intended handler and may be rejected. Events are historical facts and can have zero, one, or many subscribers. Naming them accurately helps communicate system semantics.

Code Example

Command:
ChargePayment

Event:
PaymentCharged

Intent != completed fact