Skip to content
Latchkey

What Is a Command Handler?

A command handler is a unit of code that accepts a single command object expressing an intent to change state and carries out that change. It validates the request, loads the relevant aggregate, applies business rules, and persists the result. Each command type typically maps to exactly one handler.

Why it matters

Isolating each write operation in its own handler keeps business logic focused and testable. It is a core building block of CQRS, where the write side is modeled separately from reads.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →