chapter four

4 Data management for microservices

 

This chapter covers:

  • Using Docker-Compose to build and run your microservices application in development
  • Adding file storage to your application
  • Adding a database to your application

When building any application typically we’ll need to deal with data or files and sometimes both. Microservices are no different. We need a database to track dynamic data being generated and updated by the application and we need a place to store assets that are served by the application or uploaded to it.

In this chapter we are adding both file storage and a database to our example application FlixTube. First we’ll be adding file storage so FlixTube has a location to store its videos.

Then we’ll be adding a database. At this point we are adding a database so that we have a place to record the path to each video, but this is really just an excuse to get a database in place because once we have it we can easily use it for other microservices and the ongoing needs of the broader application. To achieve this we’ll have to add a database server to our application.

As for file storage, we’d like to have distinct areas of responsibility in our application for streaming and storage of videos. That implies that we’ll need to add another microservice to our application and in this chapter we will indeed create our second microservice.

4.1       New tools

4.2       Getting the code

4.3       Developing microservices with Docker-Compose

4.3.1   Why Docker-Compose?

4.3.2   Installing Docker-compose

4.3.3   Creating our Docker-Compose file

4.3.4   Booting our microservices application

4.3.5   Working with the application

4.3.6   Shutting down the application

4.3.7   Can we use Docker-Compose for production?

4.4       Adding file storage to our application

4.4.1   Using Azure Storage

4.4.2   Updating the video streaming microservice

4.4.3   Adding our new microservice to the Docker-Compose file

4.4.4   Testing the updated application

4.4.5   Cloud storage vs cluster storage

4.4.6   What did we achieve?

4.5       Adding a database to our application

4.5.1   Why MongoDB?

4.5.2   Adding a database server in development

4.5.3   Adding a database server in production

4.8       Summary