Request Lifecycle
1. Real-time image flow
Key implementation details:
- validate the HMAC signature and normalized options
- check memory LRU, then the media-bucket storage cache
- on a miss, fetch the original from the source bucket
- use singleflight to suppress duplicate fetch and transform work
- transform with libvips
- write the result to memory immediately and to storage asynchronously
- return CDN-friendly cache headers and an
ETag
This path is fully synchronous and does not require the queue.
2. Job submission flow
The important part is not only enqueueing work. The server first computes a request fingerprint from:
typehashsource- canonicalized
options
This is what gives POST /api/jobs its idempotency behavior. The source bucket itself is deployment-owned runtime config, not caller input.
For video jobs, the server also checks the configured source store before enqueueing so it can confirm existence, measure actual size, and route oversized work to video:large when needed.
3. Worker execution flow
Worker execution falls into two categories: single-stage jobs and the video:full workflow.
Single-stage jobs
image:thumbnailvideo:covervideo:previewvideo:transcode
Shared pattern:
- dequeue a task
- mark the job as
processing - download or fetch the source media
- run the media toolchain
- upload artifacts to the media bucket
- persist progress and final results
- optionally send a webhook callback
video:full
video:full is not implemented as a parent job that spawns child jobs. Instead it runs as one workflow task:
- download the source once
- run cover and preview in parallel
- if either fails, emit
stagesandretry_plan - only proceed to transcode if both succeed
- persist one aggregated result payload
This keeps the external API simple while preserving stage-level observability.
4. Playback flow
The server does not keep local copies of segments. It maps /stream/{hash}/... directly to media-bucket objects.
5. Cleanup flow
DELETE /api/media/{hash} is shorter-lived but important for consistency:
- resolve media-bucket objects associated with the hash
- clear image-cache tracking and related metadata
- cancel active, retry, or scheduled queue tasks
- remove encryption keys and job records
This flow is intentionally best-effort and idempotent, which makes it suitable for upstream compensation or retention jobs.