Roadmap › Microservices & System Design with .NET › Module: Architecture Styles
Lessons in this course (9)

2. Finding service boundaries with Domain-Driven Design

Intermediate★ Must knowLesson 2 of 9

Split by business capability, not by technical layer (never "a database service" + "a UI service").

DDD vocabulary interviewers use:

TermMeaningExample
Bounded contextA boundary in which a model and its language are consistent"Customer" means different things in Sales and Support
Ubiquitous languageShared terms between developers and businessOrder, Shipment, Invoice
AggregateCluster of objects changed together with one root enforcing rulesOrder (root) + OrderLines
Domain eventSomething that happened in the domainOrderPlaced, PaymentFailed
Anti-corruption layerTranslator protecting your model from another system's modelAdapter over a legacy ERP
csharp
public class Order   // aggregate root: all changes go through it so rules are always enforced
{
    private readonly List<OrderLine> _lines = [];
    public IReadOnlyList<OrderLine> Lines => _lines;
    public OrderStatus Status { get; private set; } = OrderStatus.Draft;

    public void AddLine(int productId, int qty, decimal price)
    {
        if (Status != OrderStatus.Draft) throw new InvalidOperationException("Order already submitted");
        if (qty <= 0) throw new ArgumentOutOfRangeException(nameof(qty));
        _lines.Add(new OrderLine(productId, qty, price));
    }
}

Good boundary signals: high cohesion inside, few calls across, data owned by one place, a team can own it end to end.