What happens when you delete an object in an S3 bucket that has versioning enabled?
S3 does not remove the data. It adds a delete marker as the newest version, so normal reads return 404, but older versions remain and can be restored by removing the marker or fetching a version ID.
Explain it simply
Versioning is like the history in Google Docs. When you delete the document, it only disappears from your list; the earlier versions still sit in the history. S3 hides the object by placing a "deleted" sticker on top instead of shredding it.
Example
Bucket with versioning ON, key: notes.txt
PUT notes.txt -> version v1
PUT notes.txt -> version v2 (current)
DELETE notes.txt -> adds delete marker (current)
GET notes.txt -> 404 (current version is a marker)
GET notes.txt?versionId=v2 -> returns v2
Delete the marker -> v2 becomes current again
DELETE notes.txt?versionId=v1 -> v1 permanently removedKey facts: versioning once enabled can only be suspended, never fully turned off. Every version is stored and billed, so combine versioning with a lifecycle rule that expires old noncurrent versions. Adding MFA Delete requires an MFA code to permanently delete a version.
Versioning protects against accidental deletes and overwrites, and it is a prerequisite for cross-Region replication.
What to say in the interview
"With versioning on, a plain delete just adds a delete marker and older versions stay. Removing the marker restores the object, and deleting a specific version ID is the only permanent delete. I add a lifecycle rule to clean up old noncurrent versions so cost does not grow forever."
Common mistakes
- Assuming a versioned bucket stops charging for deleted objects.