Monolith truyền thốngTraditional monolith
phân tầng · cổ điểnlayered · classicMột ứng dụng build và triển khai thành một khối, code chia theo tầng kỹ thuật. Các phần gọi nhau tự do, không có rào chắn.One application built and deployed as a single block, code organized by technical layer. Parts call each other freely, with no barriers.
src/ ├── controllers/ │ ├── OrderController │ ├── PaymentController │ └── InventoryController ├── services/ │ ├── OrderService │ ├── PaymentService │ └── InventoryService ├── repositories/ │ ├── OrderRepository │ ├── PaymentRepository │ └── InventoryRepository └── models/
Hình dung: nhà lớn không tường ngăn. Lúc đầu tiện, nhưng sửa bếp dễ làm hỏng phòng ngủ. OrderService gọi thẳng InventoryRepository, không gì ngăn được.Analogy: a big house with no interior walls. Convenient at first, but fixing the kitchen easily breaks the bedroom. OrderService calls InventoryRepository directly and nothing stops it.
ĐượcGains
- Khởi động cực nhanh, ít boilerplateExtremely fast to start, little boilerplate
- Gỡ lỗi dễ: một process, một stack trace, một logEasy to debug: one process, one stack trace, one log
- Vận hành đơn giản: một thứ để triển khai, giám sát, sao lưuSimple ops: one thing to deploy, monitor, back up
- Gọi hàm trực tiếp, transaction ACID thoải máiDirect function calls, ACID transactions freely
MấtCosts
- Dễ thoái hoá thành "big ball of mud"Easily degrades into a "big ball of mud"
- Codebase phình, build/test chậm dầnCodebase grows, build/test slows down
- Nhiều team khó làm song songHard for many teams to work in parallel
- Coupling âm thầm tăng, refactor về sau rất đauCoupling silently grows; later refactors hurt
Đánh đổiTrade-offChọn monolith truyền thống là đổi cấu trúc dài hạn lấy tốc độ ra sản phẩm hôm nay.Choosing a traditional monolith trades long-term structure for shipping speed today.