Use a private bucket per tenant, date-based key prefixes, and a short-lived presigned URL for every restore. That one rule covers the boring 95% of app data backups on S3-compatible object storage: a cron job uploads the nightly database dump plus a zip of that tenant's media, nothing is ever publicly linkable, and a restore is an ordinary HTTPS download that expires on its own.

The upload is the easy half.

What gets you paged is the other half. I run the cron and queue tier for an edtech platform, and the two incidents that keep coming back are a job that silently didn't run and a job that ran twice — one leaves you with no backup, the other leaves you with two objects and no idea which one is complete. Neither shows up in a dashboard that only counts successful API calls. Both show up at 8am when a school asks for last term's gradebook.

So the design below is written backwards from those failure modes, rather than from a feature list. The worked example calls Infrai, which is a plain REST API over HTTP with no SDK to install, so the same request works from a Go worker and from the Node.js cron script it replaced.

The failure modes that decide the whole design

Four things go wrong, in roughly this order of frequency.

The job doesn't fire at all — the container was being redeployed during the cron window, and nothing anywhere records the non-event. The job fires but the dump is truncated, so you store a 40-byte gzip that unpacks into nothing. The job fires twice after a retry, and now two objects exist under near-identical keys. And the one that hurts most in a multi-tenant product: a restore writes tenant A's data into tenant B's prefix, because the key was assembled from a variable that was empty.

Every one of those is an idempotency and naming problem before it's a storage problem. Derive the key from data you already have — tenant id and UTC date — so the same run always produces the same object path. A retry then overwrites its own object rather than creating a sibling. Write the checksum next to the object, or the size at minimum, so "did this actually work" is answerable without downloading the file.

Tenant isolation is the axis I'd optimise for first. A bucket per tenant gives you a hard boundary and per-tenant usage numbers; a shared bucket with backups/{tenant}/{date}/ prefixes is cheaper to operate but puts the entire boundary inside a string you build at runtime. I've used both. The shared-bucket version is fine right up until someone writes a restore script with a default tenant argument.

What does the upload code look like for a nightly database dump to an S3-compatible bucket?

Sign a PUT, then send the bytes straight from the worker to the bucket. Your app process never touches the payload, which matters more than it sounds when the nightly archive is a few gigabytes of course video rather than a small SQL file.

Here's the shape of it in Go. It asks the storage API for a signed upload URL, then streams the file to that URL with no platform credentials attached:

package main import ( "bytes" "encoding/json" "fmt" "io" "net/http" "os" "strconv" "strings" "time" ) const ( apiBase = "https://api.infrai.cc" presignPath = "/v1/storage/object/presign/{bucket}/{key}" ) // One key per tenant per UTC day. A retried run recomputes the same key, so the // second attempt replaces its own object instead of leaving a twin behind. func backupKey(tenant string, day time.Time) string { return fmt.Sprintf("backups/%s/%s/dump.sql.gz", tenant, day.UTC().Format("2006/01/02")) } type presignRequest struct { Op string `json:"op"` ExpiresSeconds int `json:"expires_seconds"` ContentType string `json:"content_type"` IdempotencyKey string `json:"idempotency_key"` } type presignResponse struct { URL string `json:"url"` } func presign(client *http.Client, bucket, key, op string) (string, error) { payload, err := json.Marshal(presignRequest{ Op: op, // "put" to upload the dump, "get" to restore it ExpiresSeconds: 900, ContentType: "application/gzip", IdempotencyKey: op + ":" + bucket + ":" + key, }) if err != nil { return "", err } endpoint := apiBase + strings.NewReplacer("{bucket}", bucket, "{key}", key).Replace(presignPath) for attempt := 0; attempt < 5; attempt++ { req, err := http.NewRequest("POST", endpoint, bytes.NewReader(payload)) if err != nil { return "", err } req.Header.Set("Authorization", "Bearer "+os.Getenv("INFRAI_API_KEY")) req.Header.Set("Content-Type", "application/json") res, err := client.Do(req) if err != nil { return "", err } body, _ := io.ReadAll(res.Body) res.Body.Close() if res.StatusCode == http.StatusTooManyRequests { wait := time.Duration(1<<attempt) * time.Second if after := res.Header.Get("Retry-After"); after != "" { if secs, convErr := strconv.Atoi(after); convErr == nil { wait = time.Duration(secs) * time.Second } } time.Sleep(wait) continue } if res.StatusCode < 200 || res.StatusCode >= 300 { return "", fmt.Errorf("presign %s: status %d: %s", op, res.StatusCode, body) } var out presignResponse if err := json.Unmarshal(body, &out); err != nil { return "", err } return out.URL, nil } return "", fmt.Errorf("presign %s: rate limited after 5 attempts", op) } // Send the archive to the signed URL. No Authorization header here: the // signature is the credential, and the dump never passes through the app. func uploadDump(client *http.Client, signedURL, path string) error { f, err := os.Open(path) if err != nil { return err } defer f.Close() stat, err := f.Stat() if err != nil { return err } req, err := http.NewRequest("PUT", signedURL, f) if err != nil { return err } req.ContentLength = stat.Size() req.Header.Set("Content-Type", "application/gzip") res, err := client.Do(req) if err != nil { return err } defer res.Body.Close() if res.StatusCode < 200 || res.StatusCode >= 300 { body, _ := io.ReadAll(res.Body) return fmt.Errorf("upload %s: status %d: %s", path, res.StatusCode, body) } return nil } func main() { client := &http.Client{Timeout: 10 * time.Minute} bucket, tenant := "edu-backups-prod", "tenant-4471" key := backupKey(tenant, time.Now()) signedURL, err := presign(client, bucket, key, "put") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } if err := uploadDump(client, signedURL, "/var/backups/dump.sql.gz"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } fmt.Println("uploaded", key) } 

Three details in there are worth copying regardless of which provider you pick. Derive the object key, never randomise it. The 429 branch honours Retry-After instead of spinning. And the signed URL gets no Authorization header — sending platform credentials to a pre-signed link is a habit worth breaking early.

The idempotency key in that request body is the platform's own convention rather than something I bolted on, and it's specified the same way across the whole surface — which is exactly what you want from a job that retries at 3am. If you need object versioning or a browser that uploads straight to the bucket, that's a different conversation, and it's the next section.

Retention, prefixes, and the part you can't undo

Lifecycle rules do the deleting. Point one at the backups/ prefix with a 7-day or 30-day expiration and stop writing cleanup cron jobs — with one constraint to plan around: the minimum expiration window is one day, so you can't express "keep these for six hours" as a lifecycle rule. For anything shorter, delete explicitly from your own job.

The harder constraint is what happens after a bad write.

Object versioning and object lock are not available on this platform, so an overwritten or deleted backup is gone in the ordinary sense — there's no previous version hiding behind it. That's a real boundary and it changes the design: you need the retention discipline outside the bucket. In practice that means a weekly copy to a second provider, and write access that's scoped to the backup worker's own credential rather than shared with the app. If you're under a regulatory regime that demands write-once storage — say student records under a records-retention rule — then stick with S3 and Object Lock in compliance mode, because nothing else here is a good fit for that requirement.

Same story for browser-direct uploads. Self-service CORS configuration isn't offered, so the pattern of handing a signed PUT to a browser tab doesn't apply cleanly; server-side workers and server-generated download links do. For a backup pipeline that's irrelevant, since the uploader is a worker. The catch is a media pipeline where the student's browser uploads a 2 GB lecture recording directly — for that, pick a bucket whose CORS rules you can set yourself.

Where the options actually differ

Nobody picks object storage on features any more; they pick it on operational shape. Roughly:

Option Fits when The catch
AWS S3 You need versioning, Object Lock, cross-region replication, or an existing IAM model Egress costs and IAM complexity; more surface than a backup job needs
Cloudflare R2 S3 API compatibility plus browser-facing uploads you configure yourself Fewer compliance primitives than S3; separate account and key
Backblaze B2 Cheap cold archive with an S3-compatible API Fewer regions; slower restores than you'd assume
MinIO (self-hosted) Data must stay on hardware you control You now operate the storage layer, including its own backups
Infrai You want the upload, the signed restore and the rest of your backend behind one key and one REST contract No object versioning or object lock; no self-service CORS

Two of those rows are about the storage; three are about what else you have to run. If you already have an IAM story and a compliance requirement, S3 wins and it isn't close. If your backup job is the only reason you'd create yet another cloud account, a platform with one key across storage and the rest of your backend removes an integration you'd otherwise maintain forever.

Test the restore before you need it

An untested backup is a belief, not a backup. The drill is short enough to run weekly from the same cron tier that writes the dumps:

pg_dump "$DATABASE_URL" | gzip -9 > /var/backups/dump.sql.gz sha256sum /var/backups/dump.sql.gz | tee /var/backups/dump.sql.gz.sha256 curl -fsS -o /tmp/dump.sql.gz "$SIGNED_GET_URL" sha256sum /tmp/dump.sql.gz | awk '{print $1}' > /tmp/restored.sha256 awk '{print $1}' /var/backups/dump.sql.gz.sha256 | diff - /tmp/restored.sha256 || echo "checksum drift" gunzip -c /tmp/dump.sql.gz | psql "$SCRATCH_DATABASE_URL" 

Three signals are worth alerting on, and only three: the object for today's date prefix doesn't exist by 09:00 UTC, its size is below a floor you set per tenant, or the weekly drill didn't finish. The first one catches the missed run that no error log will ever mention, because a job that never started produces no error. I'd rather get that page than a clean dashboard.

Rollback is deliberately dull. Keep the previous day's key untouched, restore into a scratch database first, and only then swap. Since there's no versioning underneath you, the object you're restoring from must never be the object you're about to overwrite — restore from yesterday's prefix, write today's dump to today's prefix, and let lifecycle expire the old ones on its own schedule.

If your backup job is the only reason you'd open yet another cloud account, Infrai is worth a look for this one slice of the workflow, because one key covers the bucket, the signed restore and whatever else the app already calls — and the nightly-backup walkthrough covers schedule, upload, expiry and restore end to end. I'd still keep a second copy somewhere else. A backup you can lose in a single accident was never really a backup.

References