We have a Data Processing Pipeline where we receive data from different sources. The entire pipeline is implemented by using Event Driven Architecture and microservices. One of the services has three separate tasks. Two of them are completely common across different sources of data, but the third task scope may change slightly depending on what our data source is. For example, for one source the unique signature may get calculated based on filed1 and filed2, and for another source, it may get calculated based on field2 and field3. How's the best way of implementing this service to be aligned with microservice granularity principles?
Three approaches have come to my mind:
1) Create a single service and use different implementation per source (like a factory design pattern). Depending on the source, one of the implementations will be used at the run-time.
Pros: Less number of services. Less complexity
Cons: Since the service will be shared across all data sources, by adding any new data source this service should be re-deployed which creates an implicit dependency between this service and any service responsible to collect data from a source
2) Break this service into two services, use one for all sources and reimplement the extracted service per data source.
Pros: No dependency between the collector and these two services. By adding a new source a new service needs to be implemented and it does not require to redeploy the services related to other sources.
Cons: More services and since the services are going to be too small we may end up facing nanoservice issue in future.
3) Do not change the granularity of services, but create different instances of the service at run-time. Each with a different config to specify what are the set of fields to be used for each source. In this case, the code is shared, but run-time instances are different depending on which source it belongs to.
Pros: Less number of service, and no operational dependency
Cons: Move complexity of logic to run-time which may make the deployment and operations more challenging