Short answer: lifecycle rules should expire automated backups, while manifests, deletion ledgers, and restore tests prove 30- or 90-day retention in each US and EU region.
Daily backups are easy to schedule and surprisingly hard to delete correctly. For a B2B SaaS product that stores tenant product images, I would make retention a data contract: keep every successful backup for 30 or 90 days, prove which objects are eligible for deletion, and make a tenant-scoped export independent of lifecycle cleanup. The storage price matters, but an untestable deletion rule costs more than a slightly higher monthly bill.
The data flow before the bucket
An image arrives with a tenant ID, an immutable object key, and a checksum. The application writes the original image, then a manifest that records the key, byte count, checksum, creation time, and retention class. A daily backup job copies database metadata and the manifest into a separate backup prefix. An export job reads only the requested tenant's manifest and streams signed, time-limited download URLs. Lifecycle automation acts on backup prefixes, never on the live-image prefix.
That separation is the important bit. If a retention rule sees only object age, it cannot tell a failed backup from a complete one. The manifest gives the job something testable: a backup is complete only after all expected keys and checksums are recorded.
Boundaries matter.
How should daily backups enforce 30 or 90 day retention across regions?
Treat US and EU as two policy instances, not as a single global clock. Each region gets its own bucket or account boundary, its own backup prefix, and an explicit policy version. Store timestamps in UTC, calculate eligibility from the backup's completion time, and write the policy version into the manifest. A 30-day rule and a 90-day rule can then coexist without guessing which setting was active when an object was created.
Object lifecycle rules are a last-mile deletion mechanism. They are useful for predictable age-based expiry, but they do not replace backup verification, legal holds, or an audit trail. Keep a deletion ledger outside the expiring prefix with tenant ID, object key, policy version, eligibility time, and deletion result. If a customer asks for an export near the expiry boundary, the export service checks the ledger and manifest before issuing a URL.
A small implementation that keeps policy visible
The following TypeScript sketch uses an S3-compatible client interface without coupling the application to a particular provider. The lifecycle configuration is deployed separately; application code still decides what is complete and what may be exported.
type RetentionDays = 30 | 90;
type BackupRecord = {
tenantId: string;
completedAt: string;
retentionDays: RetentionDays;
policyVersion: string;
objects: Array<{ key: string; sha256: string; bytes: number }>;
};
interface ObjectStore {
put(key: string, body: Uint8Array, metadata: Record<string, string>): Promise<void>;
head(key: string): Promise<{ bytes: number; etag?: string }>;
presignGet(key: string, expiresInSeconds: number): Promise<string>;
}
async function createTenantExport(
store: ObjectStore,
record: BackupRecord,
now = new Date(),
): Promise<string[]> {
const expiry = new Date(record.completedAt);
expiry.setUTCDate(expiry.getUTCDate() + record.retentionDays);
if (now >= expiry) throw new Error("backup-retention-expired");
const urls: string[] = [];
for (const object of record.objects) {
const head = await store.head(object.key);
if (head.bytes !== object.bytes) throw new Error("manifest-size-mismatch");
urls.push(await store.presignGet(object.key, 900));
}
return urls;
}
The 900-second URL lifetime is an application choice, not a retention guarantee. Presigned URLs inherit the permissions of the signer, so the signer should have read access only to the selected tenant prefix; AWS documents this permission model and expiry behavior in its presigned URL guide. Never place a URL in a durable export record. Store the manifest reference instead and mint URLs when the user starts a download.
Failure modes, trade-offs, and tests
The first test I write advances a fake clock to 29, 30, 31, 89, 90, and 91 days. It verifies that the export decision uses completion time and that a lifecycle event is treated as asynchronous. The second test uploads an incomplete manifest, runs the backup verifier, and confirms that no retention countdown starts. The third test requests a tenant export while another tenant has similarly named keys; the result must contain zero cross-tenant objects.
Then test operational edges: a repeated daily job must be idempotent, a checksum mismatch must quarantine the backup, and a deletion ledger write must happen before the object is eligible for expiry. I once assumed a successful copy meant a usable backup. It didn't; the manifest was missing two image keys, and the only visible symptom was a smaller export. That is why byte counts and key counts belong in the record, even when the storage API already returns an object checksum. A useful drill restores a randomly selected tenant, compares every image checksum, measures export latency, and records the exact policy version; run it once before launch and again after a lifecycle change. The extra work feels fussy until a customer asks for an image that expired yesterday, at which point an unrecorded assumption becomes an incident you cannot explain.
| Setup pattern | Lifecycle fit | Best use | Main constraint |
|---|---|---|---|
| Managed S3-compatible service | Age and prefix rules are usually available | Small teams needing regional capacity | Provider-specific event and egress behavior |
| Self-hosted object store | Rules depend on your deployment and scheduler | Teams operating their own infrastructure | You own upgrades, replication, and audits |
| Archive tier behind a gateway | Long retention with slower retrieval | Compliance copies and cold backups | Restore latency and retrieval charges |
Choosing a storage setup without a false bargain
Compare providers and self-hosted systems on lifecycle expressiveness, regional placement, egress behavior, audit events, and the quality of their S3-compatible surface. “Compatible” is not a conformance certificate: check multipart uploads, conditional writes, versioning, delete markers, and presigning in a disposable test account. A pricing page can help model request and egress mix, but it cannot tell you whether a deletion event is observable or whether a restore is fast enough for your recovery objective.
The catch is that age-based lifecycle cannot express every business rule. It is not suitable when deletion depends on a legal hold, an external billing state, or a backup-completeness signal. In those cases, keep the policy engine in your application and use lifecycle only after the engine writes an explicit eligibility marker. Stick with a simpler object store when your team cannot monitor deletion events or rehearse a restore; operational confidence beats a nominally cheap tier.
My deployment checklist is short prose: pin a policy version, isolate live and backup prefixes, verify manifests before starting retention, log every export and deletion decision, run the boundary-clock tests in both US and EU environments, and perform a restore drill before changing 30 days to 90. I'm not sure any provider's compatibility label predicts these details, so your mileage will vary until the tests pass against the exact regions and credentials you will operate.
Top comments (1)
createTenantExport never uses object.sha256; it accepts any object whose ContentLength matches. That leaves same-length corruption outside the tests, even though the text says a checksum mismatch quarantines the backup. ETag is not a safe generic substitute, especially for multipart uploads. Either compare a provider-supported SHA-256 checksum or read and hash the accepted bytes, then add a test where the replacement object has identical length but different content. The export path is exactly where that fail-closed check should run, before a signed URL is issued.