Designing systems architecture corresponding to business needs in long future is like a reading tea leaves. There is no common way to design systems. Making decision to start project with microservices may make refactoring much harder and introduce too much complexity in the infrastructure layer and finally slow down development. However maintaining a monolith is a tough nut to crack.
Let’s see how to build a system starting from well organized monolith with well marked technical and business scopes that enables to make a decision in with way it should be decomposed and how to deliver it. Strategic and tactical techniques from Domain-Driven Design and Hexagonal Architecture will be used. I will show you how to monitor accidential complexity using different tools during CI.
I invite you if you are interested in building systems with complex business domains.
16. System Architecture - Case
Accounts
Repo
Loans
Repo
Loans
Sales Process
Dep
#1
Dep
#2
Dep
#3
17. System Architecture - Solution 1
Accounts
Repo
Loans
Repo
Loans
Sales Process
Dep
#1
Dep
#2
Dep
#3
Dep
#4
Dep
#5
• if, if, if, if
• strategy pattern (hidden if), chain of responsibility
• more dependencies
18. System Architecture - Solution 2
Loans
Sales Process
Dep
#1
Dep
#2
Dep
#3
Dep
#4
Dep
#5
• Design new process and bring some stuff to common
The Next one Loan
Sales Process
C
#1
C
#1
C
#1Commons:
22. We are making mistakes
Let’s prepare for them better
23. Microservices hype
We know benefits
We know drawbacks
One Bounded Context = 1 µS
Do we split properly? Do we understand Business?
24. Why not Microservices at the beginning?
• YAGNI
• True: Hard to scale poor designed successful software
• But it is better than have failed software but well designed
• You need to be agile at the beginning
• Works good only with well separated Bounded Contexts
• You have to learn domain first
• Refactoring in monolith is much simpler than in microservices
https://martinfowler.com/bliki/MonolithFirst.html
35. 2. Know your domain
Event Storming – reveal domain by asking “what happened? when?”
Alberto Brandolini
https://techbeacon.com/introduction-event-storming-easy-way-achieve-domain-driven-design
36. 2. Know your domain - DDD
"Software development is a learning process;
working code is a side effect."
In monolith we can start with:
• Rich domain
• Pilled-off bounded contexts (high level packages)
38. 3. Encapsulate the domain
• On top-level packages expose what application do
• not how it is devlivered
• Use Case is Application Service
pattern from DDD
It orchestrates the domain
48. 4. Make gaps in domain
Port and Adapters
aka Hexagonal Architecture
49. 4. Make gaps in domain
• Ports (red)
• Adapters (blue)
• Out
• In
• I like “delivery” instead of
“in adapters”
http://www.dossier-andreas.net/software_architecture/ports_and_adapters.html
50. 4. Make gaps in domain
• Separates domain from dependencies
• Database
• Another Bounded Context
• Domain Services can map foreign domain
to our domain
• Forum Author instead of User
• Product parameters instead of Product from
catalogue
http://www.dossier-andreas.net/software_architecture/ports_and_adapters.html
60. 7. Peel-off edges
1. Move whole package to another service
• add delivery layer only
2. Change Use Cases invocations in Adapters to RPC
61. 7. Peel-off edges
public class AuthorFromUserService implements AuthorProvider {
public Author getAuthor(String nickname) {
User user = someUsecase.getUserByUsername(nickname);
Author author = //...
return author;
}
}
Old Use Case invocation:
62. 7. Peel-off edges
public class AuthorFromUserService implements AuthorProvider {
interface UserService {
@RequestLine("GET /users/{username}")
User getUserByUsername(@Param("username") String username);
}
public Author getAuthor(String nickname) {
User user = userService.getUserByUsername(nickname);
Author author = //...
return author;
}
}
63. Monolith-First Architecture
1. Well done packaging
2. Know your domain (strategic and tactic DDD)
3. Encapsulate the domain (Clean Architecture and Usecases)
4. Make gaps in domain (Port and Adapters)
5. Integrate Bounded Contexts
6. Manage complexity (by CI tools)
7. You are ready to peel-off edges
64. We are making mistakes
Let’s prepare for them better