I am trying to understand when does it make sense to have independent layers versus merging layers together.
For example, let's say there is a wallet service where you can keep money in separate buckets like food, household, electricity, travel. Money can be redeemed across multiple buckets as well, for example if sufficient balance is not available in food, redeem from household but other way it is not allowed.
Approach 1 to have 2 independent micro services like below
Wallet service: Maintains balance against some bucket. With no redemption rules.
Redemption service: Wrapper around account service, it understands rules like
a. multiple buckets and hierarchy among different buckets.
b. only allow X% redemption from particular bucket.
c. only allow Y% redemption from particular buckets in a day.
No one calls account service directly but only the wrapper service.
In Approach 2 We merge the micro services in a single one, and separate the accounting and redemption modules.
Here are some tradeoffs I can think of
In approach 1, Any redemption operation would require taking a lock in service 2 as well. Since all the redemption operation first depends on getting the current wallet information. Calculate the redemption operations to be performed across different buckets. then making another call to wallet service. So from execution perspective both the services are coupled for any redemption operation they perform. The benefit is that wallet and account services can be scaled independently.
In approach 2 If there are multiple use cases for wallet service. Few of them might require hierarchy across wallets, some of them may not require hierarchy or some of them may only allow x% of wallet to be consumed in a day. By clubbing all these logics together in the same service we will end up having wallet service catering to different concerns. The latencies would be lower in approach 2.
For now the approach I am thinking is to start with approach 2 and then move to approach 1 if enough diverse use cases are there.
Are there other tradeoff to be considered which can be deciding factor?