Lesson389 words

Optimising a pipeline

Optimize a pipeline for cost, time, performance, and reliability

Measure, change, verify

Baseline pipeline-duration percentiles, per-task duration, and queued/running-job pressure. Identify the measured constraint, change one lever, then compare duration, failures, queueing, and cost/quota consumption. Repeat rather than stacking unmeasured changes.

The levers

LeverEffect
CachingAccelerate cross-run regeneration; cache absence must not make the job fail
ParallelismSplit independent work across jobs when dependencies, agents, and capacity allow
Path filtersDo not build at all for documentation-only commits
MatrixOne definition, many legs, throttled by maxParallel
Pipeline artifactsCarry required outputs between jobs; unlike a cache, their absence is a failure
Agent choiceBalance clean/stateless isolation against deliberate state reuse and ownership

Caching and the key

A Cache@2 primary key can combine stable tool/OS discriminators with a lockfile path; the task hashes the file contents. Caches are immutable. A fixed overbroad key can retain outdated contents, while an overspecific primary key reduces exact-hit reuse. restoreKeys can return a partial hit when the exact key misses, so a commit SHA defeats cross-commit exact reuse but not every possible fallback hit.

yaml
- task: Cache@2 inputs: key: 'npm | "$(Agent.OS)" | package-lock.json' restoreKeys: | npm | "$(Agent.OS)" path: $(Pipeline.Workspace)/.npm

Measure restore/save overhead and test the cache-miss path. Use a pipeline artifact—not a cache—for files a downstream job requires.

Capacity, agents, and cost

Azure DevOps YAML jobs run in parallel by default only when no dependency blocks them and agents plus organization-level parallel-job capacity are available. Declare dependsOn for required ordering and bound matrix fan-out with maxParallel.

Private projects can use a monthly-limited Microsoft-hosted free tier or paid parallel-job capacity with no monthly limit. Self-hosted capacity is also licensed by concurrent jobs, while its machines, patching, and isolation remain your responsibility. Microsoft-hosted pools supply a clean VM. Managed DevOps Pools add a managed choice: stateless supplies a fresh agent for each job; stateful reuse can preserve files/packages but needs an explicit security and cost decision. Benchmark VM size, storage, region, standby, and state instead of assuming bigger or warmer is better.

Primary sources

Ready to study Designing and Implementing Microsoft DevOps Solutions (AZ-400)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free