What Is CI/CD
Continuous integration, continuous delivery, and continuous deployment, and why databases need extra care.
CI/CD in one picture
CI/CD is the automated path a change takes from a developer's commit to production. Continuous integration builds and tests every change as soon as it's committed. Continuous delivery keeps every tested change ready to release at the press of a button. Continuous deployment goes one step further and releases every change that passes, with no button at all.
Continuous integration (CI)
Developers and DBAs write changes on branches and commit them to Git. Continuous integration means those changes are merged into the shared main branch often, at least daily, and every change is automatically built and tested as soon as it's pushed, usually on its pull request.
- The goal: find problems within minutes of a change, while it's small and fresh in the author's mind, rather than weeks later when many changes are mixed together.
- For databases, CI checks every schema change: lints the SQL, applies it to a fresh test database, runs tests, and confirms it can be rolled back.
- The rule: if CI fails, fixing it comes first, so
mainalways stays in a working state.
Continuous delivery (CD)
Continuous delivery extends CI: every change that passes is automatically deployed to test and staging environments, and is production-ready at all times. Releasing to production is a business decision, made by a person approving it, but the release itself is automated, the same way every time.
- Every change has been tested in production-like environments before anyone is asked to approve it.
- Releasing is routine: press a button, or approve a step, rather than run a weekend of manual scripts.
- Teams can release whenever the business wants, as often as it wants.
Continuous deployment (CD)
Continuous deployment removes the last manual step: every change that passes all the automated checks goes into production automatically, often many times a day. There's no approval button; the tests are the approval.
It requires a great deal of trust in the automation: thorough tests, monitoring that spots problems quickly, small changes, and an easy way to undo or switch off a change. Companies such as Amazon and Netflix deploy application code this way thousands of times a day.
| Continuous integration | Continuous delivery | Continuous deployment | |
|---|---|---|---|
| Every change is | Merged and tested automatically | Tested and deployed to test and staging | Tested and released to production |
| Production release | Separate, often manual process | Automated, after a person approves | Fully automatic |
| Main benefit | Problems found within minutes | Always ready to release, safely | Fastest possible delivery |
| Needs | Automated tests | Plus automated deployment to every environment | Plus very high confidence in tests, monitoring, and rollback |
Why databases are harder
CI/CD started with application code, which is easy to replace: deploy the new version, and if it's bad, deploy the old one again. Databases are different:
- They hold state
- You can't replace a database with a new version; you have to change it, carefully, while preserving its data.
- Some changes can't be undone
- Dropping a column deletes its data. A "rollback" can recreate the column, but not the data that was in it.
- Changes can lock and slow things down
- Adding an index or altering a large table can block users or take hours on production-sized data, even if it took a second in testing.
- Order matters
- The database must change in step with the application: a new column must exist before the code that uses it is released.
That's why database CI/CD needs its own tools and practices: versioned migrations, realistic testing, rollback scripts, and changes designed to be backward compatible. The rest of this module covers each.
In practice: the 2 a.m. failure CI would have caught
Before Kofi's team had CI, a developer's migration added a foreign key between two tables. It worked on their laptop, where the tables were empty. At 2 a.m., during the release window, it failed in production: existing rows didn't match, so the constraint couldn't be created. The release was rolled back, and the team spent the next day cleaning up.
With CI, the same migration runs on every pull request against a database loaded with realistic, masked data. The constraint fails in the pipeline within minutes of the commit, the developer sees exactly which rows break it, and the fix, a data cleanup step before the constraint, goes in the same pull request. Nothing reaches production broken, and nobody is awake at 2 a.m.
Key takeaways
- Continuous integration merges changes often and builds and tests every one automatically, on every pull request.
- Continuous delivery keeps every tested change production-ready; a person approves the release, which is then automated.
- Continuous deployment releases every passing change automatically, with no manual approval.
- Git stores the changes; CI/CD tools such as GitHub Actions run the pipeline.
- Databases hold state, some changes can't be undone, and big changes can lock tables, so database CI/CD needs extra care.