dimanche 28 mars 2021

system Design: service to request data for N users in M different data sources

I am struggling to create a clean design for a system that needs to call N services for M applicants.

details:

  1. each service returns different domain objects
  2. each service call should be in a different thread
  3. Max # of applicants 3
  4. max # of services currently there is no defined limit. will need to check on system limits

I am looking for best practices on design and also maintainability. my goal is to define a new service that implements an interface, then the system will add the service to the list. in my current design, I need to define the list of services manually and pass the dependencies and needed data. note: i'm using java 8 and spring

// given

Future futureOne = new DataCollectorTaskOne(applicantData, serviceOne);

Future futureTwo = new DataCollectorTaskTwo(applicantData, ServiceTwo);

// where

DataCollectorTask extends callable(not a bean just a pojo), that will call the service(initialize from the constructor) using the applicant data.

@Data
@RequiredArgsConstructor
public class DataCollectorTask<T> implements Callable<T> {
    public final BankRecordsService bankRecordsService;
    public final ApplicantData applicantData;

    @Override
    public T call() throws Exception {
        return bankRecordsService.executeRequest(applicantData)
    }

in spring I can autowire the list of beans that extends an interface. in this case I will be able to get the list of services because they will have the @Service annotation but the CallableService beans are just pojos(not manage by spring).

service interface

public interface DataCollector<T> {

  /* This will be use to disable or enable services in different environments*/
  boolean isActive();

  /*The data service will be responsible to implement the mapping*/
  void mapData(DataCollectorRequest request, ApplicantData mappingDestination, T data);

  /*different services have different time expectations*/
  int getTimeOut();

  /*this will determine based on the data in the applicantData if everything was successful*/
  boolean isRequestSatisfied(ApplicantData valueInDatabase, DataCollectorRequest dataCollectorRequest);

}

I have a feeling there is a better design than what i have right now. Also, i have a question about about multithreading should the system create a thread for each applicant then each thread will create a thread for each service ? or just create a thread for N*M services.

Aucun commentaire:

Enregistrer un commentaire