Domain-Driven Design (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What is the difference between Domain Services, Application Services, and Infrastructure Services?
senior LevelCode ExampleSystem Design
In Simple Words: Three distinct service layers in DDD architectures:
- Domain Service: Pure business logic that spans multiple aggregates (e.g.
PricingEngineService). Zero dependencies on databases, UI, or frameworks. - Application Service: Orchestration layer (Use Cases). Coordinates domain objects, loads aggregates from repositories, manages transactions, and sends notifications (e.g.
CreateOrderCommandHandler). Contains zero domain business rules. - Infrastructure Service: Concrete technical adapters for external concerns (e.g.
SmtpEmailSender,PostgreSqlOrderRepository,S3FileUploader).
text
DDD Service Layers:
[Application Service (Use Case)] ──► Loads Aggregate from [Repository]
│
▼
[Domain Model / Domain Service] ──► Executes Pure Business Invariants
│
▼
[Infrastructure Service] ──► Writes to DB / Sends Email / Kafka