Short answer: object storage is a better home for AI-generated images because image bytes have a different lifecycle from the metadata around them. A relational database should record ownership, prompts, status, and a deletion deadline. Object storage should hold the blob. The design that survives an on-call page is a deletion contract that both systems can enforce and an operator can inspect.

For a media training pipeline, I would start with a 30-day retention rule unless a documented business or legal requirement says otherwise. That is an example policy, not a universal default. The deadline must be explicit, stored with the artifact metadata, and tested as a state transition.

The page fires: where did the old images go?

The alert says the training-artifact cleanup queue has retried for 18 minutes. The dashboard shows expired image records accumulating, but the database still accepts new metadata. The on-call question is narrower: are the image bytes still retrievable after their metadata was deleted, or did a worker delete the record before deleting the object?

The bytes are not the contract.

A row deletion can succeed while a separate object deletion is delayed, retried, or sent to the wrong key. The reverse leaves a record promising an image that cannot be fetched. A larger database column does not solve either failure. A visible lifecycle does.

Instrument four transitions: eligible, delete_requested, object_deleted, and metadata_deleted. Each event gets an artifact ID, expiry timestamp, attempt count, and result. The useful alert is not merely "cleanup failed." It is "expired artifacts with no successful deletion transition are increasing for 15 minutes." A threshold that is too low pages during every normal batch. One that is too high lets the retention boundary become fiction. Measure both costs.

Why is object storage better for storing images than relational databases?

An AI-generated image is a binary object with a small set of searchable facts around it. The database is good at those facts: authorization scope, prompt hash, model label, content type, creation time, retention deadline, moderation state, and an object pointer. It is also good at joins and constraints. It is a poor place to make every image byte participate in those concerns.

Object storage gives the blob a key and a byte-oriented lifecycle. The application can stream the image while the relational side stays focused on records that need queries. expires_at belongs in metadata; the object key belongs in metadata; neither should be inferred from a display filename.

That separation has a boundary.

Generated images are often replaced. A generation can be incomplete, moderation can reject it, or a new rendition can become canonical. Versioned, deterministic keys let a worker address a concrete object instead of guessing from a human name. The database still owns which version is current.

Choice Best fit Main trade-off
Object storage plus relational metadata Large, streamed, versioned images with independent retention Two systems must be reconciled
Relational database binary column Small values always read with one row Row growth and blob lifecycle stay coupled
Filesystem or shared volume Local processing scratch space Recovery and multi-host retention need separate controls

The split is not free. It adds an upload state, an outbox or retry path, and a reconciliation job. For a small internal tool that stores a few thumbnails and never streams them independently, a relational binary column may be the more boring and correct choice. The object-storage pattern earns its complexity when image size, independent reads, replacement, or retention policy makes the coupling expensive.

{ "artifact_id": "media_01HXYZ", "object_key": "training/2026/10/media_01HXYZ/v1.png", "content_type": "image/png", "created_at": "2026-10-28T09:30:00Z", "expires_at": "2026-11-27T09:30:00Z", "deletion_state": "eligible" } 

Those dates show the contract in a testable form. They do not prescribe retention for every media operation. The policy owner decides whether 30 days fits the training set, audit obligations, and user expectations.

What does a reliable deletion worker guarantee?

The worker must be idempotent. A retry after a timeout cannot create a second image, corrupt a replacement, or turn an already-completed delete into a permanent failure. Delete the exact key recorded in metadata, and distinguish an already-absent object from a permission or transport failure. Those outcomes require different action.

A queue message needs enough information to repeat the operation without reading mutable presentation data. I use the artifact ID, object key, and expected version. The worker verifies that the row is still eligible before removal. A later retention extension must beat an old deletion message; otherwise a routine retry can delete an artifact after its policy changed.

This Go sketch shows the decision boundary. The interface is generic because the important behavior is ordering and idempotency, not a provider SDK.

package retention import ( "context" "time" ) type Artifact struct { ID string ObjectKey string ExpiresAt time.Time State string } type Store interface { Delete(context.Context, string) error } type Metadata interface { Get(context.Context, string) (Artifact, error) MarkDeleted(context.Context, string) error } func Expire(ctx context.Context, now time.Time, id string, objects Store, metadata Metadata) error { a, err := metadata.Get(ctx, id) if err != nil { return err } if a.State != "eligible" || now.Before(a.ExpiresAt) { return nil } if err := objects.Delete(ctx, a.ObjectKey); err != nil { return err } return metadata.MarkDeleted(ctx, a.ID) } 

In production, MarkDeleted should be conditional on the state observed by the worker. Emit a metric when that conditional update does not apply. It often means retention was extended or another worker finished first; it is not automatically a storage outage.

The ordering is deliberate: remove the object, then mark metadata deleted. That avoids claiming an artifact is gone while its bytes remain. It leaves a possible orphan if the final metadata update fails, so a periodic reconciliation job is required. Reconciliation finds keys whose metadata is absent or terminally deleted and applies the same policy. It is a backstop, not a substitute for idempotent workers.

The orphan is an expected failure mode, not a reason to pretend the systems are one transaction.

Consider a concrete race. At 09:30, an artifact is eligible for deletion and a worker reads that state. At 09:31, a user extends retention to 60 days, but the old queue message is still in flight. If the worker deletes by object key and only then checks anything else, the policy update arrives too late. A conditional state change prevents that race, but it does not remove the need for reconciliation: a network timeout can happen after storage accepts the delete, and a process can die before recording the result. The next attempt must treat an absent object as a terminal success and leave evidence for an operator to distinguish an expected retry from a broken permission. This is why metadata state, object key, policy version, and attempt result travel together. The extra bookkeeping is the operational price of independent lifecycles.

Keep it boring.

Which signal should fire before the cleanup page?

The first useful signal is expiry-to-completion delay, not raw delete volume. Record the time between expires_at and object_deleted. Alert on a sustained increase in the oldest unresolved artifact, then page on a policy breach. A queue with 10,000 messages can be healthy if it drains; a queue with 20 can be broken if its oldest item is stuck.

Keep metric dimensions bounded. Artifact IDs belong in logs and traces, not labels. Counters for attempts, terminal successes, retryable failures, conditional skips, and reconciliation findings are enough to start. Add a gauge for the oldest unresolved expiry. Generated media can contain sensitive material even when its prompt looks harmless, so access to object keys in logs needs a deliberate policy.

Test these paths before deployment: successful deletion; an already-absent object; a timeout after remote acceptance; a retention extension while a stale message is in flight; metadata failure after object deletion; and two workers processing one artifact. Every path must end in a state the next retry understands.

What belongs in the database, and what belongs in object storage?

Use relational metadata for identity, authorization scope, content type, policy version, retention deadline, processing state, and object key. Keep the object store responsible for bytes and byte-oriented metadata such as length or checksum when available. Do not make a filename the source of truth for authorization or retention.

A database transaction can create metadata and an outbox event for an upload request. The upload retries independently. The record should not become available until the application has evidence that the object is readable. If upload fails, leave the record visibly incomplete and eligible for cleanup instead of presenting a valid image with a missing payload.

Recovery needs both sides. A database backup without corresponding objects is not a complete artifact backup, while an object copy without metadata loses ownership and retention context. Drills should verify the relationship by artifact ID and key and report mismatches.

Object storage is not automatically right for every binary. A tiny value always read with one row can be simpler beside that row. The split becomes compelling when images are large, independently streamed, versioned, or governed by a lifecycle policy different from row metadata. Generated media commonly has all four properties.

The decision rule for the runbook

If image bytes need independent streaming, replacement, or retention, put them behind an object key and keep the searchable contract in relational metadata. Set an explicit expiration time. Make deletion idempotent. Delete the object before declaring metadata gone, then reconcile the gap. Alert on unresolved-expiry age and the oldest orphan, with thresholds based on the policy deadline rather than queue size alone.

This is a lifecycle decision. The database answers "which artifact is this, who may use it, and when does policy expire?" The object store answers "where are the bytes, and can they be streamed or deleted by this key?" Keeping those questions separate gives an SRE a smaller failure domain when the page arrives.

Further reading