Learn Labs
Data Lifecycle

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}}
after overwritev1oldv2latestafter DELETEv1oldv2old✗markerGET → NoSuchKeymarker removedv1oldv2latestundeletedv1 re-PUTv1oldv2oldv3= v1rolled back
c.put_bucket_versioning(Bucket=B, VersioningConfiguration={"Status": "Enabled"})c.delete_object(Bucket=B, Key="config.json")adds a delete markerc.get_object(Bucket=B, Key="config.json")NoSuchKeyundelete: delete the marker itself, by its version idc.delete_object(Bucket=B, Key="config.json", VersionId=marker_id)roll back: read an old version, PUT it as the new latestold = c.get_object(Bucket=B, Key="config.json", VersionId=v1_id)["Body"].read()c.put_object(Bucket=B, Key="config.json", Body=old)
  • list_object_versions lists everything, newest first.
  • A DELETE with a VersionId really 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.

Lifecycle rules

Without limits, a versioned bucket grows forever: every overwrite keeps the old copy. Lifecycle rules decide how long things are kept:

{"Rules": [{"ID": "tmp-1d", "Status": "Enabled","Filter": {"Prefix": "tmp/"},"Expiration": {"Days": 1}},current objects under tmp/{"ID": "old-versions-7d", "Status": "Enabled","Filter": {"Prefix": ""},"NoncurrentVersionExpiration": {"NoncurrentDays": 7}},old versions, everywhere{"ID": "abort-multipart", "Status": "Enabled","Filter": {"Prefix": ""},"AbortIncompleteMultipartUpload": {"DaysAfterInitiation": 3}}]}

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 -apply

Objects 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

  1. Run versioning.py, then aws s3api list-object-versions --bucket versioned.
  2. Delete config.json with its current version id. Can you undo that?
  3. Overwrite one key 1,000 times in a versioned bucket and compare the bucket's size on the dashboard with an unversioned one.

On this page