Content-Addressed Artifact Store (CAAS) Design
Overview
A content-addressed artifact store stores immutable blobs (artifacts like binaries, images, datasets) keyed by their cryptographic hash (SHA-256). This enables:
- Deduplication (dedup): Identical content shares one copy, checked via hash existence.
- Integrity: Content retrieval always verifies against the hash; mismatches indicate corruption/tampering.
- Retention: Configurable policies (refcount, time-based) with garbage collection (GC).
The design is simple, scalable, and fault-tolerant. It uses:
- Blob Store: Raw content storage (local FS, S3, or CAS like IPFS).
- Metadata Store: Refcounts, timestamps, indexes (LevelDB, RocksDB, PostgreSQL, or DynamoDB).
- Coordinator: API server handling ingest/retrieval/ref mgmt (e.g., Go/Rust app).
Assumes whole-blob storage for simplicity; block-based chunking extension provided for large artifacts (>1MB).
Architecture
+---------------+ +-------------------+ +-------------------+
| Clients |<----->| API Server |<----->| Metadata Store |
| (CLI/SDK) | TLS | (hashing, refs) | | (RocksDB/Dynamo) |
+---------------+ +-------------------+ | - hash -> {refcnt,|
| size, ctime, |
| expire_at, loc} |
+-------------------+
|
v
+-------------------+
| Blob Store |
| (FS/S3/Ceph) |
| hash -> content |
+-------------------+
- Paths: Blobs at
store/${hash:0:2}/${hash:2:2}/${hash} (prevents dir explosion).
- Total Size Tracking: Metadata aggregates usage for quotas.
Core Operations
1. Ingest (PUT(content) -> hash)
1. Compute hash = SHA256(content)
2. Lookup metadata by hash:
- Exists & refcount > 0: refcount += 1; return hash (dedup hit)
- Exists & refcount == 0: Treat as new (revived)
- Missing: Verify hash(content) == hash (integrity gate)
- Store blob at path(hash)
- Insert metadata: {refcount=1, size=len(content), ctime=now, expire_at=null}
- return hash (dedup miss)
- Idempotent: Retries safe.
- Atomicity: Use transactions (e.g., RocksDB batch) for metadata + blob.
2. Retrieve (GET(hash) -> content)
1. Lookup metadata: missing? -> 404
2. Fetch blob from path(hash)
3. Compute hash_fetched = SHA256(content)
4. if hash_fetched != hash: ERROR (integrity fail, quarantine blob)
5. return content
- Lazy refcount inc/dec optional for hot reads.
3. Reference Management (for Retention)
PIN(hash): refcount += 1 (e.g., build refs artifact)
UNPIN(hash): refcount -= 1
- If refcount == 0: Lazy-delete blob + metadata
LIST_REFS(hash): Query dependents (extend metadata with ref list if needed)
Retention Policies
Multi-policy support via metadata flags:
| Policy | Metadata Fields | GC Trigger | Use Case |
|---|
| Refcount | refcount (int) | refcount == 0 | Build artifacts, caches |
| Time-based | expire_at (time) | now > expire_at && refcount == 0 | Temp uploads (TTL=7d) |
| Quota | Global counter | Total size > quota: Evict LRU/0-ref | Disk-limited |
- Default: Refcount-only.
- Set on Ingest:
PUT(..., policy="ttl:7d") sets expire_at = now + 7d.
- Override:
SET_RETENTION(hash, policy).
Garbage Collection (GC)
Block-Based Extension (for Large Artifacts)
For >1MB artifacts (better dedup/parallelism):
- Chunking: Fixed 256KB blocks + Merkle tree.
- Block hashes: SHA256(block).
- Artifact hash: SHA256(serialize(block_hashes_tree)).
- Ingest:
- Chunk content → blocks.
- PUT each block (dedup per-block).
- Build/store Merkle root as "link" blob (hash -> {block_hashes[]}).
- Retrieve: Recurse Merkle tree, fetch/verify blocks.
- Benefits: 90%+ dedup on similar files (e.g., container layers); streaming fetches.
- Metadata: Per-block refs; artifact ref proxies to children.
Scaling & Ops
- Horizontal Scale:
- Shard by
hash % N_shards (consistent hashing).
- Gossip refs across nodes.
- Durability:
- Replicate blobs (e.g., S3 3x).
- Checksums + periodic scrub (hash all blobs).
- Monitoring:
| Metric | Source |
|---|
| Dedup ratio | miss_hits |
| Integrity errors | verify_fails |
| Storage used | sum(sizes) |
| GC reclaimed | deleted_bytes |
- Backups: Snapshot metadata + blobs.
- Impl Stack (suggested):
| Component | Tech |
|---|
| API | Go (iperf-like perf) |
| Metadata | RocksDB |
| Blob | Local FS → S3 |
| CLI | caas put file.tar |
Edge Cases & Security
- Collisions: SHA256 (2^-128 prob); upgrade to BLAKE3 if paranoid.
- Poisoned Blobs: Quarantine on verify fail; alert.
- DoS: Rate-limit PUT by size/IP.
- Encryption: Client-side (encrypt before hash? Use
hash(encrypt(content))).
- Signatures: Optional
manifest.json with sigs, stored as separate artifact.
This design is production-ready (inspired by IPFS/Nix/bazel-cache). Prototype in ~1k LoC Go. Questions?