Study guide
12.2 Pipeline Optimization: Caching, Slicing & Concurrency
Microsoft Certified: Azure DevOps Engineer Expert AZ-400
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: Flow of Work, Traceability & Work Tracking
1.1 Flow of Work, GitHub Flow & Feedback Cycles 1.2 Work Tracking with Azure Boards & GitHub Projects 1.3 End-to-End DevOps Traceability & Quality Tracking
2 Chapter 2: DevOps Metrics, Dashboards & Team Collaboration
2.1 DORA Metrics, Flow Metrics & Dashboard Design 2.2 Lifecycle Metrics Across the Six DevOps Phases 2.3 Work Item Queries, WIQL Charts & Analytics 2.4 Project Documentation: Wikis, Mermaid Diagrams & Release Notes 2.5 Webhooks, Service Hooks & Microsoft Teams ChatOps
3 Chapter 3: Git Branching Strategies & Pull Request Workflows
3.1 Git Branching Models & Strategy Design 3.2 Pull Request Workflows & Merge Strategies 3.3 Branch Policies, Quality Gates & Compliance Restrictions
4 Chapter 4: Repository Management, Optimization & Git Data Operations
4.1 Git LFS Architecture & .gitattributes Tracking 4.2 LFS History Migration, git-fat & File Locking 4.3 Git Repository Scaling, Scalar & Monorepo Governance 4.4 Repository Permissions & Git Tag Governance 4.5 Git Data Recovery & Sensitive-Data Scrubbing
5 Chapter 5: Package Management & Dependency Versioning
5.1 Selecting Package Tools: Azure Artifacts vs. GitHub Packages 5.2 Feed Scoping, Upstream Sources & Pipeline Authentication 5.3 Package Views, Immutability & Quality Promotion 5.4 Dependency Versioning: SemVer, CalVer & Automated Versioning 5.5 Pipeline Artifact Versioning & Artifact Storage Strategy
6 Chapter 6: Pipeline Infrastructure, Agents & Integration
6.1 Selecting a CI/CD Solution: Azure Pipelines vs. GitHub Actions 6.2 GitHub-Azure Pipelines Integration & Hybrid Migration 6.3 Hosted vs. Self-Hosted Agents & Runners 6.4 VMSS Elastic Pools, Container Jobs & Agent Governance 6.5 Pipeline Triggers, Filters & Concurrency Management
7 Chapter 7: YAML Pipeline Architecture & Reusable Elements
7.1 YAML Pipeline Anatomy: Stages, Jobs, Steps & Workspaces 7.2 Job Execution Order: DAG Dependencies, Parallelism & Conditions 7.3 Reusable Elements: Templates, Parameters & Variables 7.4 Variable Groups, Secret Variables & Key Vault Linking 7.5 YAML Environments, Checks & Deployment Approvals
8 Chapter 8: Testing Strategy, Quality Gates & Code Coverage
8.1 Test Strategy Design: Local, Unit & Integration Testing 8.2 Load, Stress & Performance Testing in Pipelines 8.3 Test Execution Tasks, Agents & Results Integration 8.4 Code Coverage Analysis & SonarQube Integration 8.5 Quality Gates, Release Gates & Governance Checks
9 Chapter 9: Modern Deployment Strategies & Zero-Downtime Delivery
9.1 Progressive Delivery: Blue-Green, Canary & Ring Deployments 9.2 Minimizing Downtime: Deployment Slots & Rolling Updates 9.3 Feature Flags with Azure App Configuration & Feature Manager 9.4 Designing the High-Priority Hotfix Path 9.5 Ordered Dependency Deployments, Resiliency & Rollback
10 Chapter 10: Artifact Deployment & Database DevOps
10.1 Containerized Application Delivery: ACR, AKS & Container Apps 10.2 Binary, Web App, Function & Scripted Deployments 10.3 Database DevOps: State-Based & Migration-Based Strategies
11 Chapter 11: Infrastructure as Code (IaC) & Azure Deployment Environments
11.1 Infrastructure as Code Strategy: Bicep, ARM & Terraform 11.2 Desired State Configuration & Azure Machine Configuration 11.3 Azure Deployment Environments (ADE) & Developer Self-Service
12 Chapter 12: Pipeline Maintenance, Health & Modernization
12.1 Pipeline Health, Flaky Tests & Reliability Engineering 12.2 Pipeline Optimization: Caching, Slicing & Concurrency 12.3 Artifact & Build Retention Governance 12.4 Modernizing CI/CD: Classic to YAML Migration
13 Chapter 13: Authentication, Authorization & Identity Governance
13.1 Microsoft Entra Service Principals & Managed Identities 13.2 Service Connections, Workload Identity & Personal Access Tokens 13.3 Azure DevOps Projects, Teams & Permission Evaluation 13.4 Access Levels, GitHub Roles & Outside Collaborators
14 Chapter 14: Secrets Management, Sensitive Data & DevSecOps Scanning
14.1 Azure Key Vault, Secret Variables & Secretless CI/CD 14.2 Security Scanning Strategy, GHAS & Secret Scanning 14.3 CodeQL SAST in Pipelines and Containers 14.4 Software Supply Chain, Container Scanning & Cloud Defender
15 Chapter 15: Telemetry Collection, Azure Monitor & Alerting
15.1 Azure Monitor Architecture, AMA & Data Collection Rules 15.2 Application Insights & Specialized Azure Monitor Insights 15.3 Alerting Rules, Action Groups & GitHub Repository Insights
16 Chapter 16: Telemetry Analysis, Distributed Tracing & SRE Practices
16.1 Distributed Tracing, Application Map & Exception Triage 16.2 KQL Log Analytics, SRE Observability & Error Budgets
12.2 Pipeline Optimization: Caching, Slicing & Concurrency
Key Takeaways Explain This Topic AI
Shallow fetch and disabling submodule or LFS checkout remove clone time from every run of a large repository.
The Cache@2 task restores a keyed archive; the key normally hashes a lock file so a dependency change invalidates the cache automatically.
Cache entries are evicted by least-recently-used after seven days without access, and each entry is capped at 10 GB.
Test slicing with a parallel strategy distributes a suite across agents, cutting wall-clock time in proportion to the parallel jobs purchased.
Matrix strategies multiply a job across configurations and consume one parallel job per leg, so concurrency cost scales with matrix size.
Last updated: September 2026
12.2 Pipeline Optimization: Caching, Slicing & Concurrency
As enterprise software portfolios grow, CI/CD pipelines naturally accumulate build tasks, security scans, packaging steps, and automated tests. Without deliberate performance engineering, pipeline runtimes degrade from minutes to hours. Long pipeline durations stifle developer experimentation, delay hotfixes, and escalate cloud infrastructure costs.
Concurrently, organizations generate petabytes of build artifacts, symbols, container layers, and test logs. DevOps architects must balance the need for fast feedback and rapid execution with strict regulatory governance, auditing retention mandates, and storage cost controls. On the AZ-400 exam, candidates must design high-throughput pipelines using the Cache@2 task, parallel test slicing, agent autoscaling, and comprehensive build retention leases.
1. Optimizing Pipeline Duration & Fast Feedback Velocity
A central tenet of DevOps is the Fast Feedback Loop . When a developer commits code, automated feedback should arrive within minutes, while the mental context of the change is still fresh. ┌─────────────────────────────────────────────────────────────────────────────────┐
- │ PIPELINE BOTTLENECK ANALYSIS MATRIX │
- ├──────────────────────────┬───────────────────────┬──────────────────────────────┤
- │ Pipeline Stage │ Typical Bottleneck │ Architectural Solution │
- ├──────────────────────────┼───────────────────────┼──────────────────────────────┤
- │ 1. Source Checkout │ Multi-GB git history, │ • Shallow clones │
- │ │ submodules, tags │ (fetchDepth: 1) │
- │ │ │ • Exclude tags (fetchTags: false)│
- ├──────────────────────────┼───────────────────────┼──────────────────────────────┤
- │ 2. Dependency Resolution │ Downloading hundreds │ • Pipeline Caching (Cache@2) │
- │ │ of npm/NuGet packages │ • Local Artifact Feeds │
- │ │ over public internet │ • Upstream Feed Caching │
- ├──────────────────────────┼───────────────────────┼──────────────────────────────┤
- │ 3. Code Compilation │ Rebuilding unchanged │ • Incremental builds │
- │ │ code modules from zero│ • Compiler caches (ccache) │
- │ │ │ • Pre-baked golden VM images │
- ├──────────────────────────┼───────────────────────┼──────────────────────────────┤
- │ 4. Automated Testing │ Sequential execution │ • Parallel Test Slicing │
- │ │ of thousands of tests │ • Test Impact Analysis (TIA) │
- │ │ │ • Distributed test runners │
- ├──────────────────────────┼───────────────────────┼──────────────────────────────┤
- │ 5. Artifact Publishing │ Uploading uncompressed│ • Targeted path filters │
- │ │ binaries and symbols │ • Pipeline Artifacts (v2) │
- │ │ │ • Compress before upload │
- └──────────────────────────┴───────────────────────┴──────────────────────────────┘
- Source Checkout Optimization
By default, Azure Pipelines performs a deep git fetch. For repositories with long commit histories, cloning the entire history consumes significant time and disk bandwidth: steps:
- checkout: self
- fetchDepth: 1 # Shallow clone: fetches only the tip commit
- fetchTags: false # Skips downloading git tags
- submodules: false # Disables recursive submodule fetching unless required
- 2. Pipeline Caching with the Cache@2 Task
Ephemeral build agents (such as Microsoft-hosted agents or auto-reimaged VMSS agents) start with an empty local filesystem for every job. Without caching, package managers like npm , NuGet , Maven , pip , or Gradle must download every dependency from remote registries over the internet on every single run.
Pipeline Caching stores build outputs, package dependencies, and compiler caches in Azure DevOps cloud storage, making them available across pipeline runs. [Pipeline Run Starts]
- │
- ▼
- [Cache@2 Task: Evaluates Key]
- 'npm | "$(Agent.OS)" | package-lock.json'
- │
- ┌─────────────────┴─────────────────┐
- ▼ ▼
- [CACHE HIT] [CACHE MISS]
- │ │
- ▼ ▼
- Downloads tarball from cloud Evaluates restoreKeys fallback
- Extracts to ~/.npm in seconds (e.g., 'npm | "$(Agent.OS)"')
- │ │
- ▼ ▼
- Sets CACHE_RESTORED = 'true' Runs full npm ci from registry
- Skips redundant download tasks At end of job: Uploads cache tarball
- Cache Keys and Restore Keys Syntax
The Cache@2 task relies on a primary key and optional fallback restore keys:
Primary Key ( key ) : A structured string comprising literal strings, dynamic pipeline variables, and file hashes (using the hashFiles() utility). When any dependency changes in package-lock.json , the hash changes, generating a new primary key.
Restore Keys ( restoreKeys ) : Fallback keys searched if the primary key misses. Azure DevOps searches restore keys using prefix matching, restoring the most recently saved cache matching the prefix. This enables incremental updates .
Cache Hit Variable ( cacheHitVar ) : A variable populated with 'true' when the primary key matches exactly. Subsequent steps can evaluate this variable in their condition: to skip package installation altogether.
Complete Cache@2 YAML Example (Node.js / npm) variables:
npm_config_cache: $(Pipeline.Workspace)/.npm
steps:
- # 1. Evaluate and restore npm cache
- task: Cache@2
- displayName: 'Cache npm packages'
inputs:
- key: 'npm | "$(Agent.OS)" | package-lock.json'
- restoreKeys: |
- npm | "$(Agent.OS)"
- npm
- path: $(npm_config_cache)
- cacheHitVar: CACHE_RESTORED
- # 2. Run npm ci only if cache missed or needs reconciliation
- script: npm ci --cache $(npm_config_cache) --prefer-offline
- displayName: 'Install npm dependencies'
- condition: ne(variables.CACHE_RESTORED, 'true')
- # 3. Compile application
- script: npm run build
- displayName: 'Compile Angular/React Client'
Caching Across Common Package Ecosystems ┌─────────────────────────────────────────────────────────────────────────────────┐
- │ CACHE@2 STRATEGIES BY ECOSYSTEM │
- ├──────────────┬────────────────────────────────┬─────────────────────────────────┤
- │ Ecosystem │ Path to Cache │ Primary Key Pattern │
- ├──────────────┼────────────────────────────────┼─────────────────────────────────┤
- │ npm / Yarn │ $(Pipeline.Workspace)/.npm │ 'npm | "$(Agent.OS)" | │
- │ │ │ package-lock.json' │
- ├──────────────┼────────────────────────────────┼─────────────────────────────────┤
- │ NuGet (.NET) │ $(UserProfile)/.nuget/packages │ 'nuget | "$(Agent.OS)" | │
- │ │ │ **/packages.lock.json' │
- ├──────────────┼────────────────────────────────┼─────────────────────────────────┤
- │ Python (pip) │ ~/.cache/pip │ 'pip | "$(Agent.OS)" | │
- │ │ │ requirements.txt' │
- ├──────────────┼────────────────────────────────┼─────────────────────────────────┤
- │ Java (Maven) │ ~/.m2/repository │ 'maven | "$(Agent.OS)" | │
- │ │ │ **/pom.xml' │
- ├──────────────┼────────────────────────────────┼─────────────────────────────────┤
- │ C/C++ │ $(Pipeline.Workspace)/.ccache │ 'ccache | "$(Agent.OS)" | │
- │ (ccache) │ │ src/**/CMakeLists.txt' │
- └──────────────┴────────────────────────────────┴─────────────────────────────────┘
- Cache Constraints and Invalidation Rules
Size Limits : An individual cache entry can be up to 10 GB . Organizations have total project cache limits based on subscription tier.
Eviction Policy : Azure Pipelines automatically evicts cache entries that have not been accessed within 7 days using a Least Recently Used (LRU) algorithm.
Post-Job Execution : The Cache@2 task restores dependencies during the step execution, but uploads the cache during a hidden post-job step . If any preceding step in the job fails, the cache upload is skipped by default to avoid persisting corrupted or partial dependencies.
3. Parallel Execution Optimization: Slicing, Matrix & Autoscaling
When optimizing build and test pipelines, parallelization delivers dramatic runtime reductions.
Parallel Test Slicing ( strategy: parallel )
Large enterprise test suites (e.g., 5,000 automated functional tests) can take hours on a single agent. Test slicing splits test execution across multiple parallel agents: jobs:
- job: SlicedIntegrationTests
- displayName: 'Execute Sliced Tests across Agents'
strategy:
parallel: 4 # Spawns 4 concurrent agent jobs
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
- task: DotNetCoreCLI@2
- displayName: 'Run Sliced Unit Tests'
inputs:
- command: 'test'
- projects: '**/*Tests.csproj'
- arguments: '--configuration Release'
When combined with VSTest@2 test slicing, Azure Pipelines automatically monitors test runtimes and divides the test assemblies across the 4 agents such that each agent completes approximately at the same time.
Matrix Strategies ( strategy: matrix )
A matrix strategy runs the same job across permutations of operating systems, runtime targets, or database versions: jobs:
- job: CrossPlatformValidation
strategy:
matrix:
Linux_Node18:
- osImage: 'ubuntu-latest'
- nodeVersion: '18.x'
Linux_Node20:
- osImage: 'ubuntu-latest'
- nodeVersion: '20.x'
Windows_Node20:
- osImage: 'windows-latest'
- nodeVersion: '20.x'
- maxParallel: 2 # Throttles concurrency to protect agent pool capacity
pool:
vmImage: $(osImage)
steps:
- task: NodeTool@0
inputs:
- versionSpec: $(nodeVersion)
- script: npm test