Content-Addressed Storage for Build Artifacts with Retention (CAS-BAR)
Overview
CAS-BAR is a scalable, deduplicating storage system for immutable build artifacts (e.g., binaries, packages, Docker layers) from CI/CD pipelines. Artifacts are addressed by their SHA-256 content hash, enabling automatic deduplication across builds and projects. Retention policies ensure artifacts are garbage-collected when no longer needed, based on per-project rules like "keep last N builds" or "retain for T days."
Key features:
Content-addressable: Store/retrieve by hash; identical content shares storage.
Deduplication: Global across all users/projects.
Retention: Reference-counted GC tied to build lifecycle.
Scalable: Layered on object storage (e.g., S3) or filesystem.
API-first: REST/gRPC for uploads, downloads, and metadata.
Mark expired builds: UPDATE builds SET gc_pending=true WHERE retained_until < NOW() AND NOT latest_N.
GC Steps (Cron: every 1h)
pseudocode
expired_builds = SELECT * FROM builds WHERE gc_pending;
for build in expired_builds:
for hash in build.artifacts:
UPDATE artifact_refs SET refcount -= 1 WHERE hash = ?;
if refcount == 0:
DELETE FROM blob_store WHERE key = hash_key(hash);
DELETE FROM builds WHERE id = build.id;
Optimizations:
Batch updates (e.g., 1000 refs at once).
Lazy GC: Mark for deletion, async blob purge.
Quotas: Track total size_bytes * refcount per project.
Safety: Dry-run mode; refcount never goes negative (atomic ops).
Storage Layout
Key Format: {hash[0:2]}/{hash[2:4]}/{hash}.blob
E.g., S3: s3://bar-blobs/a1/b2/a1b2c3....blob
Metadata: Optional hash.metadata.json with MIME, upload_time.
Backends:
Backend
Pros
Cons
Local FS
Fast, cheap
Not HA
S3/GCS
Durable, infinite scale
Latency/cost
MinIO
Self-hosted S3
Ops overhead
Scalability & Ops
Horizontal Scale: API servers stateless; shard DB by project_id. Blob store handles petabytes.