Separating the database

Inside of each microservice directory, we will create two more directories. In each of these new directories will be a Dockerfile with configurations for the database. We will use two different databases for each microservice to use CQRS. One database is for CommandStack and one for QueryStack.

With these changes, the directory structure for the News microservices looks like this:

├───FamousNewsService 
│   ├───command_db 
│   └───query_db 
├───PoliticsNewsService 
│   ├───command_db 
│   └───query_db 
└───SportsNewsService 
    ├───command_db 
    └───query_db 

I'll show the code changes only in the famous_news_service microservice, but such changes should be applied in the other two News microservices.

Inside the command_db directory, we ...

Get Microservice Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.