Domain-Driven Design (50 Qs)•Part 3: Advanced Architecture & Production Patterns (Senior / Lead)
The 4 Aggregate Design Rules by Vaughn Vernon.
senior LevelSystem Design
In Simple Words: Essential guidelines for high-performance, maintainable Aggregates:
- Rule 1: Model True Business Invariants: An aggregate boundary should encapsulate only data that must be strictly consistent within a single database transaction.
- Rule 2: Design Small Aggregates: Large aggregates cause severe optimistic locking conflicts and memory bloat. Prefer 1 Entity with a few Value Objects.
- Rule 3: Reference Other Aggregates by Identity Only: Never hold direct object references to other Aggregate Roots (use
customerId: CustomerId, notcustomer: Customer). - Rule 4: Update Other Aggregates Using Eventual Consistency: If updating Aggregate A requires modifying Aggregate B, use asynchronous Domain Events, not distributed multi-table transactions!