The user wants a design for a deterministic asset pipeline for game engines, specifically focusing on distributed build workers.
The key components required are:
- Determinism: The same input must produce the exact same output, regardless of where or when it is built.
- Distributed Build Workers: The system needs to scale horizontally.
- Hashing: To identify content and changes.
- Caching: To avoid re-computation.
- Validation: To ensure correctness and integrity.
- Rollback: To handle failures or versioning needs.
1. High-Level Architecture:
- Orchestrator (Coordinator): Manages the dependency graph, schedules tasks, handles the cache.
- Workers: Execute the actual asset processing (compilation, compression, conversion).
- Storage (Source & Artifacts): Networked storage (S3, NAS, etc.) for raw assets and compiled outputs.
- Database (Metadata): Stores the graph, hashes, status.
2. Determinism (The Core Constraint):
- Problem: Floating point math, multi-threading races, timestamps, file system ordering, random numbers, locale settings.
- Solution:
- Inputs must be hashed to define the "Identity" of the work.
- Environment (tool versions, parameters) must be hashed.
- Outputs must be binary identical.
- "Hermetic" builds: Workers shouldn't look at things not declared in the input hash.
3. Hashing Strategy:
- Merkle Trees / Dependency Graphs: We need to hash the asset content and its metadata (import settings).
- Input Hash:
Hash(File Content + Import Settings + Tool Version + Transitive Dependencies).
- Output Hash:
Hash(Generated Artifacts). This is used for caching and validation.
4. Caching Mechanism:
- Remote Cache: A content-addressable storage (CAS). Key = Output Hash. Value = Binary blobs.
- Local Cache: On the worker's SSD for speed.
- Logic:
- Calculate Input Hash.
- Check if Output Hash exists for this Input Hash.
- If yes, download from CAS (or local).
- If no, execute.
5. Distributed Workers:
- Scaling: Stateless workers. They pull jobs.
- Synchronization: Need to ensure dependencies are built before dependents.
- Topology: A DAG (Directed Acyclic Graph) of tasks.
6. Validation:
- Determinism Check: If two workers build the same input and produce different output hashes, that's a non-determinism bug (flaky build).
- Consistency: Does the output match the hash in the database?
- Integrity: Can we load the asset in the engine?
7. Rollback:
- Atomicity: A build step either succeeds or fails completely. No half-baked artifacts in the final build.
- Versioning: Since we use content hashes, "Rollback" essentially means pointing the current "Tip" or "Manifest" to an older hash.
- Atomic Swap: Updating the "Current Build ID" pointer.
Drafting the Design - Section by Section:
- Introduction: Define the goal (speed + correctness).
- Core Concepts:
- Content-Addressable Storage (CAS).
- Directed Acyclic Graph (DAG).
- The Pipeline Workflow:
- Analysis Phase (Scanning -> Hashing).
- Scheduling Phase (Queueing).
- Execution Phase (Worker logic).
- Assembly Phase (Writing the final manifest).
- Deep Dive: Hashing (The Identity):
- Needs to include content, config, tools, and environment.
- Deep Dive: Caching (The Speed):
- Remote vs Local.
- Deduplication.
- Deep Dive: Determinism (The Hard Part):
- Hermeticity.
- Sandbox containers (Docker/Sandboxie).
- Fixed timestamps/random seeds.
- Deep Dive: Validation:
- Consistency checks.
- "Race" validation (build same thing on 2 workers).
- Deep Dive: Rollback:
- Immutable artifacts.
- Manifest versioning.
Refining the "Determinism" aspect:
This is the hardest part in game dev (floating point, texture encoders). I should emphasize "Hermetic Execution" and "Sandboxing". If a worker writes a timestamp to a file header, it breaks determinism. We need to force timestamps to a fixed epoch (e.g., 0 or build start time fixed across workers).
Refining the "Rollback":
Rollback in a build system usually means "I broke the game, give me yesterday's data." With a content-addressable system, we don't overwrite files. We store Asset_v1.dat (hash 123) and Asset_v2.dat (hash 456). The "Rollback" is just changing the pointer in the build_manifest.json.
Structure of the Response:
- High-Level Architecture Diagram (Text description): Orchestrator, Workers, CAS, Database.
- The Determinism Contract: Rules for inputs/outputs.
- Step-by-Step Pipeline Flow: From asset creation to final build.
- Detailed Component Design:
- Hashing (Merkle DAG).
- Distributed Execution (Queue & Dependency Management).
- Caching (CAS).
- Validation (Post-process checks).
- Rollback (Immutable Storage).
- Handling Failure States: What happens when non-determinism is detected?
Self-Correction/Review:
- Initial thought: Just hash the file.
- Correction: No, must hash the file plus the importer version plus the target platform. A PS5 texture is different from a PC texture.
- Initial thought: Workers push to main storage.
- Correction: Workers upload to CAS. The Orchestrator decides if the CAS artifact is "promoted" to the current build manifest.
Let's write out the design.
- Terminology: Use standard terms like "Artifact", "Target", "Node", "Edge".
- Technologies: Mention tools like Bazel or Buck for inspiration, but keep it specific to Game Engines (assets, textures, models).
Specific focus on Game Engine needs:
- Asset dependencies (Material depends on Texture, Model depends on Material).
- Long processing times (e.g., lightmap baking).
- Large binary files.
Rollback specific:
User asked for rollback. In a build pipeline, this is "artifact promotion". We don't delete old builds. We just stop pointing to them.
Validation specific:
Needs to check if the build is "good". Can we calculate the hash of the result before doing the heavy lifting? No. Validation happens after execution.
Plan:
- Architecture Overview: CAS + Orchestrator + Workers.
- Hashing Strategy: The "Weak" and "Strong" hashing.
- Execution Flow: The lifecycle of an asset.
- Determinism Enforcement: Sandboxing.
- Validation & Rollback: The safety net.
Let's assemble.
Designing a distributed asset pipeline requires shifting from a "file-based" mentality to a "content-addressable" mentality. To achieve high performance and reproducibility, we treat the build pipeline as a pure function: Output=f(Input,Environment).
Below is the design for a Deterministic Distributed Asset Pipeline (DDAP).
1. Core Architecture
The system consists of four main components:
- The Orchestrator (Coordinator): Holds the global state of the dependency graph. It does not process assets; it schedules tasks.
- The Workers: Stateless compute nodes (Linux containers) that perform the actual conversion (e.g., PSD -> PNG, FBX -> GameFormat).
- The Content-Addressable Storage (CAS): A distributed storage system (like S3, MinIO, or Artifactory) where assets are stored by their hash, not their filename.
- The Version Database: Stores metadata mapping Human-Readable Paths to Hash IDs.
2. The Hashing Strategy (Identity)
To make the pipeline deterministic, we must define what constitutes a "change." We use a Merkle DAG (Directed Acyclic Graph) similar to Git or IPFS.
The "Strong" Hash
Every artifact is identified by a cryptographic hash (SHA-256 or BLAKE3).
- Input Hash: Calculated from the raw binary content of the source file.
- Configuration Hash: Calculated from the JSON/XML import settings (e.g., texture compression quality).
- Environment Hash: The hash of the tool version used to process the asset (e.g.,
TextureCompiler v2.1.0).
The Composite Key
The identity of an output artifact is defined as:
OutputHash=H(InputHash+ConfigHash+EnvHash)
This key guarantees that if you compile the same texture with the same settings on a worker in the US and a worker in Japan, the resulting binary will be bitwise identical.
3. Pipeline Execution Flow
Phase A: Analysis & Scheduling (The Orchestrator)
- Scan: The Orchestrator detects a change in source control (Perforce/Git).
- Dependency Resolution: It loads the asset dependency graph.
- Example:
Level1.map depends on Tree.model, which depends on Bark.texture.
- Hash Calculation: It calculates the Composite Keys for the modified files.
- Cache Check: It queries the CAS.
- Hit: If
CompositeKey exists in storage, skip execution.
- Miss: If missing, enqueue the task for a Worker.
Phase B: Distributed Execution (The Worker)
- Lease: The Worker pulls a task bundle from the Orchestrator. The bundle includes the Input Hash, Config Hash, and Tool ID.
- Pull: The Worker downloads the source artifact from the CAS into a local RAM disk or SSD.
- Sandboxing (Crucial for Determinism): The Worker runs the compiler inside a restricted environment (e.g., Docker, Bubblewrap).
- No Timestamps: The system overrides filesystem API calls to return a fixed epoch time (e.g., Jan 1, 2000) for file writes.
- No Randomness: PRNGs are seeded with the Input Hash.
- No Network: Workers cannot access the internet; they only talk to the CAS.
- Execution: The tool processes the asset.
- Push: The Worker uploads the resulting binary to the CAS, keyed by its new hash.
4. Caching Mechanism
We utilize a multi-tier caching strategy to minimize network traffic and computation.
- Remote Cache (CAS): The source of truth. Stores compiled artifacts indefinitely or based on retention policies.
- Worker Local Cache: An LRU (Least Recently Used) cache on the Worker's SSD. Before downloading from CAS, the Worker checks its local disk.
- Orchestrator "Asset Manifest": The Orchestrator keeps a lightweight database mapping logical asset paths to current CAS IDs.
Handling "False Positives":
Sometimes a file touch changes the timestamp but not the content.
- Optimization: Before queuing a compile, the Orchestrator reads the file header to calculate the strong hash. If the strong hash matches the database, the timestamp update is ignored.
5. Validation & Integrity
Since the pipeline is distributed, we need strict validation to prevent "flaky builds" (where a build fails on one worker but passes on another).
Consensus Verification (The "Golden Image")
For critical assets (or randomly sampled assets), the Orchestrator can trigger a Redundant Build:
- Send the same task to 2 different Workers.
- Compare the Output Hashes of the results.
- If
WorkerA_Output != WorkerB_Output, the pipeline flags the tool as Non-Deterministic.
- Quarantine: The system rejects the output and alerts the Tools team. This prevents "it works on my machine" bugs from reaching the game.
Post-Process Validation
- Schema Checks: A lightweight parser verifies the header of the compiled binary before accepting it into the CAS.
- Dependency Validation: Ensure the output correctly lists its dependencies (no runtime file lookups allowed).
6. Rollback Strategy
Because the system is content-addressable, rollback is instantaneous and atomic.
The "Pointer" Model
We do not overwrite files. We maintain a pointer file (The Manifest).
- Current State:
Character.model -> Hash_ABC (Size: 5MB)
- New Commit: Artist updates texture.
- New Build:
Character.model -> Hash_XYZ (Size: 5.2MB)
Rollback Execution
- Identify: The user identifies a "Bad Build" (e.g., Build #1042).
- Revert: The user requests a rollback to Build #1041.
- Re-point: The Orchestrator checks the Version Database for the Manifest associated with Build #1041.
- Deploy: It updates the "Live" pointer to reference the old hashes. No files are deleted or moved; the game client simply requests the old hash IDs from the CDN/Storage.
Benefits
- Zero Downtime: No need to copy terabytes of data back and forth.
- Binary Diffing: Since both versions exist in the CAS, patch generation is just comparing the list of hashes between two manifests.
7. Summary of Technologies
To implement this today, you would likely use:
- Orchestrator: Redis (for queue) + PostgreSQL (for metadata) or a dedicated scheduler like BuildGrid.
- Protocol: gRPC / REAPI (Remote Execution API) - standard used by Bazel and Buck.
- Storage: MinIO or S3.
- Execution: Docker containers with mounted volumes.
Diagrammatic Representation
[Artist Commits]
|
V
[Orchestrator] <--- (1. Calculate Hash & Check Graph)
|
+---> [CAS Hit?] --(Yes)--> [Update Manifest] --> [Done]
|
+---> [CAS Miss?] --(No)
|
V
(2. Dispatch Task to Worker Pool)
|
+-------+-------+
| |
[Worker A] [Worker B] (Stateless)
| |
(Sandboxed) (Sandboxed)
| |
[Output Hash] [Output Hash]
| |
+-------+-------+
|
V
(3. Upload to CAS)
|
V
(4. Update Orchestrator Manifest)