Versioning & Lifecycle
Undoing overwrites and deletes, rollback, and rules that expire data
Replication protects against hardware losing data. It does nothing against people and programs losing data: a bad deploy that overwrites every config file, a cleanup script with the wrong prefix, a stolen key. Every copy faithfully replicates the mistake. Versioning is the protection against that.
Versioning
With versioning enabled on a bucket, an overwrite keeps the old bytes as a non-current version, and a DELETE doesn't delete anything: it adds a delete marker on top.
docker compose -f compose_prod.yaml run --rm labs python versioning.py
versioning: Enabled
after overwrite: [('6722363a', 'latest'), ('6722363a', 'old')]
after DELETE: 2 versions still stored, 1 delete marker
plain GET: NoSuchKey
undeleted, GET: b'{"v": 2}'
rolled back, GET: b'{"v": 1}' (3 versions now)
lifecycle rule: tmp-1d {'Expiration': {'Days': 1}, 'Filter': {'Prefix': 'tmp/'}}
lifecycle rule: old-versions-7d {'Filter': {'Prefix': ''}, 'NoncurrentVersionExpiration': {'NoncurrentDays': 7}}list_object_versionslists everything, newest first.- A DELETE with a
VersionIdreally deletes that version. That's the operation to restrict: whoever can do it can destroy history. - Versioning can be suspended but never turned off again for a bucket.
The version ids in the output share their first 8 characters: they're
time-based, and these were written within the same second. Sorting
versions by LastModified didn't reliably find the oldest one, because
the timestamps were equal. The listing order (newest first) is the
reliable order.
Lifecycle rules
Without limits, a versioned bucket grows forever: every overwrite keeps the old copy. Lifecycle rules decide how long things are kept:
Rules run in the background, with day granularity, so the lab can only
show that they're stored. Prefix design matters again here:
tmp/, exports/2026/10/ and tenant/42/ can each get their own rule;
random keys can't.
TTL, the SeaweedFS way
SeaweedFS also has a native TTL per path, set in the filer configuration:
> fs.configure -locationPrefix=/buckets/app-data/tmp/ -ttl=1d -applyObjects under that path go to volumes created with that TTL, and when the whole volume expires, it's dropped in one operation instead of deleting objects one by one. That makes it very cheap for high-volume, short-lived data (thumbnails, caches, session uploads).
Lab
- Run
versioning.py, thenaws s3api list-object-versions --bucket versioned. - Delete
config.jsonwith its current version id. Can you undo that? - Overwrite one key 1,000 times in a versioned bucket and compare the bucket's size on the dashboard with an unversioned one.