Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 124/ 160
07. Deployment

CI/CD Pipelines

Automate build, test, eval, and deploy steps for AI applications.

BeginnerBuild · Test3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

CI/CD automatically tests and ships every change, so mistakes are caught early and releases are routine.

Think of it like…

A factory line with quality checkpoints: each product passes the same inspections in the same order, defective ones are stopped before shipping, and what leaves the factory is the exact unit that was inspected.

Where you’ve seen it

A team's pipeline for an assistant has these stages with typical times: lint and type-check 1 min; unit tests 3 min; build and scan the image 4 min; a smoke eval of 40 stratified cases 0.5 min (about $0.48 in model calls); deploy to staging 3 min; integration tests with mocked providers 2 min; a manual approval; then a canary to production. Total about 13.5 minutes to staging. With 25 PRs a day the smoke eval costs 25 × $0.48 = $12 a day, while the full 300-case suite ($3.60) runs nightly and before releases. Path filters mean documentation-only changes skip evals; image layers and dependencies are cached; the deploy job pulls the image built earlier by SHA instead of rebuilding. Secrets for provider keys are stored in the CI secret store and exposed only to jobs that need them (never to PRs from forks). Pipeline metrics (lead time, deployment frequency, change failure rate, time to restore) are tracked: lead time fell from 2 days to 3 hours, and change failure rate from 18% to 6% after eval gates were added.

Words you’ll hear

Continuous integration
Automatically building and testing every change.
Continuous delivery / deployment
Automatically promoting a tested artefact toward production, with or without approval.
Eval gate
A pipeline step that fails when AI quality, safety or cost regress.
DORA metrics
Lead time, deployment frequency, change failure rate and time to restore.

Visual diagram

Loading interactive diagram

Theory & deep dive

Stages and design principles

Order stages from cheapest and fastest to most expensive: formatting and linting, type checks, unit tests, then image build and vulnerability scan, then evals and integration tests, then deployment. Fail fast and run independent jobs in parallel. Build once: produce an immutable artefact (a container image tagged with the commit SHA), and deploy that exact artefact to staging and production, with environment differences supplied by configuration, never by rebuilding. Trunk-based development with short-lived branches and feature flags keeps changes small; every merge to main is releasable. Use environments with protection rules (required reviewers for production), secrets scoped per environment and short-lived credentials (OIDC) instead of long-lived keys.

For AI services add AI-specific checks: unit tests for parsing, validation and tool schemas; prompt linting (variables present, token count within budget); a smoke eval on every relevant PR and a full eval nightly or before release; safety checks (an injection suite with an action-level success threshold); and cost and latency gates (tokens per request, p95). Make LLM-dependent tests tractable with mocks for provider calls in unit and integration tests, recorded responses for deterministic replays and a small live suite at fixed temperature with tolerance bands, run only where it adds signal. Treat flaky tests as bugs: quarantine with an owner, don't retry until green.

Eval cost in CI

Smoke eval: 40 cases ≈ $0.48 per run. 25 PRs a day × $0.48 = $12 a day. Nightly full suite: 300 cases ≈ $3.60. Total ≈ $15.60 a day, a small price compared with a quality regression reaching users.

Key takeaway: Order checks by cost, build once and promote, and add eval, safety and cost gates alongside ordinary tests.

Delivery, rollout and measurement

Continuous delivery keeps every build deployable and releases on demand; continuous deployment releases automatically when checks pass. For AI features prefer progressive delivery: deploy dark behind a feature flag, run shadow traffic, then a canary (5%, 25%, 100%) with automated analysis of error rate, latency, cost and quality signals and automatic rollback if thresholds are breached. Keep database migrations backwards compatible (expand/contract) so rollbacks are safe, and version prompts and models as deployable artefacts (see prompt and model versioning). Store pipeline definitions as code, reuse workflows across repositories and keep runners and caches tuned: dependency and Docker layer caches commonly cut build time by half or more.

Measure the pipeline: lead time for changes, deployment frequency, change failure rate and time to restore (the DORA metrics), plus pipeline duration, flaky-test rate and cost per run. In the example, adding eval gates reduced change failure rate from 18% to 6% and automatic rollback cut time to restore. Guard against pipeline security risks: pin third-party actions or plugins by commit SHA, restrict permissions to least privilege, never expose secrets to untrusted PRs (forks), sign and scan artefacts and audit who can approve production. Document the release process and keep a manual override for emergencies, with the same checks as far as possible.

Progressive delivery

Merge → image built and scanned → staging → canary at 5% for 30 minutes (auto-compare error rate, p95 latency, cost per request, safety flags with the baseline) → 25% for an hour → 100%. Any breach triggers rollback to the previous image without human action.

Key takeaway: Use progressive delivery with automated analysis and rollback, keep migrations reversible and track DORA metrics.

How it works, step by step

Step 1 of 4
Engineering

1. Define the pipeline stages

Order lint, types, unit tests, build, scan, evals, integration tests and deployment from cheapest to costliest.

13.5 min to staging
Key numbers at this step
Parallelise
independent jobs

When to use it & trade-offs

What it is

CI/CD automates the path from a code change to production. Continuous integration runs on every pull request: lint, type-check, unit tests, build the container image and, for AI apps, run a small evaluation suite against prompts, retrieval and tools. Continuous delivery/deployment then promotes the same built artefact through environments (staging, then production) with automated checks, approvals where needed and a gradual rollout. For AI systems the pipeline also handles things ordinary apps don't: prompt and model versions as artefacts, eval gates (quality, safety, cost, latency), non-deterministic tests, provider cost and secrets for model APIs.

Why it matters: AI changes break quietly: a prompt edit passes unit tests but degrades a category of answers, a dependency bump changes tokenisation, a model alias moves. Manual release checklists don't scale, and slow, flaky pipelines get bypassed. A good pipeline is fast (minutes), trustworthy (flaky tests are fixed, not retried until green), safe (gates and gradual rollout) and cheap enough to run on every change.

When to reach for it

  • Every AI application with prompts, models and tools
  • Gating quality, safety and cost regressions
  • Reducing release risk and lead time

When to avoid or be careful

  • Rebuilding artefacts per environment
  • Retrying flaky tests until they pass
  • Exposing provider secrets to untrusted pull requests

Release approaches

Continuous deployment with gates
Best for: Mature teams with strong automated checks

Strengths: Fast lead time; small changes; consistent.

Watch out: Needs reliable tests and rollback.

Continuous delivery with manual approval
Best for: Higher-risk or regulated changes

Strengths: Human check before production.

Watch out: Slower; approval fatigue.

Manual releases
Best for: Nothing sustainable

Strengths: No automation work.

Watch out: Error-prone, slow and inconsistent.

Interview signals & numbers to know

When this topic comes up

  • “Releases are scary”
  • DORA metrics
  • Eval gates in CI
  • Build once, deploy many
  • Progressive delivery

Benchmarks & rules of thumb

13.5 min -
time from commit to staging in the example
$12/day + $3.60/night -
eval cost at 25 PRs a day
18% → 6% -
change failure rate after adding eval gates

Common mistakes & follow-ups

Common interview mistakes

  • Running expensive live LLM tests on every commit.
  • Allowing production deploys without a rollback path.
  • Letting the pipeline grow to an hour and being bypassed.

Likely interviewer follow-ups

  • How would you design CI/CD for an LLM application?
  • Why build once and promote the same artefact?
  • How do you keep AI tests from being flaky and expensive?
Interview tip: Quote pipeline time, eval cost and a DORA metric. Numbers show you run the pipeline as a product.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply CI/CD Pipelines with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Kubernetes Basics
Next topic
GitHub Actions