Applying Domain-Driven Design: Concepts, Architecture Evolution, and the Four Bounded Context Layers
This article explains how to start a new project using Domain‑Driven Design, covering terminology, the evolution from SaaS to IaaS, bounded‑context concepts and division rules, the four DDD boundaries, and how clean, hexagonal, and onion architectures realize these principles for scalable backend systems.
We have all heard of DDD (Domain‑Driven Design) and now explore how to partition and architect a brand‑new project from scratch following the DDD process.
1. Terminology
IAAS: Infrastructure‑as‑a‑Service PAAS: Platform‑as‑a‑Service SAAS: Software‑as‑a‑Service
2. Architecture Evolution
The diagram shows the evolution from a monolithic SaaS application, where business logic is tangled, to a layered approach (MVC, SSM) that decouples services. As business grows, PAAS introduces shared technologies such as mesh, SOA, and micro‑services to isolate subsystems. When load increases, IAAS brings multiple servers, containers, Docker, and Kubernetes to abstract the underlying OS.
3. Bounded Context
A bounded context (BC) corresponds to a domain, module, or business area. For example, in an order system the "order" is one sub‑domain, while "inventory" is another. The same entity (e.g., product) can have different meanings in different contexts.
BCs relate to technology: when multiple BCs need to interact, the application layer aggregates them, often requiring synchronous calls (e.g., order‑to‑inventory) or asynchronous messaging middleware.
Division rules: first consider team size to avoid overly fine‑grained BCs that increase deployment overhead; then split by semantic relevance, functional direction (business‑related vs. non‑business), and finally obtain a set of BCs.
4. Four‑Layer DDD Boundaries
1️⃣ First boundary: define vision, goals, problem space, and identify core, generic, and supporting sub‑domains. 2️⃣ Second boundary: bounded contexts act as process‑level isolation. 3️⃣ Third boundary: within each BC, apply layered architecture (interface, application, domain, infrastructure). 4️⃣ Fourth boundary: use aggregates in the domain layer to keep domain models consistent.
5. Clean Layered Architecture
The clean architecture separates implementation from interfaces, keeping the domain layer independent of any framework. Business logic resides in the domain, while infrastructure can be swapped without affecting the domain services.
6. Hexagonal Architecture
Active adapters handle input (UI, CLI) while passive adapters deal with external services (databases, message queues). All interactions go through defined ports, ensuring the core application remains isolated from technical details.
7. Onion Architecture
The onion model refines the hexagonal approach by further separating the application service layer, domain service layer, and domain model layer. It emphasizes interface‑driven design, inward‑directed dependencies, and the ability to compile and run the application code independently of infrastructure.
8. Summary
Domain‑Driven Design is a widely adopted architectural style. By following its four bounded‑context layers, teams can achieve strong domain decoupling, facilitate vertical business expansion, and support horizontal feature scaling with a solid foundation.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.