Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 2

Designing Multi-Stage CI/CD Pipelines with Quality Gates

Recommended resources

Welcome back! In our first lesson, we established the "why" of DevOps by exploring the CALMS framework and its role in breaking down the "wall of confusion" between development and operations. We saw that automation is a core pillar for achieving speed and reliability.

Today, we're putting that principle into practice. This lesson is designed to help you master one of the most common and critical DevOps interview topics: designing a CI/CD pipeline. We will focus on the learning outcome: Design a multi-stage CI/CD pipeline with appropriate quality gates and testing strategies.

You'll learn how to structure your answer to walk an interviewer through a robust pipeline, from a developer's code commit all the way to a production deployment. We'll connect these concepts to your experience with Azure DevOps and deploying applications like your Kafka services, giving you a powerful narrative for your interviews.

1. The Anatomy of a Multi-Stage Pipeline

A CI/CD pipeline isn't just one monolithic script; it's a series of stages, each with a specific purpose. The goal is to build confidence incrementally. As code progresses through the pipeline, it undergoes more rigorous and comprehensive testing, ensuring that only high-quality, reliable changes reach production.

The checkpoints between these stages are called Quality Gates.

To start, let's get a clear definition of what a quality gate is.

The Importance of Pipeline Quality Gates and How to ...

The article 'The Importance of Pipeline Quality Gates' on InfoQ provides a concise and effective definition of this crucial concept.

Read the section titled 'What is a Quality Gate and Why Do You Need Them?'. Focus on understanding its purpose as an 'enforced measure' in the pipeline.

As the article states, a quality gate is an enforced check that your software must pass before it can proceed to the next step. It's the mechanism that turns your pipeline from a simple automation script into a true quality assurance workflow.

The following diagram illustrates a typical, comprehensive pipeline. We will use this as a reference as we walk through each phase.

Typical CI/CD Pipeline with Quality Gates
This diagram shows a detailed multi-stage CI/CD pipeline, starting from code checkout and progressing through build, test, and deployment stages, with specific quality checks integrated at each step.

2. The Continuous Integration (CI) Phase: Fast Feedback

The CI phase focuses on the developer's code. Its primary goal is to provide fast feedback, ensuring that new code integrates well with the existing codebase and meets baseline quality and security standards. A failure here should be immediately visible to the developer who committed the change.

To get a feel for how to articulate this in an interview, let's watch a video that presents a clear, step-by-step pipeline explanation.

HOW TO ANSWER CICD PROCESS IN AN INTERVIEW| DEVOPS INTERVIEW QUESTIONS #cicd#devops#jenkins #argocd

Abhishek Veeramalla's video provides an excellent template for explaining a CI/CD process during an interview. We will focus on the CI part first.

Watch the segment from 01:50 to 05:55. Notice the clear progression of stages: checkout, build/unit test, code scanning, image building, image scanning, and pushing to a registry. This is the narrative you want to build.

Let's break down those CI stages, incorporating details from our resources:

  1. Code Checkout & Build:

    • Trigger: The pipeline automatically triggers on a new commit or pull request to a feature branch or the main branch.
    • Action: The code is checked out, and the application is compiled.
    • Unit Tests: Fast-running tests written by developers are executed. These verify that individual components of the code work as expected in isolation.
    • Quality Gate: The gate here is typically a combination of 100% test pass rate and a minimum code coverage threshold (e.g., 80%). If either is not met, the pipeline fails, and the build is rejected.
  2. Static Analysis:

    • Action: The pipeline runs a suite of tools that analyze the source code without executing it. This includes:
      • Linting: Checks for stylistic errors and bad practices.
      • Static Application Security Testing (SAST): Tools like SonarQube or Snyk scan for common security vulnerabilities in your code.
      • Dependency Scanning: Checks your project's dependencies (e.g., Maven/Gradle packages) for known vulnerabilities.
    • Quality Gate: The gate fails if the number of critical or high-severity vulnerabilities exceeds zero, or if the code quality rating falls below a predefined standard.
  3. Package & Scan Artifact:

    • Action: If all previous gates pass, the application is packaged into its distributable format. In modern cloud-native environments, this usually means building a Docker container image.
    • Image Scanning: The resulting container image is scanned for vulnerabilities in its layers, including the base OS and any installed packages. Tools like Trivy, Clair, or cloud-native scanners (e.g., in ACR or ECR) are used here.
    • Quality Gate: The pipeline fails if the image scan discovers critical vulnerabilities.
  4. Publish Artifact:

    • Action: The validated, versioned container image is pushed to a container registry (e.g., Azure Container Registry, AWS ECR, Docker Hub). This artifact is now immutable and ready for deployment to various environments.

At the end of the CI phase, you have a high degree of confidence that your code is well-formed, passes basic tests, is free from known static security flaws, and is packaged correctly.


3. The Continuous Delivery (CD) Phase: Staged Deployments

The CD phase takes the validated artifact from the CI phase and deploys it through a series of progressively more critical environments. The goal is to test the application's behavior in a realistic, integrated setting.

For a practical, multi-environment approach tailored to Azure DevOps, let's review the design proposed in the following guide.

Azure DevOps Engineer Interview Guide: Story-Based ...

The 'Azure DevOps Engineer Interview Guide' provides a story-based scenario that perfectly outlines a multi-environment CD pipeline. This is a great model for your interview answers.

Read 'Scenario 3: Multi-Environment CI/CD Pipeline Design'. Pay close attention to the distinct purpose of each environment (Dev, Test/QA, Staging, Production) and the types of validation performed in each.

Based on that model, here's a typical progression of CD stages:

  1. Deploy to Dev/Test Environment:

    • Trigger: Automatic, upon successful completion of the CI phase.
    • Action: The container image is deployed to a shared development or QA environment.
    • Tests:
      • Smoke Tests: Basic health checks to ensure the application starts and key endpoints are responsive.
      • Integration Tests: These verify that your service communicates correctly with other services, databases, or external APIs (like the Kafka brokers you manage). This is where you test real interactions, not mocks.
      • API/Contract Tests: Ensure your application's API adheres to its defined specification.
    • Quality Gate: All automated smoke and integration tests must pass.
  2. Deploy to Staging Environment:

    • Trigger: Can be automatic after the Test stage or require a manual approval (e.g., from a QA lead).
    • Action: The same artifact is deployed to a staging environment, which should be a near-perfect replica of production (same infrastructure, configuration, networking).
    • Tests:
      • User Acceptance Testing (UAT): Manual or automated testing to ensure the new feature meets business requirements.
      • Performance/Load Testing: Simulates production-level traffic to check for performance regressions, bottlenecks, and scalability issues.
      • Dynamic Application Security Testing (DAST): Scans the running application for security vulnerabilities.
    • Quality Gate: This is often a formal gate requiring sign-off from multiple stakeholders (e.g., Product Manager, Security Officer) before proceeding to production.
  3. Deploy to Production:

    • Trigger: Almost always a manual, scheduled trigger with final approvals.
    • Action: The change is deployed to the production environment. Best practices favor progressive deployment strategies:
      • Canary Release: Release the new version to a small subset of users first.
      • Blue-Green Deployment: Deploy the new version to an identical, idle environment and then switch traffic over.
    • Post-Deployment Checks: Automated health checks and monitoring are critical. The pipeline should monitor key business and performance metrics for a short period after deployment.
    • Quality Gate: The ultimate gate is the health of the production system. If key metrics (e.g., error rate, latency) degrade, an automated rollback to the previous version should be triggered.
Test your understanding!

A team's pipeline successfully builds and deploys a new version of a microservice. However, in production, it starts failing because a downstream service it calls recently changed its API endpoint, a change that was not caught during testing.

In the multi-stage pipeline we just discussed, which stage and type of testing was most likely missing or improperly configured, leading to this failure?

Show answer

The most likely culprit is a missing or inadequate Integration Test in the Test/QA Environment.

Integration tests are specifically designed to catch issues like this. They test the interactions between services. A proper integration test suite would have deployed the new version of the microservice alongside its actual dependencies (not mocks) and verified that the API calls between them were successful. This would have immediately caught the endpoint change and failed the pipeline long before it reached production.


4. A Framework for Testing Strategy

We've mentioned many types of tests (unit, integration, performance). It's helpful to have a mental model for organizing them.

Testing Strategy for DevOps: What to Test and When

Dave Farley, a co-author of the book 'Continuous Delivery', provides a superb framework for thinking about testing strategy. This adds depth to your understanding beyond just listing test types.

Watch the segment from 02:27 to 05:49. Focus on the distinction he makes between 'commit tests' (for fast developer feedback) and 'acceptance tests' (to confirm release readiness). This maps directly to our CI and CD phases.

To summarize this powerful model:

  • Commit Stage Testing (CI Phase): Primarily unit tests. They answer the question: "Does the code do what the developer thinks it does?" They should be fast (under 5 minutes) and provide high confidence.
  • Acceptance Stage Testing (CD Phase): A broad category including integration, performance, and security tests. They answer the question: "Is the software ready to be released to users?" These tests are slower and more comprehensive.

Thinking in these terms helps you justify why you place certain tests at certain stages of the pipeline.


Key Takeaways & Practice

  • Narrative is Key: In an interview, walk through the pipeline stage by stage: CI (build, unit test, scan) followed by CD (deploy to Test, Staging, Prod).
  • Quality Gates Enforce Standards: Clearly state the purpose of each quality gate (e.g., "The gate after static analysis ensures we don't introduce known security vulnerabilities").
  • Environments Have a Purpose: Articulate the different roles of Test (functional integration), Staging (production replica for non-functional testing), and Production environments.
  • Testing Strategy: Differentiate between fast feedback tests (unit tests in CI) and slower, comprehensive acceptance tests (integration, performance in CD).

To prepare for your interviews, practice answering the following questions out loud, using the structure from this lesson.

  • Walk me through a CI/CD pipeline you've designed or worked on.
  • What are quality gates, and can you give me examples of gates you would implement for a production-critical service?
  • How do you decide what type of testing to run at each stage of your pipeline?
  • A developer wants to bypass a failing security scan to push an urgent fix. What are the risks, and how would you handle this situation?

Next Up

We've now designed the "what" and "how" of our pipeline. But the way developers manage code in Git has a huge impact on how this pipeline operates. In the next lesson, we'll dive into different branching strategies (like GitFlow and Trunk-Based Development) and discuss how they influence your CI/CD design and deployment frequency.