Designing a system is hard, it’s even harder to build a distributed microservices style architecture…
Let's try and walk through a simplified example of carving our our entities, bounded contexts and carving out the processes on the road to building better applications.
https://www.youtube.com/watch?v=TowONOIRV_g
2. Monolith Design
Analyse the domain
Build a data model that describes the
domain
Add relationships and dependencies
@farmar2
3. Monolith Design
So we will have something like this:
@farmar3
Account
Id
IsClosed
OpenDate
Customer
Id
CustomerId
Phone
Address
LineItem
Id
Quantity
Price
Order
Id
OrderNumber
OrderDate
ShippingDate
OrderStatus
Id
OrderStatusName
Payment
Id
PaymentDate
Total
Product
Id
Name
Suplier
User
Id
UserName
UserStatus
Id
UserStatusName
New
Active
Blocked
Band
New
Hold
Shipped
Delivered
Closed
4. Monolith Design
Add a data layer
Add the Business Logic Layer
Build the UI
… don’t forget the kitchen sink
@farmar4
5. Monolith Design
And soon enough we end up with
a big ball of mud
@farmar5
Courtesy of The Daily WTF
8. Domain Driven Design - Bounded Context
Be explicit, Keep it clean
Keep the boundaries
Encapsulate
@farmar8
9. Find Single Units Of Work
Create a user login [UserAuthentication?]:
Email
Password
We may have an email account
verification process
Does access control belong here as well?
@farmar9
10. Find Single Units Of Work
Create a customer account:
UserAuthenticationId
[First Name]?
[Last Name]?
Account Active
@farmar10
11. Find Single Units Of Work
Create a customer contact details:
Contact Email (is that the logging email?)
Contact Phone number (optional?)
Home Address (optional?)
Email Validation Process
@farmar11
12. Find Single Units Of Work
Create a customer payment details:
Add one or more payment methods
Add Billing Address
Add payment methods process
(and validation)…
@farmar12
13. DDD and Bounded Context
It is not going to perfect
@farmar13
14. DDD and Bounded Context
@farmar14
UserAuthentication
CustomerAccount
CustomerPayment
CustomerContact
19. Summary
Use bounded context to slice your
verticals
Include the data in your vertical slicing
Keep your boundaries
Reduce coupling between bounded
contexts
@farmar19
20. Summary
Use asynchronous communication (for
state changes) between bounded contexts
CQS, SRP, Clean Code
Don’t forget your stakeholders, business
and developers should align to these
boundaries
It won’t be perfect, accept it
@farmar20
21. One more thing
Get free access to Advanced Distributed
Systems Design course with Udi Dahan
https://learn-
particular.thinkific.com/courses/DublinUG
@farmar21