Render-farm processing
Render-farm processing turns a Studio recording into a final MP4 and a progressive HLS stream by splitting one export across a coordinator and a fleet of render workers. The coordinator owns the plan, work state, output assembly, and recovery rules while the Rust runtime performs the media work needed for each video or audio range. The coordinator also joins worker-uploaded chunk data without moving the full media payload through memory. For the product view of this flow, see Export and editor rendering; for service and worker details, see Render-farm service and workers.
Processing model
The render farm separates control work from media work. This keeps scheduling and durable job state in the service layer while workers can focus on GPU rendering, audio processing, and media transfer.
Coordinator and worker roles
The coordinator is the control plane for an export. It accepts a request, checks its source and output scope, builds a plan, assigns work, accepts one result for each planned range, and reports the final state. Workers are execution nodes that ask for work, run it in local slots, and return progress and results.
The service supports three kinds of work:
- Video chunks that cover ordered output frame ranges.
- Audio sections that cover ordered sample ranges.
- Source transcodes that create an indexable MP4 before planning can finish. One output key represents one shared transcode for all jobs that need it.
The worker fleet can render video on GPU slots and audio on separate CPU lanes. A worker can also prepare the next task while its current task finishes, which reduces idle time without changing the job plan.
References: apps/…/coordinator.ts• L347-382 apps/…/coordinator.ts• L1581-1641 apps/…/worker.ts• L761-932 apps/…/protocol.ts• L15-83
Service and Rust runtime boundary
The TypeScript service owns orchestration and storage-facing work. The Rust binary is a long-lived chunk engine that runs one process per render slot and receives line-delimited requests for probing, video rendering, audio rendering, warm-up, or health checks. It returns a result for each request and can stream progress or completed GOP events while the request runs.
This boundary gives the service enough information to plan and monitor work without moving the full rendering system into the coordinator. It also lets each worker reuse a warmed rendering process and its GPU state across several tasks. See the child page for the service and worker implementation: Render-farm service and workers.
References: crates/…/main.rs• L1-12 crates/…/main.rs• L31-56 crates/…/main.rs• L59-123 crates/…/main.rs• L126-178 apps/…/engine.ts• L1-5 apps/…/engine.ts• L60-129 crates/…/video.rs• L24-39
Object storage roles
The render farm uses object storage for media, temporary chunk data, and durable control state. A media bucket holds recordings, the final MP4, and HLS objects, while the farm bucket holds job journals and chunk opening data. This keeps product media storage and coordinator recovery data separate. The media bucket may belong to another account, so writes preserve the bucket owner's access when that integration requires it.
Workers upload the main body of each video chunk directly into reserved parts of the final multipart upload. They place the chunk's opening bytes in a temporary stash object because a short opening cannot always form a valid multipart part. The coordinator later joins the MP4 header with small stashes and can copy a stand-alone stash server-side when both buckets share a store. This avoids padding and keeps the full media payload out of coordinator memory.
The storage client can use static credentials or temporary instance-role credentials. When it uses an instance role, it refreshes the credentials before they are needed and limits presigned URLs to the remaining credential lifetime. This keeps worker reads, uploads, and playback links tied to valid storage access.
References: apps/…/coordinator.ts• L58-61 apps/…/coordinator.ts• L1110-1114 apps/…/s3.ts• L26-59 apps/…/s3.ts• L85-174 apps/…/s3.ts• L393-451 apps/…/stitch.ts• L4-13 apps/…/README.md• L61-72 apps/…/s3.test.ts• L107-172 apps/…/s3-imds.test.ts• L42-209
Export lifecycle
An export moves from a checked request to a durable plan, then through parallel media work, assembly, and output checks. The coordinator exposes the job while this flow runs so clients can watch progress or wait for a terminal result.
The main flow is:
flowchart LR
A[Job request] --> B[Validate request and source manifest]
B --> C[Index sources and prepare transcodes]
C --> D[Probe project and source ranges]
D --> E[Plan video chunks and audio sections]
E --> F[Schedule work to workers]
F --> G[Render and upload chunk results]
G --> H[Publish HLS segments]
G --> I[Stitch and assemble MP4]
I --> J[Verify output]
J --> K[Ready or failed]
Request validation and planning
The coordinator first checks that the request has safe recording, source, output, and callback scopes. It also bounds the source manifest so a user-controlled recording cannot cause unbounded file reads, source downloads, or export duration.
The planner then reads the project metadata and probes the prepared project through the Rust engine. The probe supplies the output size, frame and sample counts, source-time spans, and audio cut points. The coordinator uses this information to make chunks based on expected render work rather than only on timeline duration. A short lead-in chunk can be added so the first HLS segment does not wait for a large first download.
Before source preparation, the worker probes the recording under the farm's pixel limits. It can copy a source without re-encoding only when its H.264 format, frame order, and keyframe spacing support random access. Other supported sources become an H.264 MP4 with regular keyframes. The coordinator shares one in-flight conversion per output key and reuses a stored output for later exports. It accepts a completed transcode only when the active worker attempt matches and the stored object has the reported size.
The coordinator also reuses source indexes and unchanged MP4 metadata across project folders. Each job still checks the cached manifest against its own source scope before it can use that data.
References: apps/…/validate.ts• L3-115 apps/…/validate.ts• L147-203 apps/…/coordinator.ts• L532-602 apps/…/coordinator.ts• L604-765 apps/…/coordinator.ts• L1505-1642 apps/…/coordinator.ts• L2694-2766 apps/…/planning.ts• L19-99 apps/…/transcode.ts• L1-158 apps/…/transcode.test.ts• L12-129 apps/…/worker.ts• L712-799 apps/…/coordinator.test.ts• L586-821
Source materialization and media work
Each worker recreates the project view that its task needs on local storage. It creates sparse files with the expected full sizes, then fetches only the source byte pieces needed for that time span. Overlapping requests reuse pieces already held by the local project cache, while a concurrency limit prevents one task from flooding object storage.
The cache keeps the renderer's file paths and timestamps unchanged, so the Rust engine can seek into the local view as if it were the full recording. It rejects short reads and can retry a failed piece while the cache remains open. When a task or worker closes the cache, pending and queued fetches stop before they write to closed files.
The Rust engine renders video frames or audio packets for its assigned range. Video results are placed into the shared MP4 upload as ordered parts, with each chunk's opening bytes held in a temporary stash until assembly. Audio sections use a fixed sample grid and pre-roll so processing state can settle before the section's owned samples begin. The audio runtime accounts for encoder priming and checks that its packet range starts and ends at the planned global boundaries. This allows the coordinator to combine independent sections without gaps or overlaps.
References: apps/…/materialize.ts• L13-17 apps/…/materialize.ts• L55-183 apps/…/materialize.test.ts• L58-170 apps/…/worker.ts• L460-580 apps/…/worker.ts• L583-672 apps/…/stitch.ts• L33-39 crates/…/audio.rs• L14-44 crates/…/audio.rs• L55-87 crates/…/audio.rs• L109-137 crates/…/audio.rs• L197-225 crates/…/project.rs• L92-98 crates/…/project.rs• L147-177
Fair scheduling and progressive delivery
The scheduler prevents one long export from holding every slot while a shorter export waits. It first favors work that unlocks the front of a job's playback timeline, then favors jobs with fewer active tasks, older jobs, and earlier timeline positions.
Workers report completed GOPs while video is still rendering. The worker wraps enough video and audio data into HLS segments and uploads them as separate objects. The coordinator grows the playlist only across the contiguous segment range that is known to be ready. As a result, HLS can become playable before the final MP4 is assembled.
When a task is close to completion, the worker can reserve and prefetch the next queued task. If a task is much slower than the normal rate or stops advancing, the coordinator can create a hedge copy on another slot. The first accepted result wins and later copies are cancelled or ignored.
References: apps/…/scheduler.ts• L28-85 apps/…/worker.ts• L191-237 apps/…/worker.ts• L489-542 apps/…/coordinator.ts• L1643-1723 apps/…/coordinator.ts• L1740-1820 apps/…/coordinator.ts• L1856-1914 apps/…/coordinator.test.ts• L471-490
MP4 assembly and output validation
The coordinator waits until every video chunk and required audio section has an accepted result. It orders the chunk metadata, checks that the chunks agree on codec headers, and builds the MP4 header from the collected sample layout. It then plans valid multipart parts from the header, worker stashes, and worker-uploaded parts before completing the final upload.
The stitch plan keeps the file in timeline order without adding padding. Large stashes can become their own parts, while small stashes join the header or a neighboring opening until the storage part-size rule is met. The coordinator can perform this work ahead of final assembly for accepted contiguous chunks, but final assembly remains the authority for the complete part list.
The output is checked after upload with a media probe. The check compares the output duration and H.264 frame count with the planned values. Clients can receive the output as soon as the object exists when asynchronous verification is enabled, while the job still exposes whether the later check passed.
References: apps/…/coordinator.ts• L2172-2434 apps/…/coordinator.ts• L2441-2567 apps/…/mp4.ts• L636-799 apps/…/stitch.ts• L33-127 apps/…/recovery.ts• L32-79
Reliability model
The render farm treats task dispatch, result acceptance, output completion, and worker presence as separate reliability concerns. Durable records and identity checks keep a restart or duplicate result from silently changing the export.
Durable job progress
The coordinator writes an acceptance receipt before it starts planning. It journals the plan before dispatch and records dispatch reservations plus accepted video and audio results as they arrive. A restart reads this journal, restores the multipart upload and task reservations, rebuilds the HLS view, and queues only work that has no accepted result.
The journal has a version boundary because old records did not reserve upload ranges safely. The current format also records the stash-based upload layout. Unfinished jobs from an incompatible format are not resumed. Current records preserve dispatch attempts and their reserved ranges so a retry cannot overwrite parts from an earlier attempt.
References: apps/…/coordinator.ts• L1098-1166 apps/…/coordinator.ts• L1217-1449 apps/…/coordinator.ts• L1485-1519 apps/…/recovery.ts• L4-18 apps/…/README.md• L36-65
Worker failure and task recovery
Workers send heartbeats that list both running and reserved tasks. The coordinator uses these reports to reattach work that survived a coordinator restart and to requeue work whose worker disappears or stops listing it. A worker can drain on shutdown: it stops accepting new work, finishes active tasks, and exits when its slots are idle.
The worker also watches the render engine for a stalled video task, a timed-out audio task, or a failed GPU path. It kills or replaces the affected process so the coordinator can retry the task. Source preparation has its own no-progress watch so a stuck probe or conversion does not hold a worker slot forever. The coordinator applies backoff, limits ordinary attempts, and fails the job when the retry budget is exhausted. A job with no progress beyond its stall limit fails and releases its upload.
References: apps/…/worker.ts• L49-56 apps/…/worker.ts• L712-799 apps/…/worker.ts• L792-813 apps/…/worker.ts• L1040-1096 apps/…/coordinator.ts• L1745-1815 apps/…/coordinator.ts• L1919-1956 apps/…/coordinator.ts• L2672-2720
Duplicate result protection
Several copies of a task may run during recovery or hedging. The coordinator accepts one result per video chunk or audio section and persists that result before it makes the result available to later steps. It ignores stale failure reports and does not allow a losing copy to replace an accepted result.
Each video attempt receives a separate reserved part range and stash key. This prevents a retry or hedge from writing over live multipart data. The coordinator also checks that the reported stash and parts belong to that dispatch and cover exactly the rendered bytes. Segment reports must name an object from the reporting attempt's reserved range. Completion checks the final object's size and header before treating an uncertain storage response as success.
References: apps/…/coordinator.ts• L2172-2233 apps/…/coordinator.ts• L2664-2691 apps/…/coordinator.ts• L2785-2817 apps/…/recovery.ts• L4-29 apps/…/recovery.ts• L32-79 apps/…/stitch.ts• L93-127 apps/…/coordinator.test.ts• L363-388 apps/…/coordinator.test.ts• L492-529
External interfaces
The render farm has a small service interface for product clients and a worker interface for internal execution nodes. Both interfaces carry job identity and progress state so the system can distinguish current work from stale work.
Client job interface
Clients submit a recording and export settings through POST /jobs. The response gives a job identifier and, when enabled, an HLS URL. GET /jobs/:id returns the current summary, progress, output details, HLS segment count, and final verification state. A wait form of the request holds the connection until the job reaches a terminal state or the wait period ends.
The service can send a signed callback for a ready or failed job. It also exposes an indexing hook and transcode status endpoints so product workflows can prepare source media before an export starts.
The indexing hook warms source metadata before an export. The transcode endpoints let a product workflow start or observe a shared source conversion, which is useful when the editor can prepare media before the user requests a final export. A transcode status is not enough to make a source usable: the coordinator also verifies the stored output when the worker reports completion.
References: apps/…/coordinator.ts• L2596-2669 apps/…/coordinator.ts• L2694-2766 apps/…/coordinator.ts• L2799-2876 apps/…/coordinator.ts• L2896-3015 apps/…/protocol.ts• L124-152
Worker work interface
Workers use long-polling to request work from POST /work. They report task progress and liveness through /heartbeat, then post success or failure to task-specific endpoints. Video results include the worker's reserved multipart data and temporary stash reference. The coordinator returns cancellation instructions when a job ends or a duplicate result makes a running copy unnecessary.
The work protocol is intentionally result-oriented. A worker does not decide whether a result is final; it reports the task identity, attempt, media metadata, and uploaded data references. The coordinator remains the authority for acceptance, stitching, assembly, and job state.
References: apps/…/coordinator.ts• L2403-2565 apps/…/coordinator.ts• L2567-2797 apps/…/worker.ts• L792-925 apps/…/protocol.ts• L15-120 apps/…/stitch.ts• L93-127
Change checklist
When these files or sections are changed, remember to consider these:
- Update the task protocol and both the TypeScript worker client and Rust engine boundary together when task fields or result metadata change.
- Preserve the relationship between chunk order, multipart part ranges, stash keys, HLS segment keys, and playlist cursor state when changing chunk planning or output layout.
- Keep journal version rules aligned with dispatch reservations, stash cleanup, and resume logic. A plan that can resume without its upload reservations can corrupt an in-flight export.
- Keep the worker's stash and part byte accounting aligned with
planStitch. A change to one side can create invalid multipart parts or omit media bytes. - Keep audio section cuts aligned with the Rust audio renderer's sample grid, pre-roll, priming, and packet-coverage rules. A change to one side can create audible seams or uncovered packets.
- Keep callback payload signing and callback host checks aligned with the product endpoint that consumes job completion events.
- Keep source manifest scope checks aligned with local project paths and object-store key scope. A valid remote key must still map to a safe local project path.
- Keep source probe limits and random-access checks aligned with the transcode and remux paths. A source that passes probing must still be safe to decode and suitable for chunk planning.
- Keep media-bucket, journal-bucket, and stash-bucket settings aligned with the access policy for product storage. A cross-account media write must remain readable by the bucket owner while journal and stash records stay in the farm bucket.
- Keep transcode identity, active worker attempts, and stored object-size checks aligned. A stale completion must not release planning or replace a newer transcode attempt.
- Keep project-cache close behavior aligned with pending range reads. A task must not write to a closed local file or leave queued storage reads running after its work ends.
- Keep temporary credential refresh, request signing, and presigned URL lifetime aligned. A URL or storage request must not outlive the credentials that signed it.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Source manifest exceeds file, byte, metadata, or duration limits | Planning rejects the export before the fleet performs unbounded work | Request and manifest bounds in validateJobRequest and checkManifestBounds |
| A recording exceeds the supported pixel count or side length | Source probing or decoding can consume unsafe resources | The worker applies the shared decode limit and rejects oversized dimensions before preparation |
| A source video has no usable index or sparse keyframes | A chunk cannot seek safely into the source | The worker remuxes only safe H.264 sources and otherwise creates a keyframe-dense H.264 source before planning |
| Worker stops heartbeating or stops listing a task | Work can remain marked running and block job progress | Heartbeat cutoffs requeue the task; worker watchdogs stop stalled engines |
| Retry or hedge reuses an earlier multipart range | A later copy can overwrite bytes from an earlier copy | Per-dispatch part reservations and a bounded range budget |
| A chunk's stash, part sizes, or part range does not match its dispatch | The coordinator rejects the result and cannot safely stitch the chunk | uploadProblem checks stash identity, byte totals, part bounds, and multipart minimums |
| An audio section is misaligned or returns the wrong global packet range | The coordinator cannot combine sections without a gap or overlap | The Rust audio runtime enforces the packet grid, accounts for priming, and checks the expected first and last packets |
| Chunks disagree on codec headers or sample runs do not cover the timeline | The final MP4 cannot be joined safely | Assembly checks codec headers and full video and audio coverage |
| Multipart completion succeeds in storage but its response is lost | The coordinator may report a false failure or retry completion | Output size and header checks recognize an already committed object |
| HLS segment upload or playlist write fails | Progressive playback stops growing even while rendering continues | Segment reports are rebuilt from accepted results and playlist writes retry from the saved cursor |
| A transcode worker reports success for a stale attempt or a partial object | Planning can use the wrong source or wait forever on a false success | The coordinator checks the active worker and attempt again after reading the stored object's size |
| Media and journal buckets use the wrong credentials or ownership mode | Workers may read or write media but the product owner cannot use the result, or recovery records are unavailable | Separate media and journal configuration with bucket-owner access for cross-account media writes |
| Instance-role metadata returns invalid, expired, or unavailable credentials | Storage reads, uploads, or playback links fail without changing to usable credentials | Bounded IMDS refresh validates the response and keeps prior credentials until a complete refresh succeeds |
| A project cache closes during a range fetch | A task can fail or write to an invalid local descriptor | Close checks stop queued work and reject in-flight work before the write or completion step |
Key files
| File | Why to read it |
|---|---|
| apps/…/coordinator.ts | Main control plane for request handling, planning, scheduling, journaling, result acceptance, stitching, assembly, and client status. |
| apps/…/planning.ts | Explains how timeline frames become work-sized chunk boundaries and how chunk part ranges support retries and the HLS lead-in. |
| apps/…/protocol.ts | Defines the shared meanings of video, audio, transcode, progress, segment, stash, and result messages. |
| apps/…/worker.ts | Shows the worker lifecycle from source probing and preparation through materialization, rendering, HLS upload, multipart upload, heartbeat, drain, and failure reporting. |
| apps/…/transcode.ts | Defines the source safety limits and the decision between direct remux and indexed H.264 preparation. |
| apps/…/transcode.test.ts | Summarizes the guarantees for source limits, remux eligibility, and preparation progress reporting. |
| apps/…/materialize.ts | Shows how each worker creates a sparse local project view from only the required object-store ranges and safely manages its cache lifecycle. |
| apps/…/stitch.ts | Defines how the coordinator joins the MP4 header and chunk stashes into valid multipart parts without padding. |
| apps/…/mp4.ts | Defines the source index and final MP4 header and sample-table boundary. |
| apps/…/recovery.ts | Shows the safeguards for multipart completion, duplicate acceptance, and retry part ranges. |
| apps/…/s3.ts | Defines the media, journal, and multipart object-store roles, request signing, temporary instance-role credentials, retry behavior, server-side part copies, and cross-account media access. |
| apps/…/README.md | Gives the deployment-level mental model, current journal version rules, storage roles, and product integration contract. |
| crates/…/main.rs | Defines the service-to-Rust engine protocol, streaming progress events, and the long-lived request loop used by workers. |
| crates/…/project.rs | Shows how all chunks derive a shared project timeline and source spans from the same prepared project. |
| crates/…/video.rs | Shows the Rust video task boundary and the long-lived GPU rendering role. |
| crates/…/audio.rs | Shows sample-aligned audio sections, encoder priming, pre-roll, and the checks that preserve continuity at section seams. |