I'm in the process of designing a microservice for a specific business domain.
The requirements for the service are:
- Expose a synchronous communication channel using RESTful API.
- Communicate asynchronously via messaging off a broker. (will account for most of the traffic).
Note: The business logic layer is the same for both communication styles.
So far I have 2 approaches in mind:
Approach 1
- Extract the business logic layer of the service to a centralized core repo.
- Reuse the business logic layer in 2 different codebases, one for REST one for messaging.
- As a result, the 2 different codebases run as 2 different processes and are also provisioned separately.
Approach 2
- Given that the service code is architected in a manner that allows the client and business logic layers to be switched interchangeably.
- Implement 2 different app entry points that utilize the same BL layer: A. Run as a server that subscribes on topic B. Rub as a server that exposes RESTful API.
- Deploy the same codebase with different configs to establish different communication styles.
My approaches might be Ill formed to begin with, I'd be happy to hear how you'd fulfill the requirement. What would be the best practice for this situation?
Thanks in advance