Suppose I have (micro)services:
The following is simplified a lot, you may assume they're significant enough to be a micro.
- Reseller Service - Our code is turned into whitelabel software. This is the service that owns the Reseller related data, like its ID, name, main brand, active modules etc. Creation and updating can only be done via the API to this service
- Distributor - This owns the data for distributors, like the name and logo. For now we manage them, but its not unthinkable in the future they might add their own.
- Insurance - This owns the data for insurances, like the name and max amount. This is just an example extra service to indicate that there are multiple other Services.
We've now came across the following issue: Not every Reseller has all Distributors or Insurances. We need to config what distributors are active for a Reseller and what Insurances are active for a Reseller.
This presents us (afaik) two routes we can take:
- Reseller Service with a
Resellertable and pivot tablereseller_distributorwith anr_idandd_id. - Distributor Service with a
Distributortable and pivot tabledistributor_resellerwith and_idandr_id.
There are good arguments to be made for both;
When all things appear equal, how do we make a choice?
Pro Distributor at Reseller: You config a Reseller, which is an important object, and you can do that in one location.
Con: Now the Reseller service needs to know about all Things (at least their IDs).
Con: If you want additional info from the pivot (like active_from) you now need to change the Reseller Service
Pro Distributor at Reseller: The Reseller needs to know about a Distributor, Insurance, Example only once, in the pivot column.
We're coming up with good arguments for both routes and we dont really think there is a bad solution*, but still we like to apply good practices :)
* Apart from the ChatGPT solution: Create a new Microservice which only responsibility would be to store the relations between everything.