2022
avoiding micro-monolIthS
MONOLITHIC BACKEND
HTTP Server
URL Router
View X
View Y
View Z
Model A
Model B
Database
HTTP
Function calls
Queries
The Monolith
Logic X, Y, Z
SPAGHETTI
MONOLITHIC BACKEND
component boundaries
- there is nothing wrong with monoliths
- ... provided they are well-structured
- humans tend to be lazy, incompetent and prone to errors
- humans break component boundaries and generate spaghetti over time
- let's enforce the boundaries then
NON-MONOLITHIC BACKEND
component boundaries
HTTP Server
URL Router
View X
View Y
View Z
Model A
Model B
Database
URL Router
URL Router
Model A
Model B
Model B
Business Logic
Logic X
Logic Y
Logic Z
COPY PASTA
NON-MONOLITHIC BACKEND
DATA BOUNDARIES?
HTTP Server
View X
View Y
View Z
Model A
Model B
Database B
Model A
Model B
Model B
Logic X
Logic Y
Logic Z
Database A
NON-MONOLITHIC BACKEND
data boundaries?
HTTP Server
View X
View Y
View Z
Model A
Database B
Model B
Logic X
Logic Y
Logic Z
Database A
View
B
View A
DISTRIBUTED SPAGHETTI
NON-MONOLITHIC BACKEND
distributed spaghetti
-
call stack lives in the cloud:
control flow is hard to follow -
inflexible:
need to coordinate interface changes in multiple places -
duplicated views and clients:
need to provide CRUD for all models used by siblings
The problem
Model A
Model B
Logic X
Logic Y
Logic Z
the solution
Logic X
Logic Y
Logic Z
Data
A
Data
B
Data
B
Data
A
Data
B
A pure function is a function that has the following properties:
- The function return values are identical for identical arguments
- The function application has no side effects
the solution
purity of essence
No matter what language you work in, programming in a functional style provides benefits. You should do it whenever it is convenient, and you should think hard about the decision when it isn't convenient.
John Carmack
the solution
BENEFITS OF PURITY
- Easy unit testing
- Self-documenting interface
- Straightforward control flow
- Easier memoization/caching
NON-MONOLITHIC BACKEND
DATA BOUNDARIES!
HTTP Server
View X
View B
Model A
Database B
Model B
Logic X
Database A
Data
A
Data
B
2022
avoiding micro-monoliths
Avoiding MicroMonoliths
By Michał Lowas-Rzechonek
Avoiding MicroMonoliths
How and why to avoid "(micro)service-based monolith"
- 291