In this article, I’ll cover your local experience, which easily extends to CI, and I’ll also touch how to do this in production. Having a great local development experience is critical to happy engineers.
Developers are happy to come into a code base and start hacking away at problems, as opposed to dreading picking up their laptops. As services become more and more separated into separate “micro-services,” new problems arise. When I look back on my short career, one problem that has caused me a lot of pain is SQL migrations and how they should work in Docker Compose. Ideally, they should run before your web apps boot so they have access to a well-structured database. Your strategy to make this happen may be different for each environment. In this article, I’ll cover your local experience, which easily extends to CI, and I’ll also touch how to do this in production.
I ran into this problem when we started to adopt Apollo Federation into our stack. One gateway service lives in front of our other GraphQL services (which have their own databases). This gateway is what the client-side app (“Web Browser” in diagram) queries to get its data. For clients to start using the gateway API, every dependent service must be up and healthy.
Our service diagram
My goal is to start the entire set of services in a deterministic manner, to have each service wait until its dependent service is running and healthy. I’ll focus on the database and migrations in this article, but the concepts here extend to any service having dependencies on another service.
A typical Docker Compose file which runs the products service with its migrations will look like this:
There are a few issues with this setup, focusing on
products-run-migrationsscript will run right when
postgresstarts to run, not when it's healthy and ready to accept connections. There is a 99% chance that the
postgrescontainer will not be healthy when the migrations begin to run, causing them to fail.
productsservice. It will run right when
products-run-migrationsstarts to run. If you query the
productsservice when it's healthy, there is a good chance the migrations have not yet completed.
SQL stands for Structured Query Language. SQL is a scripting language expected to store, control, and inquiry information put away in social databases. The main manifestation of SQL showed up in 1974, when a gathering in IBM built up the principal model of a social database. The primary business social database was discharged by Relational Software later turning out to be Oracle.
To make the most out of the benefits of offshore software development, you should understand the crucial factors that affect offshore development.
Hire our Dedicated DevOps Developers who have in-depth skills and expertise to develop an interactive and secure web application. Get custom DevOps solutions for your project.
Check out these five criteria for the selection of your software vendor, and you will never regret having the wrong quality product made for you.
Looking to hire top DevOps developers at affordable prices? **[Hire DevOps Developer](https://hourlydeveloper.io/hire-dedicated-devops-developer/ "Hire DevOps Developer")** from **[HourlyDeveloper.io](https://hourlydeveloper.io/...