The page says thumbnail_deletion_deadline_breached: after an image replace, object storage cleanup did not delete 17 old thumbnails under tenant_42/document_8f3/generation_0194, and the action is 14 minutes late. The signed document itself is present and the replacement thumbnails look fine. That is exactly why this alert is easy to underestimate: the user path recovered, but the retention promise did not.

Short answer: on image replacement, write thumbnails under an immutable generation prefix, commit the new generation, and enqueue an idempotent cleanup action for the old generation. The worker should list the exact old prefix with pagination, batch-delete those keys, verify absence, and record completion before the explicit deadline. Use a one-day lifecycle rule only as a backstop when that delay meets the retention requirement; it is not the primary deletion mechanism for a shorter deadline.

Don't delete the old prefix inline with the replace request. A timeout would leave the caller unable to tell whether the replacement committed, the cleanup committed, both committed, or neither committed. The durable action is the boundary that makes those states observable.

Incident evidence from the deletion-deadline page

It proved less than it appeared to. A counter of expired objects may mean that a cleanup action was never created, that the queue did not deliver it in time, that pagination stopped after the first page, that a batch was only partly acknowledged, or that deletion succeeded while the verification view had not caught up under the storage system's documented behavior. One alert cannot distinguish those cases. The on-call needs the document generation, tenant, deadline, action ID, attempt count, last listed page token, requested key count, acknowledged key count, and verification result in one trace.

Start the investigation at the state transition, not at a bucket browser. For a document replacement, the application record should identify both new_generation=0195 and retired_generation=0194. There should then be one cleanup action whose idempotency key is derived from the tenant, document, and retired generation. If that action is absent, paging the storage worker is noise; the write path failed to establish the deletion obligation. If the action exists but has no attempts, inspect scheduling. If attempts exist, compare page and batch checkpoints rather than rerunning an unbounded delete from a laptop.

This separation matters for signed documents. A thumbnail is derived data, but it can still reveal names, signatures, initials, or page content. NIST SP 800-66 Rev. 2 frames regulated-system work around risk analysis, safeguards, audit controls, and documented policies. It does not prescribe this key layout. It does support the operational conclusion: a deletion deadline needs auditable evidence, not an assumption that old derived files will eventually disappear.

Fast diagnosis is useful. Earlier warning is better.

How can Node.js implement prefix cleanup to delete old thumbnails?

Treat replacement as a generation change. Never overwrite current/page-1-small.webp; write generation_0195/page-1-small.webp, generation_0195/page-1-medium.webp, and the other variants, then atomically point the application manifest at generation 0195. The retired generation is now a closed set with a stable prefix. New resize work cannot legitimately add keys beneath it after retirement.

The Node.js service should persist the cleanup action in the same database transaction that changes the manifest, commonly through an outbox row. A dispatcher publishes that action to a queue. A worker claims it, lists tenant_42/document_8f3/generation_0194/ until the continuation token is empty, accumulates keys into batches no larger than the storage API allows, deletes each batch, and stores progress. The exact SDK calls vary, but the state machine does not.

State Durable evidence Safe retry behavior
pending Old prefix, deadline, idempotency key Publish or claim the same action
listing Continuation token and discovered key count Resume from a documented checkpoint, or relist the immutable prefix
deleting Batch fingerprint and per-key acknowledgement Retry only unacknowledged keys
verifying Verification timestamp and remaining keys Relist the same retired prefix
complete Zero remaining keys and completion time Return success without touching the new generation

The important invariant is short: only a retired generation can be deleted.

Here is the worker core in Go because the control flow is easier to inspect without tying the design to one Node.js SDK. The Node.js implementation should preserve the same interfaces, checkpoints, and cancellation behavior.

package cleanup import ( "context" "fmt" "time" ) type Page struct { Keys []string NextToken string } type ObjectStore interface { List(ctx context.Context, prefix, token string) (Page, error) Delete(ctx context.Context, keys []string) (acknowledged map[string]bool, err error) } type CheckpointStore interface { SavePage(ctx context.Context, actionID, nextToken string, seen int) error SaveBatch(ctx context.Context, actionID string, pending []string) error Complete(ctx context.Context, actionID string, completedAt time.Time) error } func DeleteRetiredPrefix( ctx context.Context, objects ObjectStore, checkpoints CheckpointStore, actionID string, prefix string, batchLimit int, ) error { if batchLimit < 1 { return fmt.Errorf("batch limit must be positive") } token, seen := "", 0 for { page, err := objects.List(ctx, prefix, token) if err != nil { return fmt.Errorf("list retired prefix: %w", err) } for start := 0; start < len(page.Keys); start += batchLimit { end := start + batchLimit if end > len(page.Keys) { end = len(page.Keys) } batch := page.Keys[start:end] if err := checkpoints.SaveBatch(ctx, actionID, batch); err != nil { return fmt.Errorf("save batch checkpoint: %w", err) } ack, err := objects.Delete(ctx, batch) if err != nil { return fmt.Errorf("delete batch: %w", err) } for _, key := range batch { if !ack[key] { return fmt.Errorf("key not acknowledged: %s", key) } } } seen += len(page.Keys) if err := checkpoints.SavePage(ctx, actionID, page.NextToken, seen); err != nil { return fmt.Errorf("save page checkpoint: %w", err) } if page.NextToken == "" { break } token = page.NextToken } verification, err := objects.List(ctx, prefix, "") if err != nil { return fmt.Errorf("verify retired prefix: %w", err) } if len(verification.Keys) != 0 || verification.NextToken != "" { return fmt.Errorf("verification found remaining keys") } return checkpoints.Complete(ctx, actionID, time.Now().UTC()) } 

This sample deliberately leaves provider limits in configuration. Don't copy a batch size from a different object store. Validate the configured maximum against the provider documentation and test partial acknowledgements, empty pages with a continuation token, cancellation, duplicate delivery, and a crash after remote deletion but before the local checkpoint. I've been paged by missed jobs and duplicate deliveries; the useful response is to make both paths ordinary state transitions. A duplicate cleanup action should converge on zero keys, while a missed dispatch should be found by a database sweeper before the deletion deadline.

Measuring the earlier deadline signal

The breach page is a lagging signal. The earlier signal is predicted deadline exhaustion: time_to_deadline - estimated_remaining_work - retry_budget. Calculate it from the oldest unfinished cleanup action, current queue age, discovered key count, recent worker throughput, and the provider's documented request behavior. I'm not sure a single throughput window will be accurate during a large tenant import; your mileage may vary. Resolve that uncertainty by replaying production-shaped key distributions in a non-production bucket and retaining percentiles by object count and page count.

Instrument four moments: obligation created, first attempt started, each page or batch checkpointed, and absence verified. Emit counts for actions by state and age, plus separate counters for duplicate claims, partial acknowledgements, and verification findings. Logs should carry the same action ID as the database row. A trace without durable state is a story; durable state without a trace is a slow incident.

Page on deadline risk or a deadline breach. Ticket on isolated retries that remain inside the retry budget. A worker error by itself is not evidence that retention failed, and paging every retry trains the on-call to ignore the one signal that matters.

Retention governance under lifecycle and versioning

A lifecycle rule is valuable defense in depth when its minimum age and execution semantics fit the policy. If the shortest applicable rule is one day but the signed-document contract says thumbnails must be gone within an hour, waiting for lifecycle is not suitable. Keep immediate, manifest-driven cleanup and use lifecycle to catch abandoned generations that escaped the application workflow. If the policy genuinely permits the lifecycle window and exact deletion timing is not contractual, the simpler rule may be preferable to a queue, checkpoints, and an on-call burden.

Versioning also changes what “deleted” means. In Amazon S3's documented model, overwriting an object creates another version, and a simple delete can add a delete marker rather than permanently remove earlier versions. An absence check against the current view therefore does not prove permanent removal of noncurrent data. If versioning is enabled, define whether the deadline applies to current visibility, every stored version, or both, then configure and verify deletion accordingly. Other stores can use different semantics, so this is a contract to confirm, not a portable assumption.

The catch is operational weight. Prefix listing and batch deletion are a poor fit when the application already has a complete, trustworthy manifest of every thumbnail key; exact-key deletion removes a scan and makes the expected count explicit. Stick with a prefix sweep when variants can be added independently and the manifest cannot prove completeness. For extremely large retired generations, partition the work by a predeclared shard in the key layout instead of allowing one action to monopolize a worker.

Operational rollout and the false-positive cost

After the instrumentation change, close the incident only when the retired generation verifies empty under the storage contract, the durable action is complete, and a reconciliation query finds no other overdue actions. Then test three scheduled paths: queue delivery, the sweeper that republishes missed actions, and the lifecycle backstop. The test clock should cross warning time and deadline separately so an early warning cannot masquerade as a breach.

Thresholds have a cost. A risk alert based on a brief throughput dip can wake someone even though retries have ample time; a long averaging window can hide a fast-growing backlog. Start the warning far enough ahead to allow one full retry budget, require more than one observation for a forecast-only page, and page immediately at the actual deadline. Measure alerts that resolved without intervention and adjust the forecast, never the retention deadline.

Quiet is good only when it is earned.

References