KAHIBARO
Discord Login Register

24.1. Introduction to CI/CD

Why CI/CD Matters for Backend Developers

When you work on backend applications, you will change code often. Each change needs to be tested, built, and deployed to a server. Doing this manually is slow and error prone. Continuous Integration and Continuous Delivery (CI/CD) is about automating these steps so that:

CI/CD is not a specific tool. It is a set of practices plus tools that help you move code from your laptop to production safely and quickly.

Key idea: CI/CD automates the path from code change to running in production, with automatic checks at every step.

In this chapter you will learn what CI and CD are, how they fit into backend development, and how they connect to later topics like Docker, testing, and deployment.

Core Concepts: CI, CD, and Pipelines

Continuous Integration in One Sentence

Continuous Integration (CI) means merging small code changes into a main branch frequently, and automatically checking that they work.

In practice, CI usually involves:

Typical CI tools:

ProviderCI Solution
GitHubGitHub Actions
GitLabGitLab CI/CD
BitbucketBitbucket Pipelines
Self-hostedJenkins, Drone CI, etc.

As a backend developer, CI answers the question:
“Is the code that I just pushed safe to integrate with the main branch?”

Continuous Delivery vs Continuous Deployment

CD is often used for two related ideas:

You can think of them like this:

ConceptWhat is automated?Manual step?
Continuous IntegrationBuild and tests on code changesMerge decisions
Continuous DeliveryBuild, tests, packaging, staging deployFinal production deploy
Continuous DeploymentBuild, tests, packaging, all deploymentsNone (fully automated)

Most backend teams start with CI, then add Continuous Delivery, and later decide whether they want full Continuous Deployment.

What Is a CI/CD Pipeline?

A CI/CD pipeline is a defined sequence of automated steps that run when your code changes. You usually describe it in a configuration file in your repository.

A very simple backend pipeline might:

  1. Trigger when you push to main or create a pull request.
  2. Check out the code.
  3. Install dependencies.
  4. Run tests.
  5. Build a Docker image.
  6. Push the image to a registry.
  7. Deploy it to a staging or production environment.

You can imagine it as a production line for your software:

StageExample actions for a Python backend
SourceCode pushed to GitHub/GitLab
BuildInstall dependencies, create build artifacts
TestRun pytest, linting, type checks
PackageBuild a Docker image
DeployDeploy container to server or Kubernetes
VerifyHealth checks, smoke tests after deploy

Important rule: A good pipeline is repeatable and fully defined in code, not in someone’s memory or on one person’s laptop.

CI/CD in the Backend Development Workflow

Where CI/CD Fits in a Typical Workflow

Here is a simple workflow for a backend developer:

  1. You create a feature branch from main.
  2. You implement changes locally and run tests.
  3. You push the branch to the remote repository.
  4. A CI pipeline runs automatically:
    • installs dependencies
    • runs tests
    • builds the app
  5. You open a pull request or merge request.
  6. The pipeline must be green (successful) before the branch can be merged.
  7. After merging to main, a CD pipeline might:
    • build and push a Docker image
    • deploy to staging or production
    • run post-deploy checks

Without CI/CD, steps 4 and 7 are often done manually or inconsistently.

Benefits Specific to Backend Projects

For backend development, CI/CD helps with:

Simple Example: A Minimal CI Pipeline

Imagine you have a small FastAPI backend. A minimal CI pipeline could:

  1. Run whenever code is pushed or a pull request is opened.
  2. Install Python and dependencies.
  3. Run unit tests with pytest.
  4. Fail the pipeline if any test fails.

If tests fail, the code is not merged. This alone can prevent many bugs from reaching production.

How CI/CD Is Defined as Code

Pipeline Configuration Files

CI/CD systems usually use a YAML configuration file that lives in your repository. For example:

These files define:

You will learn concrete syntax in the tool-specific chapters, but the pattern is similar everywhere: you declare the pipeline as code, commit it, and version it along with your application.

Common Pipeline Stages for Backends

Although the syntax differs, backend pipelines usually share similar stages:

StagePurposeExample checks
LintEnforce code style and basic static checksflake8, black, isort
TestRun automated testspytest, coverage
BuildCreate an artifact (jar, Docker image, zip, etc.)docker build
Pre-deployRun database migrations in a safe wayAlembic migrations
DeployRoll out new versionRestart containers or services
Post-deploySmoke tests and health checksHitting /health endpoint

Not every project needs all of these, but as you move to production, more stages become important.

The Role of Tests in CI/CD

Tests as a Gatekeeper

In earlier chapters you will learn about testing in detail. For CI/CD, tests are the gate that controls whether a change can progress.

A simple rule is:

A change must not be merged or deployed if the tests fail.

For backend development, you typically run:

As your project grows, you may also add:

Fast Feedback versus Full Coverage

In CI/CD, you often balance speed and depth:

For example:

The goal is that developers receive feedback quickly, usually within a few minutes.

Environments and Deployment Flow

From Development to Production

CI/CD pipelines usually involve multiple environments. For a backend service, you might see:

EnvironmentPurposeWho uses it
LocalDevelopment on your machineDevelopers
TestAutomated tests, QADevelopers, QA
StagingLooks like production, final validationDevelopers, product
ProductionReal users and real dataEnd users

A simple flow:

  1. Developer pushes branch.
    CI runs tests on an isolated environment (for example, ephemeral container, test database).
  2. Merge to main.
    CD pipeline builds a Docker image and deploys it to a staging environment.
  3. Manual or automatic checks on staging.
    If all looks good, another step deploys the same build to production.

Immutable Artifacts

Modern pipelines often create an immutable artifact, for example a Docker image, from your code. The same artifact is then deployed to staging and production.

This helps to avoid situations where staging and production are different because someone built them differently.

In later Docker and Deployment chapters, you will see how CI/CD pipelines build and publish Docker images and then pull them on servers.

CI/CD and Other Topics in This Course

You will see CI/CD ideas appear again and again in later chapters:

You do not need to master all of this now. For this chapter, the key goal is to understand that CI/CD connects your Git workflow, tests, builds, and deployments into one automated path.

Practical Starting Point for Beginners

You can introduce CI/CD gradually. For a first backend project, a simple plan might be:

  1. Use GitHub or GitLab for your repository.
  2. Add a very simple CI workflow:
    • trigger on push and pull requests
    • install Python
    • install dependencies from requirements.txt
    • run pytest
  3. Treat a red (failing) pipeline as a blocker:
    • fix tests
    • push again until the pipeline is green
  4. When you start using Docker, extend the pipeline:
    • build a Docker image
    • push it to a registry (for example, Docker Hub)
  5. When you learn deployment, add a deployment step:
    • deploy the new Docker image to a server
    • run a basic health check

At each step you make more of your workflow reproducible and less manual.

Summary

Views: 9

Comments

Please login to add a comment.

Don't have an account? Register now!