ddd-cross-aggregate-constraints

Guides design decisions for cross-aggregate constraint checks in DDD and CQRS/ES architectures.

Updated Jun 23, 2026
One-click install
npx skills add https://github.com/j5ik2o/marp-ai-base --skill ddd-cross-aggregate-constraints-j5ik2o
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ddd-cross-aggregate-constraints
Source: https://github.com/j5ik2o/marp-ai-base/tree/main/.agents/skills/ddd-cross-aggregate-constraints
Command: npx skills add https://github.com/j5ik2o/marp-ai-base --skill ddd-cross-aggregate-constraints-j5ik2o

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When a use case on one aggregate needs to verify the state of another aggregate (e.g., "a brand with linked products cannot be deleted"), developers often reach for the wrong solution: misusing Sagas, letting the command side depend on read models, or building complex reverse-lookup indexes. This Skill provides a structured decision framework to question the requirement, reconsider aggregate boundaries, and choose an appropriate resolution strategy. ## Core Features & Use Cases - Requirement Re-examination: Challenges whether the cross-aggregate constraint is truly necessary, analyzing lifecycle implications and offering relaxation options like logical deletion. - Modeling Review: Detects when the constraint signals wrong aggregate boundaries (1:1 relationships should merge; pure query needs should become CQRS read models). - Saga Misuse Detection: Distinguishes legitimate Saga usage (distributed transaction coordination) from misuse (simple constraint checks). - CQRS/ES Technical Guidance: Explains why command-side code must not depend on read models, how to reference other aggregates via repositories or actor messaging, and the cost of reverse-lookup indexes on event stores. - Use Case: During a code review, you find a use case that queries a brand read model before creating a product. Use this Skill to identify the race condition risk and refactor toward command-side resolution or explicit eventual consistency. ## Quick Start Ask the AI to review whether checking another aggregate's state in this use case is the right design, and what alternatives exist.

Frequently Asked Questions about ddd-cross-aggregate-constraints

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I check another aggregate's state in a DDD use case?

Reference the other aggregate through its command-side repository or send it a message (e.g., actor model), but never update it in the same transaction. Reading is allowed; cross-aggregate writes in one transaction break aggregate consistency boundaries.

When should I use a Saga for cross-aggregate validation?

Never for simple constraint checks. Sagas coordinate multi-step distributed transactions with compensation on failure. A check like "does this brand have products" is a single validation, not a sequence of operations requiring rollback.

Can the command side query a read model in CQRS?

No, the command side must not depend on read models. Event propagation lag creates race conditions between the check and the command execution. Resolve constraints using command-side repositories or inter-aggregate messaging instead.

How do I find all products linked to a brand in event sourcing?

Event stores only support lookup by aggregate ID, so reverse lookups require a separate index read model updated on every product create, update, and delete event. This adds significant complexity, so first verify the business value justifies it.

When should two aggregates be merged into one?

Merge when they share a 1:1 relationship and must always change together in one transaction, such as a Task and its TaskReport. Keeping them in one aggregate makes invariant violations structurally impossible.

What inconsistencies must be accepted with CQRS and event sourcing?

Accept temporary inconsistency from event processing delays, orphaned data from failed compensations, and read model lag. Never accept inconsistency inside an aggregate, broken business rules, or permanent data divergence.