What’s the problem with monoliths?
In order to understand what microservices are, first, we have to talk about monolith systems and their drawbacks.
Imagine Amazon as a Laravel project. It is one huge git repository, and it’s made of classes like these:
- Product
- Inventory
- Catalog
- Rating
- Shipping
- Order
- OrderHistory
- Payment
- Discount
- Refund
- Recommendation - Wishlist
- Account
- PrimeMember
- OneClickBuy
And so on. Just ask yourself: what does the one-click buy functionality have to do with shipping? One-click buy cares about credit card numbers, and user info, while shipping cares about product attributes, like weight and height, and addresses. Similarly refund logic has nothing to do with a wishlist.
Despite the fact that these modules, these classes are very different from each other, they live in the same repository, they can be accessed by the same API, they can call each other, and they can share some general functions or classes.
They are tightly coupled and have low cohesion. But in great architecture, we’d like to have loose coupling and high cohesion.