© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
DOMAIN-DRIVEN DESIGN! / " OLIVERGIERKE
# [email protected]
FUNDAMENTAL
FOR MICROSERVICES
4
http://www.infoq.com/minibooks/domain-driven-design-quickly
Microservices ♥Domain-Driven Design
5
11:10 — Beethoven Saal
Implementing Domain-Driven
Design7
Stringly typed code9
public class Customer {
private Long id;private String firstname, lastname, email;
…}
Stringly typed code10
public class SomeService {
public void createUser(String firstname, String lastname, String email) {
…}
}
11
public class Customer {
private Long id;private Firstname firstname;private Lastname lastname;private EmailAddress emailAddress;
…}
Value Objects are aPITA to build in
some languages.
12
Still, they’re worth it.
13
See „Power Use of Value Objects in DDD“ by Dan Bergh Johnsson.
Lombok — putting the spice back into Java.
14
15
@Valuepublic class Customer {
UUID id = UUID.randomUUID();Firstname firstname;Lastname lastname;EmailAddress email;
@Valuestatic class EmailAddress {String value;
}}
AutoValue
16
Project website on GitHub.
Entities & Aggregates
17
18
Order
LineItem
Product
Invoice
CustomerPayment Address
Email
18
Order
LineItem
Product
Invoice
CustomerPayment Address
Email
Persistence technologyVS.
Domain model
19
Aggregate =Entity + Repository
20
21
Order
LineItem
Product
Invoice
CustomerPayment Address
Email
Bounded Context
22
Order
LineItem
Product
Invoice
CustomerPayment Address
24
Shipping
AccountingCatalog
Orders
UserRegistration
24
Shipping
AccountingCatalog
Orders
UserRegistration
Accounting Payment information
Billing Address
Shipping
Shipping address
Customer
Product
Domain-Driven Design &
Monoliths25
Avoid technologies that get in your way.
26
How to enforcecontext boundaries?
27
What aboutconsistency?
28
References between Bounded Contexts?
29
31
Level 0: No events at all
31
Level 0: No events at all
Level 1: Explicit operations
If you’re calling two setters in a row, you’re
missing a concept.
32
33
Level 0: No events at all
Level 1: Explicit operations
Level 2: Some operations as events
State transitionsbecome domain
events.
34
35
Level 0: No events at all
Level 1: Explicit operations
Level 2: Some operations as events
Level 3: Event Sourcing
Domain-Driven Design &
Microservices36
Bounded contexts define systemboundaries.
37
38
Shipping
AccountingCatalog
Orders
UserRegistration
Accounting Payment information
Billing Address
Shipping
Shipping address
Customer
Product
39
Shipping
AccountingCatalog
Orders
UserRegistration
Accounting
Shipping
40
Shipping
AccountingCatalog
Orders
UserRegistration
Accounting
Shipping
HTTP
Messaging
Architecture is lesslikely to deteriorate
as it’s harder toviolate boundaries.
41
Restructuringservice boundaries
is much harder.
42
Inter-Service communicationbecomes remotecommunication.
43
Accept and embrace eventual consistency
between services.
44
REST & Messaging
46
Domain eventsbecome state
transitions.
47
Hypermedia for state transition and explicit
events.
48