Why can a command be rejected but an event cannot?
A command represents a request for something to happen, and requests can fail — the business rules might disallow it, so the command handler throws and nothing changes. An event, by contrast, represents something that has already, definitively happened; by the time an event object exists and is being processed, whatever it describes has already occurred and is now a permanent part of the system's history. Rejecting an event after the fact wouldn't make sense, because there's no request left to refuse. This is also why an @EventSourcingHandler method should never throw an exception for a business-rule reason: all decision-making about whether something is allowed happens earlier, in the command handler, before any event is ever applied.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response