DDD Tactical Patterns: aggregates as transactional consistency boundaries, entities with identity, immutable value objects, domain events for cross-aggregate eventual consistency, repository pattern abstracting persistence, factories, application/domain/infrastructure layers. Order aggregate (root + items + Money/Quantity VOs) shows transactional unit; OrderPlaced event triggers Shipment aggregate update in separate TX. Includes scenarios for happy-path aggregate transaction, cross-aggregate via event, repository load/save, and god-aggregate anti-pattern.
Tactical DDD — это набор modelling building blocks, а не шаблон ORM. Entity имеет identity, Value Object определяется значением, Aggregate защищает выбранные invariants внутри consistency boundary, Repository скрывает retrieval/persistence aggregate, а Domain Service нужен для поведения, которое естественно не принадлежит одному объекту.
| Компонент | Ответственность |
|---|---|
| Application Command Handler | Оркестрирует use case, transaction и retry policy без присвоения domain invariants. |
| Order Aggregate | Проверяет synchronous invariants и меняет state через root. |
| Money Value Object | Сохраняет amount/currency semantics и value equality. |
| Aggregate Repository | Загружает/сохраняет aggregate с optimistic version. |
| Transactional Outbox | Коммитит integration intent в той же local transaction. |
| At-Least-Once Relay | Повторяет publish до подтверждения и допускает duplicates. |
| Integration Event Topic | Передаёт versioned facts между bounded contexts. |
| Idempotent Billing Consumer | Deduplicate по event identity и ведёт reconciliation. |
The handler loads one Order version, the aggregate verifies currency, remaining refundable amount and state transition, then repository commits aggregate and event intent together.
Проверяемый исход: Invalid refund/charge state is rejected before any externally visible effect.
Two commands load version 7. One commit advances to 8; the second compare-and-set fails and must reload/re-evaluate business rules.
Проверяемый исход: A lost update is not silently accepted, and retry does not bypass invariants.
A committed outbox row survives a process crash. The relay can publish the same event more than once when acknowledgement is lost; the consumer records event identity atomically with its effect.
Проверяемый исход: No commit-then-publish loss; duplicates are expected and contained by idempotency.
A process spanning Order and Billing uses durable state, compensation and reconciliation. It does not pretend the aggregate transaction covers a remote payment provider.
Проверяемый исход: The state machine exposes pending/failed/compensated outcomes and never calls eventual consistency a hard money invariant.
Числа здесь — размерностные формулы или явно помеченные учебные inputs. Паттерн архитектуры сам по себе не задаёт SLA, throughput, latency или fault tolerance.
Tactical patterns protect only explicitly modelled local invariants. Remote payments, messages and cross-aggregate workflows retain partial-failure, replay and compensation semantics.
Введите числа или выберите пресет