Domain-Driven Design: Separate Ways, when it is better to keep Bounded Contexts independent.
Learn to decide when not to integrate two contexts. Compare Sales discounts and Marketing incentives with TypeScript, evaluate costs and duplication, and document independence along with its boundaries and review conditions.
The indicator keeps the furthest percentage explored; marking the article complete is your choice.
Two discounts that do not represent the same decision
Sales needs to calculate a commercial reduction applied to an order. Marketing needs to estimate how much budget to allocate to incentives while planning a campaign.
Both teams have a function with numbers, percentages, and limits. During code review, someone proposes creating a global discount service: “If they do the same thing, let's share the implementation.”
But they do not do the same thing. Sales decides how much can be discounted from an actual sale. Marketing compares internal scenarios that are not yet customer offers.
Unifying these rules can cause a campaign adjustment to change order amounts or a new commercial condition to block a simulation. In this case, accepting some code similarity may be less costly than maintaining an artificial dependency.
That is the kind of decision we will study with Separate Ways.
What choosing separate ways means
Separate Ways proposes not establishing an integration when the relationship between capabilities is not important enough to justify it. Contexts solve their needs independently, with solutions suited to their scope.
Evans notes that integration has a cost and the benefit may be small; when functionalities have no significant relationship, keeping them separate allows specialized solutions. DDD Reference: Separate Ways, page 37 of the document.
It is not permission to ignore shared processes. It is a decision based on exchange or coordination not being necessary for the capability being analyzed.
In our example, the scope is order discount calculation versus internal incentive estimation. We are not claiming that the entire Sales and Marketing organization has no relationship.
Sales Marketing
Order discount Incentive estimate
Commercial rules Planning rules
Local tests Local tests
No global service or exchange between these calculations.
The absence of an arrow is deliberate. If we discover that Marketing's results must be applied in Sales, the map must reflect that dependency.
Independence does not mean two servers
Modules can live in the same Node.js application or repository. They do not need microservice deployments to maintain independent models and rules.
They can also share technical infrastructure, such as compilation tools, without thereby sharing a discount policy.
What we are reviewing here is dependency between business models and decisions. Sharing a process does not prove domain integration exists; separate processes do not prove conceptual autonomy either.
The service needs to know who calls it. baseAmount may mean order subtotal or budget per person, and maximum may represent limits with different units.
The generalization has not found a common rule. It has placed two decisions under an imprecise signature.
As needs change, parameters such as campaignMode, customerSegment, or applyOrderMinimum will appear. Each team must check that its changes do not affect another team's branch.
The problem is not having a conditional. It is creating a point of joint evolution without a business responsibility to justify it.
Check whether independence is possible
Before separating, we verify these store assumptions:
Sales can calculate the order discount without reading campaigns.
Marketing simulates incentives using a budget and audience entered for planning.
The simulation does not generate redeemable coupons or promise customer discounts.
Neither calculation requires the other to produce the same result.
The owners accept that their rules evolve for different reasons.
If the third point is not met, the case changes significantly. A campaign announced to customers can commit Sales' behavior even if there is no API today.
The Separate Ways decision cannot hide that obligation behind a spreadsheet or manual exchange.
Sales' local model: discount on an order
For this example, Sales agrees on a specific rule:
For orders of at least 100 euros, apply a 10% discount with a maximum of 20 euros. Round the discount down to the cent.
This is not a universal commercial recommendation. It is an invented policy to show where the rule belongs.
The input limit is an example decision to bound the calculation. The function works only in EUR cents and does not calculate taxes or combine other promotions.
For a subtotal of 20,000 cents, it returns a 2,000 discount and 18,000 payable.
The result can be used when preparing an order, but does not implement acceptance or persistence. Sales must retain accepted conditions according to its process, without recalculating historical orders using future policy versions.
Marketing does not import this function or need the minimum purchase amount to plan its budget.
Marketing's local model: estimating an incentive
Marketing is comparing internal scenarios. Its rule is:
Distribute a budget among an expected audience, with a maximum of 10 euros per person. The incentive is expressed in whole cents and cannot exceed the budget.
With a budget of 50,000 cents and 500 expected people, the estimated incentive is 100 cents per person. It is a planning allocation, not the value of an issued coupon.
If the budget does not cover one cent per person, the result is zero. The function does not guarantee conversions, actual spending, or audience response.
Sales does not need to call this simulation to apply its commercial discount. Marketing can modify its planning limit without changing order amounts.
This independence is the important decision; the functions could share arithmetic operations and still express different knowledge.
Module structure and local tests
A simple organization:
src/
sales/
order-discount.ts
order-discount.test.ts
marketing/
campaign-incentive.ts
campaign-incentive.test.ts
No rule imports between the two modules.
No global discount package.
We have not implemented endpoints or storage because neither operation requires integrating both contexts. Adding them merely to demonstrate architecture would contradict the objective.
The following are examples of unit tests using Node.js built-in APIs. They assume TypeScript compilation to JavaScript ESM. They have not been run as part of the article.
Sales tests explain its policy
import test from"node:test";
import assert from"node:assert/strict";
import { calculateOrderDiscount } from"./order-discount.js";
test("no descuenta por debajo del mínimo comercial", () => {
assert.deepEqual(calculateOrderDiscount(9_999), {
discountCents: 0,
payableCents: 9_999,
});
});
test("aplica el porcentaje desde el mínimo incluido", () => {
assert.deepEqual(calculateOrderDiscount(10_000), {
discountCents: 1_000,
payableCents: 9_000,
});
});
test("limita el descuento a veinte euros", () => {
assert.deepEqual(calculateOrderDiscount(30_000), {
discountCents: 2_000,
payableCents: 28_000,
});
});
test("rechaza fracciones de céntimo", () => {
assert.throws(() =>calculateOrderDiscount(100.5));
});
Marketing tests explain its estimate
import test from"node:test";
import assert from"node:assert/strict";
import { estimateCampaignIncentive } from"./campaign-incentive.js";
test("reparte el presupuesto entre la audiencia prevista", () => {
assert.deepEqual(estimateCampaignIncentive(50_000, 500), {
incentivePerPersonCents: 100,
estimatedSpendCents: 50_000,
unallocatedBudgetCents: 0,
});
});
test("conserva el presupuesto que excede el límite por persona", () => {
assert.deepEqual(estimateCampaignIncentive(50_000, 10), {
incentivePerPersonCents: 1_000,
estimatedSpendCents: 10_000,
unallocatedBudgetCents: 40_000,
});
});
test("deja sin asignar los céntimos del reparto indivisible", () => {
assert.deepEqual(estimateCampaignIncentive(101, 3), {
incentivePerPersonCents: 33,
estimatedSpendCents: 99,
unallocatedBudgetCents: 2,
});
});
test("no calcula una asignación con audiencia cero", () => {
assert.throws(() =>estimateCampaignIncentive(50_000, 0));
});
We do not need a test forcing both models to produce the same amount. They do not represent the same decision.
It is useful to check dependencies to prevent one module from eventually querying the other for convenience. Folder structure expresses intent; imports and actual flows show whether it is maintained.
Technical duplication and knowledge duplication
A repeated operation does not prove there is a shared rule.
Technical duplication: both modules validate integers or perform division. Accepting a few local lines may be reasonable, or using a stable technical utility if one already exists and adds value.
Apparent business duplication: both speak of “discount,” but one modifies an order while the other estimates budget. Sharing code can conceal that the decisions differ.
Duplication of the same knowledge: both must apply exactly one approved policy, with the same meaning and necessarily consistent changes. Here independence needs reconsideration.
Do not turn Separate Ways into an argument for unlimited copying. If an important correction must always be repeated in several places for the same reason, investigate whether there really is shared knowledge.
Nor use “avoid code duplication” as sufficient reason to create a remote call. The cost of that dependency may exceed maintaining two small functions.
Evaluate the full integration cost
Before extracting a common service, compare two concrete alternatives: keeping rules local or introducing a shared dependency.
Business benefit
Which error or work is eliminated? Which new capability appears? In our example, neither function needs to produce the same result, so the benefit of a single rule is doubtful.
Development and maintenance
Integration requires a contract, compatibility, consumer tests, and owners for its changes. A shared library avoids some transport, but retains coordination over behavior.
Independence also costs: separate tests, review of each policy, and possible repetition of technical improvements. Do not present it as free.
Availability and performance
If order calculation queries a campaign service, Sales may depend on its availability to sell. What it obtains in return must be justified.
The example's local functions do not add that runtime dependency, although they still depend on their own environment.
Evolution and coordination
Can Marketing test another strategy without requesting Sales changes? Can Sales modify the minimum discount threshold without reviewing simulations?
Autonomy adds value when those decisions really belong to different owners. If both must maintain the same customer promise, coordinating them is no longer optional.
There is no need to invent savings percentages. If there are no measurements, identify expected costs, uncertainties, and evidence that would allow comparison.
Document the decision without making it an eternal prohibition
This is a brief architectural decision example, not a decision observed in an actual repository.
Context
Sales applies order discounts. Marketing runs internal budget simulations. No campaign issues redeemable benefits through these functions.
The policies have different objectives and owners.
Decision
Keep calculations and tests independent. Do not create a global discount service or import rules between Sales and Marketing for these capabilities.
Alternatives considered
Common discount package: would reduce some repeated lines, but impose joint evolution on different rules.
Remote campaign service: would add availability, contracts, and coordination without a current need for exchange.
Consequences
Each team can evolve its calculation within its responsibility. Some technical duplication and the obligation to maintain local tests are accepted.
No consistency is promised between a Marketing estimate and a Sales discount because they do not represent a shared offer.
Review conditions
Review if Marketing starts issuing coupons, if a campaign advertises discounts Sales must honor, or if a monetary policy appears that both must apply exactly.
The decision must have owners and be reviewed under those conditions. It does not need an invented date to seem complete.
When Separate Ways stops being appropriate
An advertised promotion must be honored
If Marketing promises 15% on eligible purchases and Sales must apply it, a business relationship exists. It cannot be ignored because the teams prefer independence.
Establish who defines the promotion, how it is interpreted, and how its application is verified. The specific mechanism is decided afterward; the coordination need already exists.
There is master data or decisions with common authority
If both processes need the same official customer, product, or commercial-condition reference, identify the owner and necessary guarantees.
Local copies may be a technical strategy, but if they must be populated and maintained from a common source, an integration exists and must be documented.
Compliance obligations exist
An applicable obligation may require consistency, traceability, or coordination between processes. First determine the actual requirement with its owners; do not assume the pattern allows avoiding it.
Separate Ways does not mean each team independently invents the meaning of a shared obligation.
Manual exchange sustains the process
Someone copying rules from campaigns into the sales system maintains an operational connection even without an API.
The map must reflect it. Do not describe as complete independence something that relies on human synchronization to fulfill a promise.
Compare alternatives without mixing decisions
Shared Kernel: can help when a small part of the model has common meaning and joint governance. Here the rules differ and do not justify that commitment.
Partnership: corresponds to a dependency of success requiring close collaboration. There is no need to create this relationship between two calculations that can meet their goals separately.
Customer/Supplier: establishes a negotiated dependency between supplier and consumer. It makes sense only when a capability must be consumed.
Anti-Corruption Layer: protects a model when integration exists and translation is needed. Separate Ways can avoid integration if its benefit is insufficient; it does not replace translation when exchange is necessary.
Published Language: defines how shared information is interpreted. If we do not need to exchange it, there is no reason to design a message merely to connect similar names.
The decision is not to find the most elaborate pattern. It is to recognize the relationship the business actually needs.
Two examples beyond commercial discounts
Education: stars and grades
An educational game displays stars for completing challenges. An academic record stores grades under institutional rules.
Although both use numbers and speak of performance, there is no reason to share a scoring calculator if neither capability requires equivalence between those results.
If challenges later grant academic credits, criteria and responsibility must be established. The new requirement changes the relationship; it does not justify having built it earlier by intuition.
Reservations: independence that would be false
A room system accepts reservations and another allows blocking those same spaces for maintenance. If both decide over the same physical time slots, they can generate real conflicts.
Creating two local calendars and claiming separate ways is not enough. There is a coordination need around availability.
This counterexample teaches looking for the shared resource or promise. Technical autonomy does not eliminate a business collision.
Ask AI to question automatic reuse
Cursor, Claude, or Codex may detect two similar functions and propose shared/discounts. That does not prove the abstraction is correct.
You can use these prompts:
To analyze:
Compare the discount applied to Sales orders and Marketing's internal incentive estimate. Identify objectives, units, rules, and reasons for change. Distinguish technical similarity from shared knowledge. Do not propose integration without a concrete business need.
To implement:
Keep functions and tests local in both contexts. Sales applies its commercial policy; Marketing only simulates budget and issues no redeemable benefits. Do not add cross-context imports, global packages, or remote calls to eliminate a few repeated lines.
To review a new need:
This campaign now promises benefits Sales must apply. Compare the requirement with the earlier Separate Ways decision. Identify which assumption no longer holds and which agreements are needed. Do not invent a complete architecture or claim independence remains valid unchanged.
A person must confirm whether there is a customer promise, shared resource, or common obligation. Code does not always contain all that information.
Exercises
1. Two formulas identical today
Sales and Marketing temporarily use 10%. A team proposes a single function because the numbers match. What information is missing?
2. A new coupon
Marketing starts sending codes Sales must accept under certain conditions. Can the previous decision remain without review?
3. The hidden common rule
Both contexts receive an official policy by email that must be applied without differences. Each team transcribes it into its code. Is this a good case of complete independence?
Reasoned solutions
1. What decision each formula represents, who maintains it, and whether it must change for the same reason are missing. Matching a percentage does not prove a common model.
2. No. An operational relationship appears between Marketing's promise and Sales' acceptance. Authority, conditions, and coordination must be defined, and the map and decision updated.
3. Not necessarily. Shared knowledge exists whose consistency matters, along with a connection through the policy distribution process. How to guarantee it must be analyzed; duplicating transcription can introduce divergence.
Maintain separate ways with explicit reasons
Separate Ways adds value when each context can fulfill its responsibility without an integration whose cost outweighs its benefit.
Check that independence does not conceal shared promises, resources, or rules; that calculations have different reasons to change; and that you know when to review the decision.
Accepting two small solutions may be clearer than sustaining a global abstraction. Independence is useful while it respects actual business needs.
Integrate the collection by building an order API with TypeScript, Express, Zod, and SQLite. Includes project files, domain rules, events, version control, Vitest tests, and commands to run and verify it locally.
Learn to guide AI agents with business rules, context boundaries, and verifiable criteria. A TypeScript case shows how to prepare instructions, protect Order, design tests, and review changes without delegating architectural judgment.
Compare a modular monolith with separating Sales, Payments, and Inventory. Design contracts in TypeScript and Express and understand partial failures, eventual consistency, idempotency, Outbox, and Sagas without introducing complex infrastructure.