I wanted to see how small these ideas could get while still being executable, so I built a minimal Python reference implementation.
It uses four synthetic data products to explore how explicit contracts, quality checks, publication boundaries, and dependency lineage can be expressed in plain code.
This article walks through the design decisions, the failure scenarios covered by the tests, and what a production implementation would still need.
The boundary that makes a domain product meaningful
Consider two producing domains: Customer publishes customer profiles and Sales publishes order lifecycle records. An Analytics domain consumes both to create a business performance product. Sales also produces a simple order-volume feature by consuming its own order records alongside the published customer product. Rather than allow every consumer to read unvalidated internal records, each producer has a declared contract and an explicit publication step.
The four data products in the example are:
| Product | Owning domain | Inputs | Intended output |
|---|---|---|---|
|
| Customer | Synthetic customer fixture | Customer identifiers, segments, update times |
|
| Sales | Synthetic order fixture | Order identifiers, amounts, states, event times |
|
| Analytics | Published customer and order products | Completed-order count and revenue per customer |
|
| Sales | Published customer and order products | Completed-order count per customer for the bounded fixture |
This is the dependency structure implemented by the project:

The important boundary is not the diagram itself. Each downstream product requests its inputs through the catalog's published interface, and the catalog checks the consumer domain against a declared allowlist. This models an architectural intention: consumers should depend on stable interfaces rather than the producing domain's private implementation. In the present code, a caller supplies its domain as a string, so this is an allowlist simulation, not authenticated access control. A production implementation would have to bind identity to a real enforcement mechanism.
Data contracts need more than a schema
A schema can say that an amount is numeric and a timestamp is a string. A usable data-product contract needs to carry more context: who owns the data, who may consume it, which fields must be present, how freshness is defined, and which records must be unique. The contracts in this example declare those properties in JSON.
For example, the order-lifecycle contract declares order_id as a unique key, sets a non-negative minimum for amount, and uses event_time for a bounded freshness check. One part looks like this:
{ "product_id": "sales.order_lifecycle", "domain": "sales", "quality": { "min_rows": 1, "unique_key": ["order_id"], "freshness_field": "event_time", "max_age_days": 14, "minimums": { "amount": 0 } } } Those assertions give a concrete meaning to publishable data. Here, a data product should not be published if it contains a duplicate order identifier, a missing required amount, a negative amount, or an event timestamp outside its freshness window. The contract is versioned, and a separate compatibility helper flags certain breaking changes, such as removing a field or changing its declared type. That helper is deliberately narrow. A real compatibility review would also look at nullability, accepted value ranges, business semantics, and who is consuming the data.
The code validates the entire candidate batch before writing the published file. The core publication rule is simple:
errors = validate(contract, proposed_rows, as_of) if errors: raise GovernanceError("; ".join(errors)) # Only validated rows reach the published interface. Validated content is written to a temporary file and then moved into place, so a rejected batch never replaces the previously published file. It is a nice property to demonstrate, but it is not a distributed transaction, a streaming checkpoint, or atomicity across multiple products.
A reproducible example
The fixtures are deliberately tiny: three customer records and four order records. Customer C101 has two completed orders totaling 110.50 and a third pending order that is excluded. Customer C102 has one completed order worth 125.00, while C103 has no orders.
These numbers come straight from the sample rows. They are not enterprise-scale results. A successful run publishes the two source products, computes the analytics product, computes the sales feature, and writes a report with the product dependencies and impacted downstream products.
Run it from the repository root using Python 3.10 or later:
PYTHONPATH=src python -m domain_companion PYTHONPATH=src python -m unittest discover -s tests -v For Windows PowerShell:
$env:PYTHONPATH="src" python -m domain_companion python -m unittest discover -s tests -v The generated run/run_report.json shows which products were published and lists their dependency edges. The input timestamp is pinned to 2026-11-01T12:00:00Z, so if you rerun the example months from now, the freshness checks still behave the same way. There is no live ingestion or continuously running service here.
The unit tests cover the happy path and several ways things can go wrong:
| Failure or behavior | Expected behavior in the example |
|---|---|
| Missing required amount | Validation rejects the candidate batch |
| Negative order amount | Contract minimum rejects the candidate batch |
| Duplicate order identifier | Uniqueness check rejects the candidate batch |
| Stale or future event timestamp | Freshness check rejects the candidate batch |
| Wrong declared producing domain | Publication is rejected |
| Unlisted consuming domain | Published-product access is denied in the simulation |
| Invalid replacement batch | Previously published file remains unchanged |
| Valid synthetic flow | Four products publish; dependencies and impact are recorded |
A passing test here tells you a failure case was thought about. It does not tell you a production platform is safer under concurrent writes, identity compromise, partial infrastructure failures, or adversarial data. Keep that gap in mind.
Lineage should answer a question
Lineage is often presented as a graph of jobs and tables. That graph helps operations, but a platform consumer usually has a sharper question: if the Customer Profile contract changes, which published products could break? The sample catalog stores dependencies as directed edges between declared data products and calculates the full downstream set.
In this graph, a change to customer.customer_profile can affect both analytics.business_performance and sales.order_volume_feature. This is product-level declared lineage, not field-level provenance. It cannot tell you which source record produced a specific downstream value, or trace a model prediction back to its training examples. Still, a product-level graph is a practical hook for design-time impact checks, change review, test selection, and eventually notifications.
A natural next step would be to combine that declared graph with runtime lineage collected from actual executions. The two answer different questions. The declared graph captures intended interfaces, while observed lineage can reveal unexpected coupling or someone quietly bypassing a contract. Comparing the two is an interesting problem in its own right, because there is no reason to assume they always agree.
Where this fits in an enterprise data stack
The example is small enough to run without Snowflake, Spark, dbt, Airflow, or a model serving platform. That is on purpose. Stripping away the tooling makes the responsibilities visible before you assign them to any specific technology. In a real deployment, those responsibilities would be spread across several services.
The contract could live alongside a data product’s version-controlled definition, with validation running as part of a CI/CD or data-quality workflow. A catalog would need durable metadata, identity-aware access policies, audit logs, and ownership and lifecycle management. Published data might sit behind versioned tables, views, APIs, or events, while lineage could pull from orchestration events and query-level provenance. The validation boundary would also need transactional publication semantics that fit the storage engine.
ML features add another layer. It is not enough for a feature to have an owner and a type. Its definition should spell out time windows, leakage constraints, training/serving consistency, and when its meaning is allowed to change. In this example, the completed_order_count_30d name is only illustrative. It counts completed orders present in the bounded input, not a true rolling 30-day window. Making that window real, and testing it against late-arriving events, would be a worthwhile next step.
How I’d test whether this holds up at scale
A small reference implementation is useful because it makes assumptions explicit, but it is not a benchmark. To really know whether this approach pays off, you would need to compare at least two equally capable architectures under a controlled set of failures, with reproducible datasets, a declared workload, and evaluation metrics agreed on up front.
I would test four dimensions:
- Containment: When invalid, stale, or schema-incompatible records appear, what fraction reach a downstream published product?
- Change impact: How accurately and quickly can the system identify downstream consumers affected by schema and semantic changes?
- Recovery: After a failure, how long does it take to restore a correct published state without introducing duplicates or inconsistent versions?
- Operational cost: What latency, infrastructure overhead, and engineer effort does enforcing contracts and lineage add compared with a baseline?
An honest experiment should also show where this approach hurts. Overly strict contracts can block legitimate changes, lineage can be incomplete, and validation can become a bottleneck. Shared data, a clear failure-injection protocol, and a fair baseline would let others weigh those trade-offs for themselves instead of taking an architecture on faith.
A concrete starting point
Domain ownership becomes useful in practice when a product has an identified publisher, a documented interface, a clear validity condition, and a way to see what depends on it. This example turns those ideas into code and tests you can read, run, and argue with. It is not trying to pass a handful of JSON files off as an enterprise platform. It is a starting point for the conversation.
The code and tests are on GitHub if you want to break it yourself: https://github.com/akshaysharma1088/domain-driven-ai-research-companion
Reference(s)
Dehghani, Z. (2020). Data Mesh Principles and Logical Architecture.