I had a monolithic application and now, I want to separate this application into multiple services.
For example, consider the User and the Notification services that two of them will be written with PHP and Laravel framework.
Now I want the Notification service to be responsible for formatting and sending messages. In the previous version, I could handle the notification just with Model and Notifiable
trait easily, but now I don't have access to the User model in the Notification service.
How can I handle the Laravel notification, should I repeat the User model in this domain?
Is there any example to be used?
You rightly pointed out that one service (Notification) may not have access to the data it needs to operate (User data), which was previously directly accessible in a monolithic setup.
In a microservice architecture, each service should be self-contained and loosely coupled, which means that duplicating the User model in the Notification service could lead to issues down the line (like data consistency, handling updates, etc.).
Instead, consider the following approach:
API calls: Another common way to handle inter-service communication in a microservices architecture is to use API calls. The Notification service can make a request to the User service's API to fetch necessary user details for a given notification.
Data Transfer Objects (DTOs): Instead of directly using models across services, consider using DTOs that can be tailored to each service's needs. DTOs can be seen as a form of contract or API between services, reducing the coupling between them.