Back to Platform & Architecture
platform
DDD (Domain-Driven Design)
Bounded contexts, aggregates, ubiquitous language
DDD (Domain-Driven Design) — Overview
Bounded contexts, aggregates, ubiquitous language
DDD models complex domains with bounded contexts (Payment, Ledger, Fraud), aggregates (consistency boundaries), entities, value objects, and domain events. Microservices often map 1:1 to bounded contexts with Kafka for integration.
// Bounded Context: Payments
// Aggregate: Payment (root)
public class Payment { // Aggregate Root
private PaymentId id;
private Money amount;
private PaymentStatus status;
public void authorize(AuthorizationService auth) {
if (status != PaymentStatus.PENDING)
throw new DomainException("Already processed");
AuthResult result = auth.authorize(this);
this.status = result.isApproved()
? PaymentStatus.AUTHORIZED : PaymentStatus.DECLINED;
domainEvents.add(new PaymentAuthorized(id, result));
}
}
// Anti-corruption layer between contexts
public class LegacyCbsAdapter implements AccountPort {
// Translates domain model ↔ legacy CBS format
}Tip: Context map defines relationships: Partnership, Customer-Supplier, Anti-Corruption Layer between teams.