Skip to content

Advanced Level

This section covers expert-level CI/CD practices and implementation strategies.

0 / 20 reviewed (0%)
  1. What are self-hosted runners, and when should you use them?

    Self-hosted runners are machines you own and register with the CI platform to execute jobs, instead of using the provider's hosted fleet:

    • Reach private resources — runners inside your VPC can hit internal databases, staging clusters, and artifact stores that hosted runners can't see
    • Special hardware — GPUs for ML builds, ARM for mobile, large memory for monorepo compiles
    • Cost at scale — high-volume teams can be cheaper on reserved infrastructure than per-minute hosted pricing
    • Compliance — build isolation requirements that demand your own hardware

    The security trade-off interviewers probe: hosted runners are ephemeral and disposable, while self-hosted runners are persistent — a malicious PR could plant a payload that persists. Mitigations: run self-hosted runners only for trusted repos, use ephemeral containerized runners that are destroyed per job, and never reuse state between runs.

  2. How does caching improve CI/CD performance, and how do you get it right?

    Caching skips re-downloading unchanged inputs — dependency installs and Docker layer rebuilds are usually the top two time sinks:

    yaml
    - uses: actions/cache@v4
      with:
        path: ~/.npm
        key: node-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
        restore-keys: node-${{ runner.os }}-

    Getting it right:

    • Key on the input's hash — the lockfile hash guarantees the cache matches exactly what the build needs; restore-keys gives partial fallback so a changed lockfile still reuses most packages
    • Cache invalidation is the whole game — a stale cache is worse than no cache (mysterious "works locally" failures); prefer hash-based keys over time-based purges
    • Docker layer caching — order Dockerfiles so dependency layers come before source-copy layers; use BuildKit's registry-backed cache in CI
    • Remote build caches — Gradle/Bazel/Turborepo cache compiled outputs keyed by input hashes, so unchanged modules never recompile

    Measure before and after: a cache that doesn't move p95 pipeline duration isn't worth its maintenance.

  3. What is parallel (matrix) execution in CI/CD?

    Parallel execution splits one pipeline into concurrent jobs to cut wall-clock time:

    yaml
    strategy:
      matrix:
        node: [18, 20, 22]
        os: [ubuntu-latest, windows-latest]
      max-parallel: 4      # bound the concurrency cost
      fail-fast: false     # let all combinations finish for a full report
    shard:                 # or split one suite into chunks
      total: 4
      index: ${{ matrix.shard }}
    • Matrix builds — test the same code across versions/OSes simultaneously
    • Test sharding — divide one slow suite across N runners, each running a slice; results merge at the end
    • Fan-out/fan-in — independent stages (frontend, backend, docs) run in parallel and converge on a final gate

    Two costs to manage: concurrency spend (runners are billed per-minute — use max-parallel deliberately) and result merging (one red shard must fail the whole job, with artifacts/reports aggregated from every shard).

  4. What is the difference between static and dynamic analysis in CI/CD security?

    • Static analysis (SAST) — inspects source/bytecode without running it: code flaws (SQL injection patterns, hardcoded secrets), dependency CVEs (SCA), IaC misconfigs (Checkov). Runs on every PR — fast, precise location, no test environment needed
    • Dynamic analysis (DAST) — attacks the running application: OWASP ZAP or Burp probing a staging deployment for auth flaws, XSS, and misconfigurations that only appear at runtime. Slower, needs a live environment, catches what static analysis structurally can't (runtime behavior, server configs)

    A mature pipeline runs both at different stages: SAST on the PR (minutes, fail-fast), DAST nightly or pre-release against staging. The honest caveat: both produce noise — severity tuning and triage workflows are what make them usable.

  5. How do feature flags integrate with CI/CD?

    Feature flags decouple the two decisions CI/CD usually merges: deploying code and activating a feature:

    code
    deploy (always safe) → flag off → gradual flag rollout (1% → 10% → 100%) → flag retired
    • Pipeline impact — deployments become low-drama: unfinished or risky features ship dark, so integration risk stays low and main stays releasable (the enabler of trunk-based development)
    • Operational uses — instant kill switch (faster than any rollback), canary-by-cohort, A/B experiments, and entitlement gating
    • The engineering discipline — treat the flag system as production infrastructure (Slack/LaunchDarkly/Unleash); every flag needs an owner and an expiry ticket; dead flags get removed on a schedule
    • Testing implication — CI must cover both flag states (or test flag combinations) — a feature flag multiplies the config matrix

    The summary line: flags move risk management from deploy time to runtime, which is why high-frequency deployers are heavy flag users.

  6. How do you handle secrets in CI/CD pipelines securely?

    The modern answer removes long-lived secrets entirely:

    yaml
    # GitHub Actions: OIDC federation instead of stored AWS keys
    permissions:
      id-token: write
      contents: read
    steps:
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123456789:role/ci-deploy-role
          aws-region: us-east-1
    • Federation (OIDC) — the CI job exchanges a short-lived token for a scoped cloud role; nothing to leak, nothing to rotate
    • Vault dynamic secrets — database credentials minted per job with a TTL, expiring on their own
    • If static secrets are unavoidable — vault-managed, injected at runtime, masked in logs, scoped to the one job that needs them
    • Pipeline-level rules — never echo secrets, never pass them as build args (they land in image history), rotate on schedule and on suspicion

    The bar to state: the pipeline holds credentials to production — the design goal is that stealing any single secret yields an attacker nothing useful.

  7. What does observability mean for the CI/CD system itself?

    The pipeline is production infrastructure — it needs the same treatment:

    • Metrics — pipeline duration, queue time, success rate per workflow, flaky test rate, runner utilization; export to Prometheus/Datadog and dashboard them
    • Logs — structured, centralized pipeline logs with job/commit/run IDs so "why did this fail" is a query, not an archaeology dig
    • Traces — correlate commit → build → artifact → deployment → release as one chain (deploy tools like Argo/Spinnaker record this lineage)
    • Alerting — on symptoms that matter: main-branch red for more than N minutes, queue-time SLO breaches, credential-expiry warnings — not every individual job failure
    • Cost observability — runner spend per team/repo, because CI cost creeps silently

    The payoff to state: teams with pipeline observability fix broken builds in minutes and see flaky trends early; teams without it discover problems when releases pile up behind a red main.

  8. What is immutable infrastructure in a CI/CD context?

    Immutable infrastructure means deployed instances are never modified in place — every change produces a new artifact and a replacement fleet:

    code
    code change → build image vX → deploy new instances → drain/terminate old
    • What CI/CD changes — the pipeline's output becomes the only way change reaches production; SSH-and-patch workflows are deleted, not discouraged
    • Why it pairs with CI/CD — builds are reproducible, so "replace the fleet" is as cheap as "patch it"; rollback is redeploying image vX-1
    • Tools — containers/Kubernetes, Packer golden AMIs + auto-scaling groups, Terraform replacing resources
    • The trade-off to name — more builds and more image storage; mitigated by good layer caching and registry retention policies

    The drift-elimination is the interview point: servers that are never modified can't drift from their definition — the pipeline is provably the sole source of change.

  9. What are the key metrics for CI/CD performance?

    Combine DORA (outcome) metrics with pipeline-internal (mechanism) metrics:

    • Lead time for changes — commit → running in production; the single best agile-health number
    • Deployment frequency — how often production changes; correlates with smaller, safer releases
    • Change failure rate — % of deployments causing incidents/rollback; the safety-net check
    • MTTR (failed deployment recovery) — minutes to restore, rollback speed included
    • Pipeline duration & queue time — p95, not averages; queue time exposes runner starvation
    • Flaky test rate — reruns to pass / total runs; the silent killer of pipeline trust

    The reporting insight: track them as trends per team, never as cross-team leaderboards — the DORA research explicitly warns that gaming these numbers destroys the signal.

  10. How do you ensure zero-downtime deployments?

    Stack the primitives, because each covers a different failure mode:

    • Rolling updates with health gates — Kubernetes maxSurge/maxUnavailable + readiness probes: new pods only receive traffic once provably ready, and a stuck rollout aborts itself
    • Traffic-shifting strategies — blue-green (atomic switch, fastest rollback) or canary (metric-gated expansion, smallest blast radius)
    • Graceful shutdown — SIGTERM handling, connection draining, and preStop hooks so in-flight requests complete during pod replacement
    • Backward-compatible contracts — API and schema changes support old and new versions during the transition window (expand/contract)
    • Session/state strategy — externalized sessions, idempotent APIs, so instances can come and go freely

    The honest caveat to include: "zero downtime" is a property of the whole chain — one ungraceful SIGTERM handler or breaking schema migration is enough to drop requests, no matter how good the traffic shifting is.

  11. What is a release train, and when does it make sense?

    A release train ships on a fixed schedule — the train leaves at a set time, and whatever is ready (and only what is ready) boards; anything unfinished waits for the next train.

    • Predictability — QA, docs, marketing, and support plan around known release dates; the Chrome 4-week cycle is the canonical example
    • Small, contained scope — missing the deadline doesn't pressure anyone to rush half-done work; the next train is close
    • Works well when — releases need heavy coordination (mobile app-store review, embedded/firmware with hardware cycles), or regulated change processes apply
    • The contrast to know — continuous deployment releases per change, so it offers lower per-change risk and no train-waiting; the trains model trades some speed for coordination simplicity

    Hybrid pattern worth naming: continuous deployment for web services + a train for the mobile/mobile-embedded surface that users can't update server-side.

  12. How do you handle database migrations safely in an automated pipeline?

    The pipeline mechanics plus the design discipline:

    bash
    flyway validate    # schema history consistent, no pending checksum drift
    flyway migrate     # apply pending migrations, ordered and versioned
    ./deploy-app.sh    # application compatible with the NEW schema
    • Order is non-negotiable — migrations run before the new application version starts, and the migration must be backward-compatible so the previous app version survives the transition window
    • Design discipline (expand/contract) — additive changes first (add column, backfill), deploy code that uses them, remove old structure releases later; destructive changes are never coupled to a deploy
    • Guardrails — validate in CI (syntax + against a prod-scale copy), snapshot/backup before applying, advisory locks to prevent concurrent migrators, and a rehearsed manual fallback
    • Tool nuance to mention — flyway undo is a paid Teams feature, and Liquibase rollbacks require authored rollback files — so forward-fixable, additive migrations beat trusting a tool's undo
  13. What is trunk-based development at scale, and what does it demand?

    Trunk-based development means every developer integrates into main at least daily; nothing lives on a long-lived branch:

    • Branches last hours — code review on small PRs is fast; merge conflicts nearly vanish; the trunk is always releasable
    • Unfinished work hides behind flags — the flag system carries what release branches used to; this is the non-negotiable companion practice
    • What it demands from CI — a red main must be everyone's top priority (minutes, not days), fast PR pipelines (under ~10 minutes), and strong automated tests since there's no long staging branch to catch things
    • At scale — monorepos add affected-path builds and merge queues (batch PRs that conflict with each other get tested together before landing)

    The evidence to cite: trunk-based development with short-lived branches is one of the strongest correlates of high delivery performance in the DORA research.

  14. How do you implement blue-green deployments in Kubernetes?

    Two Deployments (blue, green) behind one switchable Service:

    yaml
    # The switch: Service selector points at the live version
    selector:
      app: web
      version: blue    # flip to "green" to switch 100% of traffic atomically
    • The flip — one selector/label change (or Ingress/weight change) moves all traffic; rollback is flipping it back
    • Safer than hand-rolled — Argo Rollouts or Flagger automate blue-green with preview endpoints, automated smoke tests before the switch, and auto-rollback on analysis failure
    • The details that matter — readiness gates so green only takes traffic when healthy; connection draining on the old pods; and database compatibility — both versions run simultaneously, so schema changes must be backward-compatible
    • Cost note — double capacity during the release window; downscale blue after green soaks

    Canary vs blue-green at this level: blue-green shifts all traffic at once (fastest rollback, full-blast exposure), canary shifts gradually (smallest blast radius, needs metric analysis).

  15. What is a service mesh, and how does it improve CI/CD?

    A service mesh (Istio, Linkerd, Consul) injects a sidecar proxy beside every workload, centralizing service-to-service traffic control:

    • Traffic shifting — precise percentage splits (90/10, 99/1) between versions enable canary releases at the mesh layer, without changing application code or only via Ingress
    • Resilience policies — retries, timeouts, outlier ejection (circuit breaking) declared as config — so a deploy with a flaky new version sheds traffic to healthy pods automatically
    • Security — automatic mTLS between services plus authorization policies; new deployments inherit zero-trust posture by default
    • Observability — per-version golden-signal metrics (rate/errors/latency) fall out for free — exactly the data canary analysis needs

    The honest trade-off to include: a mesh adds operational weight (control plane, sidecar overhead, upgrade toil) — small estates get the same CI/CD wins from Ingress-level tools; the mesh earns its cost at hundreds of services.

  16. What is progressive delivery, and how do you implement it?

    Progressive delivery extends CI/CD: instead of a binary "deployed or not", releases move through graduated, metric-verified exposure:

    code
    deploy dark (flag off) → internal users → 1% canary → 10% → 50% → 100% → flag cleanup
    • The moving parts — feature flags (release control), canary analysis (risk detection), and automated rollback (response)
    • Implementation — Argo Rollouts or Flagger on Kubernetes: they shift traffic, query Prometheus for the canary's error/latency deltas, promote or roll back automatically, and integrate flag platforms for the dark-launch phase
    • Gates need real metrics — define per-release analysis templates (error-rate delta, p99 latency, saturation) and a bake window; without them "progressive" is just slow
    • Organizationally — product decides when to widen exposure (business signal), while the pipeline decides whether (technical signal) — the separation is what makes it progressive rather than merely staged
  17. How do you handle long-running test suites in CI/CD?

    Attack test time in layers — it's usually the largest pipeline cost:

    • Parallelize and shard — split the suite across N runners (by file/timing data), merge results; nearly linear speedup until setup costs dominate
    • Test impact analysis / selective testing — run only tests affected by the change (Bazel/Turborepo dependency graphs, jest-related-only); in monorepos this is the difference between 8 minutes and 40
    • Kill the slowest suite's waste — mocks/stubs for external services (WireMock, Testcontainers for real-but-local dependencies), contract tests instead of full cross-service E2E
    • Manage flakiness deliberately — auto-quarantine flaky tests with a tracking issue, measure flake rate, and never let "just rerun" become the workflow
    • Right-size the schedule — full regression on merge or nightly; fast, targeted suites on every PR

    The target to state: PR feedback under ~10 minutes keeps developers in context; suites that take 30+ minutes get bypassed, and bypassed safety nets are worse than none.

  18. How does chaos engineering fit into CI/CD pipelines?

    Chaos experiments verify that resilience mechanisms actually work — and the pipeline is where they run repeatedly, not annually:

    • Pre-release chaos stages — against staging or a canary slice: kill pods, inject network latency, exhaust a connection pool, and assert the system holds its steady state (success rate, latency SLOs)
    • Tooling — LitmusChaos (Kubernetes-native, GitOps-friendly), Gremlin (hosted, safety controls), AWS FIS (cloud-native faults); each expresses an experiment as declarative config that lives in the repo
    yaml
    # Litmus: pod-kill experiment as pipeline step
    - name: run-chaos
      run: |
        kubectl apply -f experiments/pod-kill-checkout.yaml
        kubectl wait --for=condition=completed chaosengine/pod-kill --timeout=300s
    • The guardrails to state — experiments need a hypothesis and steady-state metrics (otherwise it's sabotage), a bounded blast radius, an abort switch, and a "game day" culture before automating against production
    • The CI/CD connection — resilience becomes a regression-tested property: every deployment is proven to survive known failure modes, not just to return 200s
  19. What are immutable deployments, and how do you implement them?

    Immutable deployments never modify a running instance — every release builds new instances and retires the old ones:

    • Bad pattern — SSH into servers, pull code, restart; drift accumulates, "snowflakes" appear, rollback is archaeology
    • Immutable pattern — the pipeline builds one versioned artifact (container image/AMI); deployment replaces the fleet from that artifact; rollback is redeploying the previous version

    Implementation path: containers + Kubernetes (the natural fit — pods are cattle), Packer-built golden AMIs with instance replacement in ASGs, or Terraform with create_before_destroy lifecycle. Serverless is immutable by construction.

    The subtle CI/CD implications: config must come from the environment (nothing is patched on the box), logs/state must be externalized (instances die routinely), and the image build must include everything the app needs — which is exactly what makes "build once, deploy the same artifact everywhere" enforceable.

  20. What are the best practices for securing a CI/CD pipeline end to end?

    Treat the pipeline as critical production infrastructure:

    • Identity first — OIDC federation for short-lived cloud credentials; per-pipeline/per-job least privilege; human access via SSO + MFA
    • Protect the supply chain — pin actions and base images by digest; verify third-party actions; generate SBOMs and sign artifacts (cosign/SLSA provenance); verify signatures at deploy admission
    • Isolate execution — ephemeral runners destroyed per job; untrusted PRs run on isolated, unprivileged runners only; secrets never exposed to fork PR builds
    • Gate everything — SAST/SCA/image/IaC scans with severity thresholds; branch protection with required reviews and green pipelines; protected environments with required approvers for production
    • Watch the pipeline itself — audit logs of who ran what, anomaly alerts on new workflow definitions or credential access, SIEM integration

    The completeness test to aim for in an interview: walk the attack path — "if an attacker compromises a developer laptop / a dependency / a runner, what stops them reaching production?" — and have a control named for each.