Course contentsShow
← Cloud and Infrastructure
Lesson 1738 of 2,98936. GitLab CI/CDFree lesson

Cache vs Artifacts: Performance Optimization

Understand the difference between cache and artifacts, and when to use each for optimal pipeline performance.

Cache vs Artifacts: Performance Optimization

What you'll learn: How to choose between cache and artifacts to speed up your GitLab pipelines without wasting resources.

The Core Difference

Both cache and artifacts store files between pipeline runs, but they serve fundamentally different purposes:

Artifacts are outputs your pipeline produces — build binaries, test reports, compiled assets. They're the "deliverables" that later jobs or humans need to consume. Artifacts move forward through your pipeline stages and can be downloaded from the GitLab UI.

Cache is about speeding up repeated work. It stores dependencies or intermediate files that don't change often but take time to download or generate — like node_modules, Maven dependencies, or compiled object files. Cache is a performance optimization, not a guarantee.

The Restaurant Analogy

Think of artifacts as the finished dishes you send from the kitchen to customers — they're the point of your work.

Cache is like the pantry of staple ingredients (flour, oil, spices) that multiple cooks reuse across shifts. You could buy fresh ingredients every time, but keeping them stocked saves trips to the store. If the pantry empties occasionally, you just restock — no disaster.

When to Use Each

Use artifacts when:

  • Jobs downstream need the files (test results, binaries)
  • You want to download outputs after the pipeline completes
  • The data represents work that shouldn't be repeated

Use cache when:

  • Dependencies rarely change (package managers)
  • Rebuilding is expensive but not critical
  • Multiple pipelines reuse the same files

Performance Impact

Artifacts are uploaded/downloaded every time. Cache might not be available (cache miss), so your job must handle that gracefully. Over-caching bloats storage; under-caching wastes rebuild time.

Key Takeaway: Use artifacts for pipeline outputs you must keep; use cache for dependencies you can reuse. Artifacts are reliable delivery; cache is optional speed.