← Building blocks

Process uploads in parallel

Data processing & searchstaff

Transcoding a long video or processing a large file takes hours on one worker.

Say it like this

A two-hour upload would take hours on one encoder, so I split it at keyframes into chunks and run the encodes as a DAG of parallel tasks with per-task retries, which turns wall-clock time into a few minutes and makes a failure cost one chunk instead of the whole file.

Basic solution

Split into chunks, process chunks in parallel as a DAG of tasks with retries per task, then stitch.

FFmpegTemporal / Step FunctionsAirflowworker pools

Probe, split, parallel encode, package

The orchestrator turns one upload into a DAG: a probe and split, then one idempotent encode task per chunk and rendition running in parallel, then a fan-in package step that writes the manifests and flips the video to ready.

How it works

  1. The upload completes and a message containing the object key lands on the transcode queue, in one of three priority lanes: premiere, normal or bulk.
  2. The orchestrator creates a durable workflow record for the video and runs the probe task, which reads the file's metadata: codec, duration, resolution, and the positions of its keyframes.
  3. The split task cuts the source at group-of-pictures boundaries, which start with a keyframe, into chunks of 10 to 30 seconds. Each chunk can be decoded on its own, which is what makes the rest of the pipeline parallel. The chunks are written to object storage.
  4. Fan-out: for every chunk and every target rendition (1080p, 720p, 480p, 360p) the orchestrator enqueues one encode task. Workers pull tasks, read their chunk, encode it with FFmpeg, and write the output chunk back. Side tasks run in parallel on the same queue: audio transcoding, thumbnails, a copyright fingerprint.
  5. Each task is keyed by (video, chunk, rendition) and writes to a path derived from that key, so a retry overwrites the same output object rather than creating a second one. The orchestrator records each task's completion; a worker that crashes mid-task just leaves the task to be re-queued.
  6. Fan-in: when the orchestrator sees that every task for the video has completed, it runs the package task, which concatenates the chunks of each rendition in order, writes the segment playlists and the master manifest, and flips the video's metadata to ready in a single write. For a premiere the CDN is pre-warmed with the first segments.

What the orchestrator owns

  • The task graph, its state, retries with backoff, timeouts per task, and priority. Workers own only the encode. Keeping state out of the workers is what lets you scale them to zero and back.

Worked example

Transcoding on the video streaming platform

  • 500K uploads per day, average 10 minutes, so 5M minutes of source video per day; peak hour carries 5 percent of the day, about 25K uploads.
  • Encode cost: 1080p at roughly real time on one core, 720p at 2x, 480p at 4x, 360p at 8x real time. Per source minute that is about 1 + 0.5 + 0.25 + 0.125 = 1.9 core-minutes, so 5M source minutes need 9.5M core-minutes per day, about 6,600 cores busy all day, or roughly 8,000 cores during the peak hour (250K source minutes x 1.9 core-minutes, finished within 60 minutes). A fleet of 250 to 300 32-core workers, autoscaled for bursts.
  • Chunking: a 10-minute video in 20-second chunks is 30 chunks; times 4 renditions is 120 encode tasks plus 3 side tasks. The longest task is a 1080p chunk at about 20 seconds of encoding, so the whole video finishes in roughly 40 seconds of wall clock plus queueing, instead of 19 minutes serially.
  • Task volume: 500K videos x 123 tasks = 62M tasks per day, 700 per second average, 3,500 per second at peak. The orchestrator must sustain that write rate for task state; a workflow engine with a sharded state store, or a task table partitioned by video id.
  • Failures: at a 0.1 percent task failure rate, 62K retries per day; each retry costs one chunk encode of about 20 core-seconds, so retries add about 0.2 percent to compute. Without chunking, 0.1 percent of 500K whole-file encodes failing would waste 500 x 19 core-minutes = 160 core-hours per day and delay those videos by the full encode time.
  • Priority: a premiere from a creator with 10M subscribers jumps the queue; bulk re-encodes for a new codec run only when the normal lane is idle. Three lanes with weighted pulling, never strict priority.
  • Storage: chunks are temporary; a lifecycle rule deletes intermediate objects 24 hours after the video is ready.

Variants and when each wins

Workflow engine orchestration (Temporal, Step Functions)

  • A service that holds the task graph and its state durably and handles retries, timeouts and fan-in for you, with the DAG written as code. It wins for anything with fan-out and fan-in, which is every transcoding pipeline.

Queue per stage

  • Separate queues for probe, encode and package, with workers per stage and a status table to track progress. It wins on infrastructure simplicity; deciding when all 120 tasks are done and retrying the failed ones becomes your code.

Managed transcoding (AWS MediaConvert, Mux)

  • Hand the file to a service and receive renditions back. It wins while volume is modest, because there is no fleet to run; you give up control over cost, priority and custom side tasks.

Single worker per file

  • One job encodes the whole file from start to finish. It wins for an MVP or short clips; there is no parallelism, and a failure near the end restarts everything.

Recommendation: chunked DAG on a workflow engine with your own FFmpeg fleet at scale, managed transcoding until the volume justifies the fleet.

Failure modes

Orchestrator state lost

  • Videos sit in processing forever after a deploy, with all their chunks encoded but no manifest written. It happens because task state was kept in a worker's memory or in a store without replication, so the record of which tasks finished was lost. Keep workflow state in a durable store, record each task's completion before acknowledging it, and resume from that record on restart.

Chunk boundary not on a keyframe

  • A visible glitch or a decode error at every point where two chunks join. It happens because the split was made at fixed times rather than at group-of-pictures boundaries, so a chunk's first frames depend on data in the previous chunk. Probe the keyframe positions first and cut only there, and force a fixed keyframe interval when encoding so every rendition's chunks line up.

Head-of-line blocking by bulk work

  • A new upload waits an hour behind a library-wide re-encode. It happens because there is one queue and it is served first in, first out. Use priority lanes, have workers pull from them with weights, and cap how many bulk tasks run at once.

Retry storm on a poisoned file

  • Workers spend the whole day failing the same chunk over and over. It happens because a corrupt source file is retried without limit. Give each task a retry budget, and when it is spent, dead-letter the video with a clear status and alert a person.

Fleet idle or saturated

  • Either thousands of cores sit idle, or the backlog keeps growing. It happens because the fleet is a fixed size while uploads arrive in bursts. Autoscale the workers on queue depth and the age of the oldest task, and let the bulk lane run on cheaper spot capacity.

Intermediate storage never cleaned

  • Object storage costs climb while the catalogue barely grows. It happens because chunks and intermediate outputs are kept forever after packaging. Add a lifecycle rule on the intermediate prefix and delete the chunks when packaging succeeds.

Interviewer follow-ups

Answer out loud before you open each one.

Why cut at keyframes, and what is a GOP?

A group of pictures starts with a keyframe that can be decoded on its own, followed by frames that reference it. Cutting anywhere else leaves a chunk whose first frames depend on data in the previous chunk, so each chunk must begin at a keyframe to be encoded independently.

How do you know all 120 tasks for a video are finished?

The orchestrator holds a counter or a completion set per video, updated atomically as each task reports success, and triggers the package step when the count reaches the expected total. A workflow engine does this with a fan-in wait; with plain queues it is a conditional update on the video row.

How do you prioritise a big creator over bulk work without starving the bulk lane?

Separate lanes per priority, and workers pull with weights such as 70 percent premiere and normal, 30 percent bulk when both have work. Strict priority would let a long re-encode campaign never finish; weights guarantee progress on every lane.

What does chunking cost you?

Slightly lower compression efficiency at chunk boundaries, a split and a concatenate step, temporary storage for intermediates, and an orchestrator that must track thousands of tasks per video. In exchange, wall-clock time drops from minutes to seconds and a failure costs one chunk.

Connections

In study paths
Video from upload to play
Built on
DAG of tasks
Pairs with
Move slow work off the request · Keep urgent work ahead of bulk work · Upload large files without touching your servers · Stream video to any connection · Keep large blobs out of the database · Make retries safe · Park poison messages
Used in
Video Streaming Platform (YouTube / Netflix)

The same parts on other clouds

The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.

AWSUsed here asGoogle CloudMicrosoft AzureOpen source and others
Amazon SQSTranscode queuePub/Sub, Cloud TasksService Bus queues, Queue StorageRabbitMQ, ActiveMQ
AWS Step FunctionsOrchestratorWorkflowsLogic Apps, Durable FunctionsTemporal, Apache Airflow
Amazon EC2Probe + split, Encode 1080p, Encode 720p, Encode 480p / 360p, Side tasks, PackageCompute EngineAzure Virtual MachinesDigitalOcean Droplets, any VM or bare metal
Amazon S3Object storageCloud StorageBlob StorageCloudflare R2, MinIO, Ceph