What is an aggregate responsible for in an event-sourced Axon application, and why is it described as the one authority for its domain concept?
An aggregate is the single place in the system responsible for deciding whether a command touching a given entity — one customer, one account, one loan — is valid, and it is the only thing allowed to say a command can proceed by applying an event. All the business rules about that entity live inside its aggregate class's command handlers, and nowhere else is permitted to change that entity's state directly. This concentration matters because it gives the codebase exactly one place to look when asking under what conditions a given change is allowed, instead of that logic being scattered across controllers, services, and database constraints. Each aggregate is also scoped narrowly to one kind of entity — a CustomerAggregate does not enforce loan rules — keeping each aggregate's responsibility small and its event history focused purely on that one entity's lifecycle.
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