I’m developing a NodeJS project with hexagonal architecture but I have a big doubt about how to manage the workflow in implementations of databases (MySQL & Redis)
MySQL implementation:
- I’m using Sequelize ORM & it’s possible to populate models to get associations (JOINs). Sequelize implementation let me to set up some options in one model to include other model directly in its own repository. I don’t need to have a dependency from the second model.
Redis implementation:
- However, with Redis, I need to query all resources separately. This is normal. It’s not possible to associate models & I have to go to repository of second model. These actions should be done in the use case I supposed.
Example:
MySQL implementation sequence
1.1. GetContentsWithVideosUseCase -> I create a Criteria for get all Contents joining its own Videos
1.2. ContentRepository.findAll(criteriaForJoinVideos) -> Here I already have each content with its videos.
1.3. GetContentsWithVideosUseCase -> I doesn't need anymore so return it to controller.
Redis implementation sequence
2.1. GetContentsWithVideosUseCase -> I create a Criteria for get all Contents.
2.2. ContentRepository.findAll(criteriaContents) -> Here I only have each content.
2.3. GetContentsWithVideosUseCase -> I have contents but now I need videos from them. Contents.map & create criteria for each query of videos by content.
2.4. VideoRepository.findAll(criteriaVideosByContent) -> Here I already have videos for one content.
2.5. GetContentsWithVideosUseCase -> I have now all videos for all contents & I compose the object which will be returned.
Question!
We can see that the problem here is that usecase should be different depend of implementation & that shouldn’t happen.
The question with this scenario what is the best & most correct practice:
- Should I do all the MySQL queries independently (separating them on respective reporsitories) & leaving JOINs?
- Is it possible to keep JOINs with Redis implementation?
- Have you dealt with this ever?
Thanks!