SlideShare a Scribd company logo
Pragmatic Monolith-First
easy to decompose, clean architecture
Piotr Pelczar
Gliwice 2017, Spread IT
Let’s design a system
• Several different products
• Multi Channel
System Architecture - Case
Accounts DepositsLoans
System Architecture - Case
Product API
GUI
Channel 1
GUI
Channel 2
• Simple Split-Architecture (GUI + backend)
System Architecture - Case
Accounts DepositsLoans
Business makes money
and want to scale
• Cross-sell
System Architecture - Case
Accounts DepositsLoans
System Architecture - Case
Accounts Loans
System Architecture - Case
System Architecture - Solution 1
Accounts Loans
Event Bus
Loans’
• Event-Driven + data duplication
System Architecture - Solution 2
Accounts
Repo
Loans
Accounts
Sales Process
• Refactor – move functionality to another module
System Architecture - Solution 2
Accounts
Repo
Loans
Repo
Accounts
Sales Process
Loans
Sales Process
• And more refactor…
Business makes Cross-sell
and want to scale
• Sell next type of Loan
“We want the same process.”
“… almost the same process, but…”
System Architecture - Case
Accounts
Repo
Loans
Repo
Loans
Sales Process
Dep
#1
Dep
#2
Dep
#3
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
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:
Is it good decision?
Accounts Loans
…or this coupling is acceptable?
Can we assume that it is essential complexity
not accidental complexity?
Piotr Pelczar
Java, Groovy, node.js, PHP
11 yrs exp
We are making mistakes
Let’s prepare for them better
Microservices hype
We know benefits
We know drawbacks
One Bounded Context = 1 µS
Do we split properly? Do we understand Business?
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
https://zeroturnaround.com/rebellabs/developer-productivity-report-2017-why-do-you-use-java-tools-you-use/
Monolith-First Architecture
Manifest:
• Build well-managed complexity monolith
• Easy to refactor (move between packages)
• Enables quick pivots in Domain Modeling
• Exposes ready to peel-off edges into microservices
Idyll?
Monolith-First Architecture
For:
• Long-living components (many projects)
• with Complex domain (no CRUD)
1. Well done high-level packaging
1. Well done high-level packaging
• Open the app folder
and can easily recognize what it is about
1. Well done high-level packaging
• Packaging by technical layer = Monoloth RIP
• More than one Bounded Context in each layer = cannot split them
1. Well done high-level packaging
Packaging by business scopes/Bounded Context = easy to split
com.acme.SERVICE-NAME.BOUNDED-CONTEXT.*
2. Know your domain
2. Know your domain
Modeling - DDD gives us tools:
• Tactical: (how to organize code)
• Aggregates, Value Objects, Repositories, Events
• Application Services, Domain Services (transforming data, integration)
• Strategic: (how to map and discover domain)
• Problem mapping
• Bounded Contexts
2. Know your domain
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
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)
3. Encapsulate the domain
(Clean Architecture and Usecases)
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
3. Clean architecture
https://8thlight.com/blog/uncle-bob/2011/11/22/Clean-Architecture.html
@Service
public class CreateScheduleUC {
@Transactional
public void createSchedule(CreateScheduleCommand command, CreateScheduleResult result) {
ScheduleId newScheduleId = scheduleRepository.generateNextId();
ProgrammeId programmeId = ProgrammeId.of(command.getProgrammeId());
final Schedule newSchedule = Schedule.create(
newScheduleId,
programmeId
);
scheduleItemsMapper.mapItemsToDomain(newSchedule, command.getItems());
scheduleConstraintsMapper.mapConstraintsToDomain(newSchedule, command.getConstraints());
scheduleRepository.save(newSchedule);
result.success(newScheduleId.getId());
}
}
3. Clean architecture
https://8thlight.com/blog/uncle-bob/2011/11/22/Clean-Architecture.html
3. Clean architecture
https://8thlight.com/blog/uncle-bob/2011/11/22/Clean-Architecture.html
3. Clean architecture
https://8thlight.com/blog/uncle-bob/2011/11/22/Clean-Architecture.html
@Service
public class FindScheduleForDayUC {
@Data
@Builder
public static class ScheduleForDayCommand {
private final String programmeId;
private final LocalDate day;
}
public interface ScheduleForDayResult {
void success(Schedule schedule);
void notExists();
}
public void findScheduleForDay(ScheduleForDayCommand command,
ScheduleForDayResult result) {
// ...
result.notExists();
// ...
result.success( ... );
}
}
@Controller
@RequestMapping("/schedule")
class FindScheduleForDayController {
@GetMapping(value = "/forDay/{programmeId}/{day}")
@ResponseBody
@ApiResponses({
@ApiResponse(code = 200, message = "", response = ScheduleDto.class),
@ApiResponse(code = 404, message = ""),
})
public ResponseEntity<?> createSchedule(@RequestParam("programmeId") String
@RequestParam("day") @DateTimeFormat
ScheduleForDayCommand command = ...
FindScheduleForDayResponseBuilder responseBuilder ...
findScheduleForDayUC.findScheduleForDay(command, responseBuilder);
return responseBuilder.toResponse();
}
}
3. Clean architecture
UI
Business Logic
DAO I/O …
Business Logic
Domain
GUI DAO I/O
3. Clean architecture
https://8thlight.com/blog/uncle-bob/2011/11/22/Clean-Architecture.html
4. Make gaps in domain
Port and Adapters
aka Hexagonal Architecture
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
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
5. Integrate Bounded Contexts
5. Integrate Bounded Contexts
• Integrate via
Ports -> Adapters ->
referring to Usecases
• Almost Microservices!
http://www.natpryce.com/articles/images/ports-and-adapters-acceptance-testing.png
But we live in monolith…
and easy to make some unwanted
dependencies
6. Manage Complexity
6. Manage Complexity
http://www.structure101.com/
6. Manage Complexity
6. Manage Complexity
• Structure 101
• Java
• PHP
• Socomo Maven Plugin
• Java
• Another tools?
# prevent cyclic dependencies
check acyclicCompositionOf com.acme.someservice
[usecase] = com.acme.someservice.*.usecase.*
[domain] = com.acme.someservice.*.domain.*
[adapter] = com.acme.someservice.*.adapter.*
[delivery] = com.acme.someservice.*.delivery.*
# domain is independent of usecase
check [domain] directlyIndependentOf [usecase]
check [delivery] directlyIndependentOf [dziedzina]
# delivery constraints
check [usecase] directlyIndependentOf [delivery]
check [adapter] directlyIndependentOf [delivery]
check [domain] directlyIndependentOf [delivery]
# only heagonal architecture structure
check deny *
check allow com.acme.someservice.*.usecase.*
check allow com.acme.someservice.*.domain.*
check allow com.acme.someservice.*.adapter.*
check allow com.acme.someservice.*.delivery.*
# except technical packages
check allow com.acme.someservice.technical.*
7. You are ready to peel-off edges
7. Peel-off edges
1. Move whole package to another service
• add delivery layer only
2. Change Use Cases invocations in Adapters to RPC
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:
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;
}
}
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
We are making mistakes
Let’s prepare for them better
Monolith-First Architecture
For:
• Long-living components (many projects)
• when is a good time to peel-off?
• with Complex domain (no CRUD)
Monolith-First Architecture
• Many buzzwords?
These patterns already exists
there name is “interfaces”
here they are structured
Thanks! Q&A
http://doineedbackup.com/customer-acquisition-channels-for-saas/
https://highspark.co/how-to-end-a-presentation/
Thanks! Q&A

More Related Content

PDF
Statyczna analiza kodu PHP
PDF
Architectural caching patterns for kubernetes
PDF
Taming AEM deployments
PDF
PDF
"Wix Serverless from inside", Mykola Borozdin
PDF
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
PDF
Beyond Puppet
PDF
Использование Docker в CI / Александр Акбашев (HERE Technologies)
Statyczna analiza kodu PHP
Architectural caching patterns for kubernetes
Taming AEM deployments
"Wix Serverless from inside", Mykola Borozdin
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Beyond Puppet
Использование Docker в CI / Александр Акбашев (HERE Technologies)

What's hot (20)

PDF
Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...
PDF
Docker and Go: why did we decide to write Docker in Go?
PDF
On-Demand Image Resizing from Part of the monolith to Containerized Microserv...
PDF
Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate)
PDF
DockerCon EU 2015: The Glue is the Hard Part: Making a Production-Ready PaaS
PDF
Online Meetup: Why should container system / platform builders care about con...
PPTX
Jenkins' shared libraries in action
PPTX
Enable Fig to deploy to multiple Docker servers by Willy Kuo
PDF
Drone CI/CD 自動化測試及部署
PDF
Multiple django applications on a single server with nginx
PPT
Learn jobDSL for Jenkins
PPTX
Prometheus: infrastructure and application monitoring in kubernetes cluster
PDF
DevOps tools for everyone - Vagrant, Puppet and Webmin
PPTX
Zero to Continuous Delivery on Google Cloud
ODP
Jenkins 101: Continuos Integration with Jenkins
PDF
JCConf 2015 workshop 動手玩 Java 專案建置工具
PDF
An Introduction of Node Package Manager (NPM)
PDF
Sprint 17
PDF
Containerizing a Web Application with Vue.js and Java
PPTX
Learn docker in 90 minutes
Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...
Docker and Go: why did we decide to write Docker in Go?
On-Demand Image Resizing from Part of the monolith to Containerized Microserv...
Puppet Camp Paris 2015: Continuous Integration of Puppet Code (Intermediate)
DockerCon EU 2015: The Glue is the Hard Part: Making a Production-Ready PaaS
Online Meetup: Why should container system / platform builders care about con...
Jenkins' shared libraries in action
Enable Fig to deploy to multiple Docker servers by Willy Kuo
Drone CI/CD 自動化測試及部署
Multiple django applications on a single server with nginx
Learn jobDSL for Jenkins
Prometheus: infrastructure and application monitoring in kubernetes cluster
DevOps tools for everyone - Vagrant, Puppet and Webmin
Zero to Continuous Delivery on Google Cloud
Jenkins 101: Continuos Integration with Jenkins
JCConf 2015 workshop 動手玩 Java 專案建置工具
An Introduction of Node Package Manager (NPM)
Sprint 17
Containerizing a Web Application with Vue.js and Java
Learn docker in 90 minutes
Ad

Similar to Pragmatic Monolith-First, easy to decompose, clean architecture (20)

PDF
"The working architecture of NodeJs applications" Viktor Turskyi
PDF
Refactoring to a system of systems
PDF
Software Architecture and Architectors: useless VS valuable
PDF
The working architecture of NodeJS applications, Виктор Турский
PDF
The working architecture of node js applications open tech week javascript ...
PDF
its all about the domain honey! Experiences from 15 years of Domain-Driven De...
PPTX
Breaking down a monolith
PDF
Architectural Decisions: Smoothly and Consistently
PDF
Reactive Microservice Architecture with Groovy and Grails
PDF
Microservices for Java Architects (Chicago, April 21, 2015)
PPTX
Clean architecture
PDF
DDD Tactical Design with Clean Architecture - Ivan Paulovich
PPTX
Pragmatic Approach to Microservices and Cell-based Architecture
PDF
Viktor Turskyi "Effective NodeJS Application Development"
PDF
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
PDF
Microservices for java architects schamburg-2015-05-19
PDF
Return of the monolith
PPTX
Clean architecture
PDF
Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)
PDF
Architecture tests: Setting a common standard
"The working architecture of NodeJs applications" Viktor Turskyi
Refactoring to a system of systems
Software Architecture and Architectors: useless VS valuable
The working architecture of NodeJS applications, Виктор Турский
The working architecture of node js applications open tech week javascript ...
its all about the domain honey! Experiences from 15 years of Domain-Driven De...
Breaking down a monolith
Architectural Decisions: Smoothly and Consistently
Reactive Microservice Architecture with Groovy and Grails
Microservices for Java Architects (Chicago, April 21, 2015)
Clean architecture
DDD Tactical Design with Clean Architecture - Ivan Paulovich
Pragmatic Approach to Microservices and Cell-based Architecture
Viktor Turskyi "Effective NodeJS Application Development"
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
Microservices for java architects schamburg-2015-05-19
Return of the monolith
Clean architecture
Microservices for Java Architects (Madison-Milwaukee, April 28-9, 2015)
Architecture tests: Setting a common standard
Ad

More from Piotr Pelczar (7)

PDF
Elasticsearch - SEARCH & ANALYZE DATA IN REAL TIME
PPTX
[BDD] Introduction to Behat (PL)
PDF
Asynchronous programming done right - Node.js
PPTX
How NOT to write in Node.js
PPTX
Liquibase - database structure versioning
PPTX
PPTX
Scalable Web Apps
Elasticsearch - SEARCH & ANALYZE DATA IN REAL TIME
[BDD] Introduction to Behat (PL)
Asynchronous programming done right - Node.js
How NOT to write in Node.js
Liquibase - database structure versioning
Scalable Web Apps

Recently uploaded (20)

PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Cost to Outsource Software Development in 2025
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
Download FL Studio Crack Latest version 2025 ?
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
AutoCAD Professional Crack 2025 With License Key
PPTX
assetexplorer- product-overview - presentation
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Digital Systems & Binary Numbers (comprehensive )
Cost to Outsource Software Development in 2025
Design an Analysis of Algorithms I-SECS-1021-03
CHAPTER 2 - PM Management and IT Context
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Download FL Studio Crack Latest version 2025 ?
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Salesforce Agentforce AI Implementation.pdf
AutoCAD Professional Crack 2025 With License Key
assetexplorer- product-overview - presentation
Why Generative AI is the Future of Content, Code & Creativity?
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Nekopoi APK 2025 free lastest update
Navsoft: AI-Powered Business Solutions & Custom Software Development
Monitoring Stack: Grafana, Loki & Promtail
wealthsignaloriginal-com-DS-text-... (1).pdf

Pragmatic Monolith-First, easy to decompose, clean architecture