Data orchestration

In shared data patterns, there is no need for the orchestration of data, because the microservices will use the same physical component for storage of the data. In the case of our related microservice, News, this can be seen in the docker-compose.yml file of our application.

In our archive, we add that MongoDB is our database. The declaration is done very simply by giving a name to the container, specifying the door where MongoDB will be exposed, and giving the command that should be executed for the functioning of Mongo:

mongo: 
    image: mongo:latest 
    container_name: "mongodb" 
    ports: 
        - 27017:27017 
    command: mongod --smallfiles --logpath=/dev/null # --quiet 

Now, we add the microservices that we created earlier. The three offices have the same pattern. The highlight is the environment variables. The APP_SETTINGS variable indicates which setting we adopt in the microservice according to what is contained in the config.py file of the application. The DATABASE_HOST variable shows us the route of access to the database. Consider the following code:

Note that the three microservices point to the same database, because they use the same container.
famous_news_service: 
    image: famous_news_service 
    build: ./FamousNewsService 
    volumes: 
      - '.:/usr/src/app' 
    environment: 
      - APP_SETTINGS=config.DevelopmentConfig 
- DATABASE_HOST=mongodb://mongo:27017/ 
    depends_on: 
      - mongo 
    links: 
      - mongo 
 
politics_news_service: 
    image: politics_news_service 
    build: ./PoliticsNewsService 
    volumes: 
      - '.:/usr/src/app' 
    environment: 
      - APP_SETTINGS=config.DevelopmentConfig 
- DATABASE_HOST=mongodb://mongo:27017/ 
    depends_on: 
      - mongo 
    links: 
      - mongo 
 
sports_news_service: 
    image: sports_news_service 
    build: ./SportsNewsService 
    volumes: 
      - '.:/usr/src/app' 
    environment: 
      - APP_SETTINGS=config.DevelopmentConfig 
- DATABASE_HOST=mongodb://mongo:27017/ 
    depends_on: 
      - mongo 
    links: 
      - mongo 

However, the internal control patterns of data is highly recommended. Command Query Responsibility Segregation (CQRS) and caching first can be applied normally. CQRS is a little more complicated than just the amount of physical data storage components, but caching fits nicely into this pattern.

The alert point is exactly about the cache. The shared data pattern is not just about sharing the storage of the database, but also of other physical storage resources such as cache. So, removal of items from the cache should be treated very thoroughly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.172.195