We are designing a deterministic asset pipeline for game engines with distributed build workers.
Key requirements: deterministic (same input -> same output), hashing (for content-addressable storage), caching (to avoid rebuilds), validation (ensure integrity), and rollback (ability to revert to previous versions).
Steps:
-
Asset Ingestion:
- Assets are provided by artists/designers in various formats (e.g., .psd, .fbx, .wav).
- Each asset is assigned a unique identifier (maybe based on its source path and version) and a hash of its source content.
-
Hashing:
- For each source asset, compute a cryptographic hash (e.g., SHA256) of the file content.
- This hash will be used as the key for caching and for tracking versions.
-
Build Process:
- The build process transforms source assets into engine-ready formats (e.g., textures to DDS, models to mesh, audio to OGG).
- The build process must be deterministic: given the same input (source asset and build parameters) and the same environment, the output must be byte-for-byte identical.
- To achieve determinism, we must control:
- Tool versions (e.g., specific version of texture compressor, FBX converter).
- Build parameters (e.g., compression quality, mipmap generation settings).
- Environment (e.g., locale, system time, random seeds). Use fixed seeds for any random operations.
- Avoid non-deterministic operations (like using current timestamps in output, or unordered dictionary traversal).
-
Caching:
- The output of the build process (the built asset) is stored in a content-addressable cache, keyed by:
- Hash of the source asset.
- Hash of the build parameters (and tool versions).
- Before building an asset, check the cache. If the output for the given source hash and build parameter hash exists, use it.
-
Distributed Build Workers:
- Build tasks can be distributed to multiple workers (machines).
- Workers must have the same toolchain and configuration.
- The cache must be shared (e.g., a distributed cache like a shared file system or a dedicated cache server) so that any worker can reuse results from any other.
-
Validation:
- After building, we can validate the output by:
- Checking that the output file is non-empty and matches expected format (magic bytes).
- Optionally, we can compute a hash of the output and store it in a manifest for further integrity checks.
- Also, we can validate the entire pipeline by comparing the hash of the built asset with a previously recorded hash (if we are rebuilding for validation).
-
Rollback:
- Since we have content-addressable storage (by source hash and build parameters), we can keep multiple versions of built assets.
- The build system should maintain a manifest (or a database) that maps from a logical asset version (e.g., a commit in version control) to the hashes of the built assets.
- If a new build fails or produces bad assets, we can revert to the previous manifest and use the previously built assets (which are still in the cache).
-
Manifest and Dependency Tracking:
- We need a manifest file (or set of files) that records:
- For each logical asset (with its source path and version in VCS), the hash of the source asset and the hash of the built asset.
- The build parameters used (and their hashes).
- The manifest itself should be versioned (e.g., in git) so we can rollback to a previous manifest.
-
Build Process Flow:
a. Update: Get the latest source assets from version control (or a source depot). For each asset, compute the source hash.
b. Load Manifest: Read the current manifest (which might be from a previous build or from version control). The manifest records the built asset hash for each source asset (for a given set of build parameters).
c. For each asset:
- If the source hash matches the one in the manifest and the build parameters haven't changed, then the built asset hash in the manifest is valid and we can skip building (if the built asset is in the cache).
- If the source hash is new (or changed) or the build parameters changed, then we need to build.
d. Build:
- Assign the build task to a worker (could be local or distributed). The worker must have the required tools.
- The worker runs the build tool with the given parameters, reading the source asset and writing the built asset to a temporary location.
- After building, the worker computes the hash of the built asset and checks if it matches the expected hash (if we are rebuilding for validation) or just stores it.
e. Cache:
- The built asset is stored in the distributed cache with a key that is a combination of the source hash and the build parameters hash.
- Also, update the manifest to record the built asset hash for that source asset.
f. Validation:
- We can have a separate validation step that, for each built asset, verifies:
- The file exists and is non-zero.
- The format is correct (e.g., for a texture, check the header).
- Optionally, run a tool that can validate the asset (e.g., check for corrupted meshes).
g. Rollback:
- If the build fails or validation fails, we can revert the manifest to the previous version (from version control) and then use the built assets from the previous build (which are still in the cache, because we never delete old cache entries until we decide to clean up).
-
Cache Invalidation and Cleanup:
- We must have a policy for cleaning the cache (e.g., keep the last N builds, or use a least-recently-used policy).
- But note: we want to keep old built assets for rollback, so we might want to keep at least the last successful build's assets.
-
Distributed Cache Design:
- We can use a shared file system (like NFS) with a directory structure based on the hash (e.g., first two characters of hash as directory, then next two, then the rest).
- Or use a dedicated cache server (like an HTTP server or a custom service) that stores blobs by hash.
-
Build Parameters:
- The build parameters must be versioned and hashed. For example, if we change the texture compression quality, we must change the build parameters hash.
- We can have a configuration file (e.g., JSON) that lists all the parameters. Hash the entire configuration file (or a canonical representation) to get the parameters hash.
-
Toolchain Versioning:
- The build parameters should also include the version of the build tools (e.g., the version of the texture compressor). This can be part of the configuration or we can have a separate file that records the tool versions.
-
Example:
Let's say we have a texture asset: assets/textures/hero.png.
Step 1: Compute source hash of hero.png -> abc123...
Step 2: Check the current manifest (for the current build parameters) to see if we have a built asset for source hash abc123... and build parameters hash def456....
Step 3: If not, build:
- Run the texture tool with parameters from the configuration (which we hash to
def456...).
- The tool reads
hero.png and writes hero.dds.
- Compute hash of
hero.dds -> xyz789...
Step 4: Store hero.dds in cache with key abc123..._def456... (or a combination of the two hashes).
Step 5: Update manifest: for asset assets/textures/hero.png record:
- source_hash:
abc123...
- built_hash:
xyz789...
- build_params_hash:
def456...
Step 6: Validation: run a DDS validator on hero.dds. If it fails, we can mark the build as failed and rollback.
-
Rollback Procedure:
- If the build fails, we revert the manifest file to the previous version (from version control). Then, for the next build, we will use the old manifest and thus use the old built assets (which are still in the cache) for all assets that haven't changed source.
-
Distributed Workers:
- We need a task distribution system (like a queue) that assigns build tasks to workers.
- Each worker, when assigned a task, checks the cache for the built asset (using the source hash and build parameters hash). If found, it doesn't build but just copies from the cache to the output directory (or notifies the master). If not found, it builds and then stores the built asset in the cache.
-
Atomic Updates:
- The manifest should be updated atomically (or in a way that we can recover from partial updates). We can write to a temporary file and then rename.
-
Monitoring and Logging:
- We must log every build step, cache hit/miss, and validation result.
-
Security:
- The cache should be protected from unauthorized modifications (since we rely on hashes for integrity). Use secure storage and access controls.
-
Implementation Considerations:
- The system must be able to handle very large files (assets can be GBs). The cache storage must be scalable.
- The hash computation for large files must be efficient (streaming hash).
-
Example Tools:
- For hashing: use SHA256 (or BLAKE3 for speed).
- For cache: use a simple file system with hash-based directories, or a blob store like Amazon S3 (with a local cache for workers).
- For task distribution: use a message queue (e.g., RabbitMQ, AWS SQS) or a build system like Bazel's remote execution.
-
Determinism Enforcement:
- We can run the build in a container (Docker) with a fixed environment to ensure determinism across workers.
-
Example Build Configuration:
Let's say we have a build_config.json:
{
"texture_compressor": "crunch_v1.2.3",
"texture_compression_quality": 50,
"model_converter": "fbx_converter_v2.1",
"audio_compressor": "vorbis_v1.3.7",
...
}
Then, we compute the hash of this JSON (with sorted keys) to get the build parameters hash.
-
Manifest Format:
We can have a manifest per build (or a single manifest that we update). For example, a JSON file:
{
"build_params_hash": "def456...",
"assets": {
"assets/textures/hero.png": {
"source_hash": "abc123...",
"built_hash": "xyz789...",
"built_path": "textures/hero.dds" // relative to the output directory
},
...
}
}
-
Rollback:
- We keep the manifest in version control (e.g., in the
build/ directory). When we rollback, we checkout the previous manifest and then the build system will use that manifest to decide which assets to build (only those that changed) and which to reuse from cache.
-
Challenges:
- If a build tool is not deterministic, we might get different outputs. We must either fix the tool or use a deterministic alternative.
- If the build parameters change (e.g., we upgrade the texture compressor), then all assets will be rebuilt. But that's expected.
-
Summary:
The pipeline:
source asset -> hash (source_hash) -> build (with build_params) -> built asset -> hash (built_hash) -> cache (key: source_hash + build_params_hash)
manifest: maps source asset path to {source_hash, built_hash, build_params_hash}
Steps:
1. Compute source_hash for each source asset.
2. Check manifest for the current build_params_hash.
3. If source_hash matches and build_params_hash matches, then use the built_hash from manifest and check cache.
4. If cache hit, use cached built asset.
5. If cache miss, build and then cache by (source_hash, build_params_hash) -> built asset.
6. Update manifest with new built_hash.
7. Validate built asset (optional but recommended).
8. If validation fails, rollback manifest and stop.
Distributed:
- The cache is shared (network accessible).
- The manifest is stored in version control (or a database) and is updated at the end of a successful build.
-
Incremental Builds:
- The system naturally supports incremental builds because we only rebuild when the source hash or build parameters change.
-
Clean Builds:
- If we want a clean build (ignore cache), we can delete the cache or use a new build parameters hash (by changing the build configuration) and then rebuild everything.
-
Rollback to a specific previous build:
- We can check out the manifest from a previous commit and then run the build. The build system will see that the source hashes and build parameters hash match the manifest, and then it will use the cache (if available) to populate the output.
-
Cache Sharing between Builds:
- The cache key is (source_hash, build_params_hash). So if we change the build parameters, we will have a separate cache entry. Old cache entries remain until cleaned.
-
Example Rollback:
Suppose we have build A (with manifest A) and then build B (with manifest B). Build B fails validation.
We rollback to manifest A. Then we run the build again (with build parameters that correspond to manifest A). The build system will:
- For each asset in manifest A, check if we have the built asset in the cache (key: source_hash from manifest A and build_params_hash from manifest A). Since we built these in build A, they should be in the cache (unless we cleaned the cache). Then we can copy them to the output directory.
If we cleaned the cache, then we would have to rebuild, but that's acceptable because we are rolling back to a known good state and we might have to rebuild.
-
Conclusion:
This design provides determinism, caching, distributed builds, validation, and rollback.
We must be cautious about:
- Ensuring build tools are deterministic.
- Managing the cache size (with a cleanup policy that respects rollback needs).
- Keeping the manifest in version control (so we can rollback) and updating it only after successful validation.
This is a high-level design. Implementation details will depend on the specific game engine and tools.
I'll design a deterministic, distributed asset pipeline with strong guarantees for game development. This is a complex system that requires careful architectural decisions.
System Architecture Overview
[Source Control] → [Content Tracker] → [Distributed Scheduler] → [Build Workers]
↓ ↓ ↓ ↓
[Hash Database] ← [Manifest Store] ← [Cache Cluster] ← [Validation Ring]
↓ ↓ ↓ ↓
[Rollback Store] ← [Dependency Graph] ← [Atomic Swaps] ← [Artifact Registry]
1. Core Components
1.1 Deterministic Asset Processor
class DeterministicProcessor:
def process(source_path: Path, parameters: FrozenDict) -> BuiltAsset:
# 1. Load source with fixed locale/encoding
# 2. Apply transformations with seeded RNG
# 3. Normalize all metadata (timestamps → 0, sort entries)
# 4. Write to temp with fixed permissions
# 5. Compute SHA3-256 of output
return BuiltAsset(hash=final_hash, path=temp_path)
Determinism Enforcement:
- Containerized Build: All workers run identical Docker containers with pinned tool versions
- Environment Sanitization:
TZ=UTC, LC_ALL=C, SOURCE_DATE_EPOCH=0
- Tool Configuration: All conversion tools in "deterministic mode" (e.g.,
crunch --deterministic)
- File System: Use
tmpfs or overlayfs with consistent inode ordering
2. Content-Addressable Storage (CAS)
2.1 Hash Computation Pipeline
Source File → Normalize → Chunk (16MB) → Parallel SHA3-256 → Merkle Root
- Chunking: Content-defined chunking (Fixed 16MB chunks)
- Merkle Tree: Enables partial rebuilds and delta verification
- Hash Format:
sha3:256:base64(merkle_root)
- Metadata Store: Redis/ScyllaDB mapping
{asset_path} → {source_hash, build_hash}
2.2 Cache Hierarchy
L1: Worker Local (NVMe) - LRU, 100GB
L2: Regional Cache (Redis Cluster) - Sharded by hash prefix
L3: Global CAS (S3/MinIO with erasure coding) - Immutable blobs
Cache Key Structure:
{toolchain_version}:{parameter_hash}:{source_hash}
3. Distributed Build System
3.1 Task Queue with Priority
class BuildTask:
asset_path: str
source_hash: str
parameter_hash: str # Hash of build configuration
priority: int # 0=critical, 1=normal, 2=background
dependencies: List[str] # Other asset hashes
Queue Features:
- Work Stealing: Workers pull from multiple queues
- Backpressure: Queue depth monitoring → auto-scale workers
- Priority Inversion Prevention: Critical path assets (shaders) jump queue
3.2 Worker Implementation
type BuildWorker struct {
cache ContentAddressableCache
toolchain PinnedToolchain
validator AssetValidator
metrics PrometheusCollector
}
func (w *BuildWorker) Process(task BuildTask) (Result, error) {
// 1. Check L1/L2/L3 cache for (param_hash, source_hash)
// 2. If miss: deterministic build in isolated container
// 3. Validate output
// 4. Store to cache (write-through to L3)
// 5. Update manifest atomically
}
Worker Guarantees:
- Idempotent: Same task → same result forever
- Stateless: Can be killed/replaced at any time
- Resource Isolation: CPU/memory limits per asset type
4. Validation Layers
4.1 Validation Types
Level 1: Syntax (file format magic bytes, schema validation)
Level 2: Determinism (re-hash output, compare to expected)
Level 3: Functional (run in engine sandbox, capture warnings)
Level 4: Performance (measure frame time impact)
4.2 Validation Ring
Asset → Worker → Primary Validator → Quorum Validators → Consensus
- Quorum Validation: 3/5 validators must approve
- Canary Deployment: New assets tested in isolated world
- Regression Detection: Compare metrics against baseline
5. Manifest & Dependency Tracking
5.1 Manifest Structure (Protocol Buffers)
message BuildManifest {
string version = 1; // Semantic version
string build_id = 2; // UUID for this build
map<string, AssetEntry> assets = 3;
repeated string dependencies = 4; // Other manifests
uint64 timestamp = 5; // SOURCE_DATE_EPOCH
}
message AssetEntry {
string source_hash = 1; // SHA3 of source
string built_hash = 2; // SHA3 of output
string parameter_hash = 3;
repeated string dependents = 4; // Assets that use this
ValidationResult validation = 5;
}
5.2 Dependency Resolution
Directed Acyclic Graph (DAG) of assets:
- Textures → Materials → Meshes → Prefabs → Scenes
- Topological sort ensures correct build order
- Change detection: only rebuild affected downstream assets
6. Rollback Mechanism
6.1 Multi-Level Rollback
1. Hot Rollback (seconds): Switch manifest pointer (atomic symlink swap)
2. Warm Rollback (minutes): Rebuild from previous manifest (cache hits)
3. Cold Rollback (hours): Restore from backup + rebuild delta
6.2 Rollback Procedure
# 1. Identify bad build
bad_build_id=$(cat current_build_id)
# 2. Find last good manifest
good_manifest=$(git log --oneline --grep="BUILD:success" | head -1)
# 3. Atomic switch
ln -sfn /manifests/$good_manifest /current_manifest
# 4. Workers automatically pick up new manifest
# 5. Optionally: trigger rebuild of changed assets from cache
Rollback Guarantees:
- Consistent State: All assets from same manifest version
- Zero-Downtime: Clients can keep using old assets while switching
- Audit Trail: Every build/rollback logged with
who/when/why
7. Distributed Consistency
7.1 Consensus Protocol
- Manifest Updates: Raft consensus among 3 master nodes
- Cache Eviction: Conflict-free replicated data types (CRDTs)
- Worker Registration: Etcd/Consul service discovery
7.2 Transactional Updates
BEGIN;
UPDATE current_manifest SET id = :new_id
WHERE id = :expected_old_id; -- Optimistic locking
INSERT INTO build_history (manifest_id, status, timestamp)
VALUES (:new_id, 'active', NOW());
COMMIT;
8. Monitoring & Audit
8.1 Metrics to Track
- Cache hit rate per asset type
- Worker utilization & queue depth
- Determinism failures (hash mismatch)
- Validation quorum timeouts
- Rollback frequency & causes
8.2 Audit Logging
Every operation signed with HMAC:
[timestamp] [worker_id] [action] [asset] [source_hash] [built_hash] [sig]
9. Failure Modes & Recovery
| Failure Mode | Detection | Recovery |
|---|
| Worker crash | Heartbeat timeout | Task re-queued, cache intact |
| Cache corruption | Periodic re-hash audit | Rebuild from source |
| Bad tool upgrade | Validation quorum fail | Rollback manifest, pin toolchain |
| Network partition | Consensus timeout | Pause new builds, serve cached |
| Disk full | Write error | Alert, pause non-critical |
10. Implementation Roadmap
Phase 1 (Foundation):
- Implement deterministic processing containers
- Build basic CAS with S3 backend
- Single-worker pipeline with validation
Phase 2 (Distribution):
- Add work queue + worker pool
- Implement manifest store with Raft
- Cache hierarchy (L1→L2→L3)
Phase 3 (Resilience):
- Validation ring & quorum
- Rollback automation
- Monitoring/alerting
Phase 4 (Optimization):
- Predictive caching (build common assets ahead)
- Delta builds (only rebuild changed chunks)
- GPU-accelerated validation
11. Key Design Decisions
- Why SHA3-256? Collision resistance + performance vs SHA2
- Why Merkle Trees? Enables sub-asset caching, partial verification
- Why Quorum Validation? Prevents single-point bad builds
- Why Immutable Blobs? Simplifies cache coherency
- Why Manifest in Git? Human-auditable, natural rollback via VCS
12. Example Workflow
# Artist edits: assets/textures/character.dds
$ git commit -m "Update character texture"
# CI detects change
$ hash=$(sha3sum assets/textures/character.png)
$ if ! manifest.has(hash); then
queue.add(asset="character.png", source_hash=$hash)
fi
# Worker picks up task
$ worker pulls task → checks cache (miss) → builds → validates
$ worker stores: s3://cas/ab/cd.../ef... (key: param_hash:source_hash)
$ worker updates manifest (Raft commit)
# If validation fails:
$ system auto-rollbacks to previous manifest
$ alerts sent: "Build failed for character.png - rolled back"
13. Guarantees Provided
✅ Determinism: Same source + params = identical output forever
✅ Reproducibility: Anyone can reproduce any build from manifest
✅ Cache Efficiency: 95%+ hit rate after warm-up
✅ Safe Rollback: <30s to revert to any previous build
✅ Fault Tolerance: Worker/cache failures don't corrupt state
✅ Auditability: Complete chain of custody for every asset
This design balances strong consistency for correctness with eventual consistency for performance. The system treats build artifacts as immutable values in a content-addressable store, making rollbacks trivial and caching maximally effective. The validation ring prevents "bad" builds from propagating, while the manifest-based approach ensures entire game states can be reproduced exactly.