Storage System for Compiled Build Outputs
System DesignModel answerLast updated
Design a scalable distributed storage service that handles immutable binary files produced by continuous integration pipelines.
You need to design a distributed storage service that handles the binary outputs of compilation and packaging steps in a continuous integration system. These outputs—executables, container images, compressed archives, and similar files—are produced by build machines and later retrieved by testing infrastructure, deployment tools, and release processes.
The service shares characteristics with distributed databases but differs in two key ways: stored items are opaque binary blobs rather than structured records, and you can relax some consistency guarantees that databases maintain.
Your design should address:
- The client-facing API for storing and retrieving items
- How blobs and their associated metadata are organized and located
- Durability mechanisms including replication strategy
- Scaling approaches for both write and read traffic
- Which consistency properties you maintain and which you deliberately weaken, with justification
Consider practical concerns like upload verification, handling popular items that many clients request simultaneously, retention policies, and reclaiming space from obsolete items.
Before diving into the design, clarify assumptions about scale (daily upload volume and file size distribution), access patterns (who reads what, and when), mutability (are stored items permanent or can they be replaced), retention requirements, lookup mechanisms (content-based vs. metadata-based), geographic distribution, and whether you're building the entire storage stack or can use existing infrastructure as a foundation.
Hints
Hint 1
Separate the concerns of storing large immutable blobs from tracking mutable metadata about those blobs
Hint 2
Think about what happens when thousands of test machines all need to download the same newly-built binary at once
Hint 3
Consider how to make an item atomically visible only after all its bytes are safely stored and validated
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
Requirements and Scale Estimation
First, establish the scope through clarifying questions. Assume:
- 100K builds daily producing 500GB total (5MB average, ranging from 100KB configs to 5GB images)
- 50TB stored with 90-day retention
- Read/write ratio of 20:1 (downloads dominate)
- Peak fan-out: 1,000 simultaneous downloads of a fresh artifact
- Multi-region deployment with 99.9% availability and 99.999999% durability targets
- Items are immutable; lookups by build ID or content hash
Traffic estimates:
- Writes: ~12 uploads/sec sustained, ~100/sec peak
- Reads: ~240 downloads/sec sustained, ~2K/sec peak during deployments
- Bandwidth: ~60MB/s write, ~1.2GB/s read during peak
Architecture Overview
Split into three layers:
- Metadata service: Strongly consistent coordination layer tracking which artifacts exist, their properties, and storage locations
- Blob storage: Content-addressed immutable storage holding the actual binary data
- CDN/cache layer: Edge caching for hot items
Blob Storage Layer
Store content using content-addressed storage where each blob's identifier is its SHA-256 hash. This enables:
- Automatic deduplication when different builds produce identical outputs
- Integrity verification on every read
- Immutability guarantees (changing content changes the hash)
Chunking strategy: Split large blobs into 4MB chunks, each with its own hash. This allows:
- Resumable uploads
- Efficient partial replication repair
- Better load distribution across storage nodes
Data placement: Use consistent hashing to map chunk hashes to storage nodes. Each chunk is replicated to R=3 nodes (primary + 2 replicas) in different fault domains (racks/zones).
Alternative: For cost optimization at massive scale, use erasure coding (8+4 Reed-Solomon) instead of 3x replication. This reduces storage overhead from 3x to 1.5x while maintaining durability, at the cost of higher read latency and compute during reconstruction.
Metadata Service
Maintain a strongly consistent database (Raft-based KV store or managed SQL) tracking:
Artifact {
build_id: string (primary key)
content_hash: string
size_bytes: int64
chunk_hashes: []string
created_at: timestamp
metadata: map<string,string>
state: enum(uploading, available, expired)
}
The metadata service is the source of truth for what exists and where. Clients query metadata first, then fetch blobs using returned locations.
Upload Protocol (Atomic Visibility)
Critical requirement: an artifact must appear atomically—either fully available or not present at all. Partial uploads should never be visible.
Two-phase commit approach:
- Prepare phase: Client requests upload, receives upload_token and chunk assignments
- Upload chunks: Client uploads chunks to assigned storage nodes in parallel. Each node validates hash and signals completion
- Commit phase: After all chunks are durable, client calls commit(upload_token). Metadata service atomically transitions artifact from "uploading" to "available"
If commit never arrives (client crash), a background job times out the upload after 1 hour and deletes staged chunks.
Why this is safe to relax: Unlike financial transactions, build artifacts don't require cross-artifact consistency. An artifact is either complete and usable or doesn't exist—partial visibility is never correct, so we maintain this atomicity.
Download Path and Fan-out Handling
Problem: When a fresh build completes, hundreds of test workers immediately download the same artifact, overwhelming storage nodes.
Solution layers:
- Edge cache: Deploy caching proxies in each region. Cache hit rate of 80%+ for popular artifacts
- Chunked downloads: Clients fetch chunks in parallel from different storage nodes, distributing load
- Peer-to-peer assist: For extreme fan-out (>1K concurrent downloads), use BitTorrent protocol where downloaders become seeders
- Backpressure: Metadata service can rate-limit queries when detecting hot spots, forcing clients to retry with jitter
Consistency Guarantees
Strong consistency (maintained):
- Artifact existence: once visible, always visible until explicit deletion
- Content integrity: content hash matches actual bytes
- Upload atomicity: artifacts are atomic units
Relaxed (acceptable for this domain):
- Read-after-write: A client might not see its own upload immediately from a different region (eventual consistency across regions). Acceptable because build systems typically wait for explicit completion signals.
- Deletion propagation: After marking an artifact for deletion, replicas may remain readable for minutes. Acceptable because retention is policy-driven, not security-critical.
- Metadata-blob lag: Metadata might reference chunks not yet replicated to all regions. Mitigated by requiring quorum reads.
Replication and Repair
Async replication: After writing to primary node, asynchronously replicate to secondary nodes. Primary responds immediately to metadata service (low latency), while secondaries catch up within seconds.
Health monitoring: Nodes continuously hash-check stored chunks. Corrupted chunks are flagged and repaired from healthy replicas.
Repair process: When a node fails or a chunk becomes under-replicated, the coordinator identifies affected chunks and triggers re-replication to maintain target replica count.
Retention and Garbage Collection
Retention policy: Keep all artifacts for 90 days, release builds indefinitely. Mark artifacts as expired based on policy, but defer actual deletion.
Safe GC:
- Metadata service marks artifacts as "expired" (soft delete)
- After 7-day grace period, add chunks to GC candidate list
- Reference count chunks (one chunk may belong to multiple artifacts)
- Delete only when ref count reaches zero and grace period passed
- Use two-phase delete: mark deleted in metadata, then asynchronously purge from storage
Common Mistakes
- Uploading to metadata first: If you record an artifact in metadata before chunks are stored, clients will see 404s
- No chunking: Storing 5GB blobs as monolithic units makes replication and repair inefficient
- Synchronous cross-region replication: Waiting for all regions makes uploads slow; async is sufficient
- Missing deduplication: Content addressing is free deduplication and integrity checking
- No cache warming: Proactively pushing fresh artifacts to edge caches prevents thundering herd
Technology Choices
- Metadata: etcd, Consul, or Cloud Spanner
- Blob storage: Custom (like Facebook's Haystack) or S3/GCS with careful key design
- Cache: Nginx/Varnish or CDN (CloudFront, Cloudflare)
- Coordination: Kubernetes for orchestration, Prometheus for monitoring