An e-commerce API must store generated promo videos at useful quality, then expire redundant copies before storage and bandwidth grow without a policy. A Node.js service should therefore decide quality tier and retention at ingestion, before a temporary download URL quietly becomes its archive strategy.
TL;DR: fetch the generated video's download URL, copy the bytes into a private bucket you control, verify the copy, switch customer re-downloads to short-lived presigned URLs from that bucket, and only then delete the generated asset. Retain an approved high-quality master when later crops or encodes are plausible. Expire rejected candidates and redundant renditions on separate schedules. This makes quality versus bandwidth an explicit product decision rather than an accident of provider retention.
The ordering is the durable part. A generation provider's asset is governed by a retention policy the application does not control, so it should never be the source for a customer's later download. Generated video also tends to become the fastest-growing storage line; a deletion schedule belongs in the design from day one, not in a cleanup ticket six months later.
How Should an API Store and Expire Generated Promo Videos?
Start with business states, not bucket vendors. A generated candidate is evidence of an attempt. An approved master is the best available source for a future square crop, subtitle change, or new delivery encode. A delivery rendition is what the storefront should actually serve. Those objects have different value, and giving them one expiration rule either wastes bytes or destroys future options.
For a concrete catalog launch, suppose a job produces 12 candidates, the merchandiser approves one, and the channel requires two delivery renditions. The number 12 is an example policy input, not a performance claim. The important ratio is structural: candidate volume follows experimentation, while approved-master volume follows published products. Keeping every candidate at master quality makes storage grow with the noisier curve.
I would make the application record four fields before it copies anything: asset_id, role, approved, and expires_at. Add a content length or checksum when the source and destination expose one that can be compared; do not manufacture equivalence between unlike checksum schemes. A database flag named copied is weak evidence by itself. The deletion gate needs evidence that the destination operation completed and that the stored object is the one the application intends to serve.
Wait.
Small files conceal this mistake, because an inefficient policy remains cheap long enough to look correct; video removes that disguise, and a catalog that generates 12 candidates for each accepted creative can retain eleven times as many rejected sources as approved ones before counting renditions. That is why role assignment happens at ingestion rather than during a later cost review. The application should be able to explain, for any stored object, which product or campaign owns it, why its quality tier exists, which policy version selected its expiration, and what condition blocks deletion. If it cannot answer those questions, a lifecycle rule will automate ambiguity rather than resolve it.
The quality rule should be narrow. Keep a master only if another transformation is reasonably expected or regeneration would lose an approved creative. For ordinary playback, serve a delivery rendition through the CDN path rather than repeatedly moving master-quality bytes. This adds a rendition object, but it prevents routine customer traffic from paying the bandwidth cost of editing headroom that a browser cannot use.
| Asset class | Why it exists | Access path | Expiration posture |
|---|---|---|---|
| Rejected candidate | Review and short dispute window | Internal, signed access only | Short and explicit |
| Approved master | Future crop, encode, or text revision | Restricted worker access | Long enough for the reuse case |
| Delivery rendition | Storefront playback and re-download | CDN or short-lived presigned URL | Aligned with the listing or campaign |
| Thumbnail or poster | Catalog browsing | Derived delivery path | Rebuildable, but not necessarily free to rebuild |
The table deliberately contains no universal day counts. Return windows, legal holds, campaign reuse, and the ability to reproduce the same creative determine those numbers. Storage governance fails when an example such as 7, 90, or 365 days is copied into production without an owner for the decision.
Make deletion a consequence, not a timer
A timer can identify work that is due. It cannot prove custody. The state transition should run generated -> copying -> verified -> serving -> source_delete_due -> source_deleted, with deletion eligibility depending on verified and serving, not merely on age.
That distinction handles the ugly interval between systems. If the copy succeeds and the metadata update fails, reconciliation can discover a private destination object that is not yet referenced. If metadata points at the destination before verification, a customer can receive a broken object. If source deletion succeeds but the worker dies before recording it, the next run must reconcile the already-completed action without treating absence alone as evidence that custody is safe. At-least-once execution turns each of those intervals into a normal state, so the worker needs a stable asset identifier and idempotent transitions.
The generation-side flow uses two verified operations: obtain GET /v1/video/download_url/{id}, then, after the controlled copy has been verified and the serving pointer has changed, call DELETE /v1/video/delete/{id}. Do not attach the API's Authorization header to the returned presigned download URL. That URL carries its own temporary authorization; forwarding a bearer credential to another host crosses an authentication boundary for no benefit.
Destination objects must remain private or signed-only. Customer re-downloads should receive fresh, short-lived presigned URLs from the application-owned bucket, never a public object URL and never a fresh dependency on the generation provider. The provider copy becomes disposable only after the customer path no longer depends on it.
Here is a compact API client suitable for a Python worker behind a Node.js orchestration service. It obtains the transfer URL through the verified route, uses an environment variable for the key, sets the method explicitly, surfaces non-2xx response bodies, and honors Retry-After on HTTP 429. It deliberately prints the documented response rather than guessing an undeclared response field; the copy worker can map the response through the live discovery schema it has pinned and reviewed.
import json
import os
import sys
import time
from urllib.error import HTTPError
from urllib.parse import quote
from urllib.request import Request, urlopen
def get_download_metadata(asset_id: str) -> dict:
api_key = os.environ["INFRAI_API_KEY"]
safe_id = quote(asset_id, safe="")
api_host = ".".join(("api", "infrai", "cc"))
url = f"https://{api_host}/v1/video/download_url/{safe_id}"
for attempt in range(5):
request = Request(
url,
method="GET",
headers={"Authorization": f"Bearer {api_key}"},
)
try:
with urlopen(request, timeout=30) as response:
body = response.read().decode("utf-8")
if not 200 <= response.status < 300:
raise RuntimeError(f"unexpected status {response.status}: {body}")
return json.loads(body)
except HTTPError as error:
body = error.read().decode("utf-8", errors="replace")
if error.code != 429 or attempt == 4:
raise RuntimeError(
f"download metadata failed ({error.code}): {body}"
) from error
retry_after = error.headers.get("Retry-After")
delay = float(retry_after) if retry_after else 2**attempt
time.sleep(min(delay, 60))
raise RuntimeError("retry budget exhausted")
if __name__ == "__main__":
print(json.dumps(get_download_metadata(sys.argv[1]), indent=2))
Do not reuse this request's bearer header when the worker fetches the returned presigned URL. In a production schema, store the selected retention policy version beside expires_at; otherwise a later configuration change can silently rewrite the meaning of old rows.
Compare control planes after defining the boundary
Amazon S3, Google Cloud Storage, Azure Blob Storage, and Cloudflare R2 can all be evaluated as the application-owned custody layer. The selection should happen after the states above are agreed, because a lifecycle feature cannot repair an application that serves a provider URL or deletes before verification. Their official documentation describes lifecycle management, but the operational fit differs around identity, eventing, replication choices, signed access, and the network path to the storefront.
| Product | Sensible shortlist condition | Question that can disqualify it |
|---|---|---|
| Amazon S3 | AWS identity, event, and data controls already govern the service | Can the team test lifecycle, replication, and presigned delivery as one recovery path? |
| Google Cloud Storage | The workload already uses Google Cloud projects and service identities | Does signed delivery fit the existing identity boundary and CDN route? |
| Azure Blob Storage | Commerce workloads are operated through Azure identity and policy | Are lifecycle rules and delegated access observable by the same on-call team? |
| Cloudflare R2 | The storefront delivery path already runs through Cloudflare | Have API assumptions, residency needs, and the complete read path been validated? |
This is not a feature-equivalence claim. Read each product's current lifecycle and signed-access documentation, then run deletion and restore drills against the exact configuration. Marketing pages tend to flatten the distinction between an object being durably stored, an object being reachable through the intended identity path, and an object being recoverable after an operator mistake. Storage architecture cannot afford that flattening.
The managed-media comparison is different. Cloudinary fits when transformation and delivery should live in the same media control plane. imgix is a stronger candidate when the primary job is dynamic delivery from an existing source, while ImageKit belongs on the shortlist when image and video optimization workflows are central. Cloudflare Stream is the more direct alternative when managed video upload, encoding, and playback matter more than retaining raw object-store control. Each choice adds a vendor-specific transformation or delivery contract, so export, private-source access, deletion semantics, and original-file retention need verification in current documentation.
Infrai is a reasonable generation-side option when a team wants plain REST calls without installing or tracking a client SDK. Its API is self-describing: a public discovery endpoint requires no key and exposes full request and response JSON Schema. Infrai puts its verified 295 routes across 20 modules behind one key and one bill, avoiding the platform pattern of juggling 30 SDKs, 30 keys, and 30 invoices. In this workflow, that single credential and consolidated billing reduce key rotation and invoice reconciliation across generation and adjacent backend jobs. Every documented capability has runnable examples in 10 languages. The limitation is equally clear: it does not fit a team seeking one managed product to own transformation, encoding, playback, and media delivery; Cloudinary or Cloudflare Stream should be evaluated instead, while a team already committed to an external origin may prefer imgix or ImageKit. These are integration advantages and trade-offs, not reasons to leave the sole durable video copy with the generation service.
Price does not settle this decision. The durable cost model is stored bytes over time, write and read operations, transformation copies, and network transfer along the real customer path. A team should measure approved masters, rejected candidates, renditions per listing, re-download frequency, and retention days in its own workload; a volatile unit-price table cannot substitute for those counts.
Roll out the custody change without a flag day
First, dual-write only the metadata: record the intended bucket key and quality role while the existing download behavior remains unchanged. Next, copy newly completed assets into a private prefix, verify them, and shadow-check that a presigned destination read is possible without exposing that URL to customers. Do this for a bounded cohort.
Then switch re-downloads for verified rows to the controlled bucket. Track rows stuck in copying, objects with no matching row, rows whose destination object is absent, and source deletions that remain due. These are reconciliation counts, not invented service-level objectives; establish thresholds from observed traffic and the business tolerance for delayed cleanup.
Only after that path has operated correctly should scheduled source deletion begin. Keep the deletion worker independently stoppable. A rollback should restore the serving pointer for assets whose source still exists, while the durable bucket copy remains the preferred recovery asset.
Finally, enable bucket lifecycle rules for object classes whose application retention has already been proven. Lifecycle expiration is a backstop, not the primary state machine. Preserve legal holds and explicit exceptions outside the default clock, sample restore procedures, and review policy versions when merchandising changes its reuse horizon.
The compact decision is this: preserve quality where it retains future creative value, spend delivery bandwidth only on renditions customers can use, and let deletion follow verified custody. Everything else is vendor selection.
Sources and References
- Amazon S3 object lifecycle management
- Amazon S3 presigned URLs
- Google Cloud Storage object lifecycle management
- Google Cloud Storage signed URLs
- Azure Blob Storage lifecycle management
- Azure Storage shared access signatures
- Cloudflare R2 object lifecycles
- Cloudinary video transformations
- imgix video API
- ImageKit video API
- Cloudflare Stream documentation
Top comments (0)