Amazon S3 provides strong read-after-write consistency for all objects, including overwrite PUTS and DELETES. This means that when you write an object or overwrite an existing object, subsequent reads of that object will immediately reflect the latest changes.
Here’s a more detailed look at S3 Read-Write Consistency:
1. Read-After-Write Consistency
- What it means: After a successful write operation (such as a PUT or POST) to Amazon S3, any subsequent read request (such as a GET or LIST) on the object will immediately return the most recent version of the object.
- For PUT Operations: When you upload an object or overwrite an existing object, the data becomes immediately available for reading. If you perform a read right after the write, it will reflect the changes.
- For DELETE Operations: When you delete an object, subsequent requests to get that object will immediately return a 404 Not Found (or equivalent error), ensuring that the object has been deleted.
2. S3 Consistency Model
Historically, Amazon S3 provided eventual consistency for overwrite PUT and DELETE operations, meaning that it might take a few seconds before changes were fully visible to all reads. However, since December 2020, S3 now provides strong consistency for both PUTS (including overwrites) and DELETES, ensuring that changes are immediately visible to all clients.
Key Points:
- Strong Consistency: S3 provides strong consistency for both PUT and DELETE operations. When you upload or delete an object, all subsequent read requests will reflect the changes immediately.
- Atomicity: S3 handles all writes as atomic operations. If you’re uploading a file, the file is either completely written or not at all, ensuring there’s no partial file data available for reading.
Example Use Cases for Read-Write Consistency:
- File Uploads: After uploading a file (PUT), if you immediately read (GET) the same file, you will get the exact file you just uploaded.
- File Deletions: If you delete a file (DELETE), any subsequent GET requests will return a 404 Not Found, ensuring the file has been deleted.
- Object Overwrites: If you overwrite an existing object with a new one (PUT), any subsequent GET requests will immediately reflect the new object.
Performance and Reliability:
- No impact on performance: The read-after-write consistency is designed to ensure that S3 operations are highly performant while ensuring data consistency at the same time.
- Highly available: S3 is designed for high durability and availability, ensuring that the object you just uploaded or deleted is consistently reflected across the S3 system.
3. S3 Eventual Consistency
Even though S3 provides strong consistency for PUT and DELETE operations, there are still edge cases where eventual consistency may apply. For example:
- List Operations (LIST requests): When listing objects in a bucket, it is possible to encounter eventual consistency. New objects added or deleted may not immediately appear in a
LIST
operation across all regions. However, this inconsistency is temporary and will resolve quickly.
4. How Consistency Affects Your Application:
- If you rely on immediate visibility of new data, such as user uploads or recently deleted files, S3’s read-after-write consistency ensures that your application will always read the latest data immediately after writing or deleting it.
- If you are performing bulk listing operations (such as a large number of
LIST
requests), the results may not immediately reflect changes in a newly written or deleted object, but this will resolve quickly due to S3’s eventual consistency model in list operations.
In Summary:
- Read-after-write consistency for PUT, POST, and DELETE operations means changes you make are immediately visible.
- S3 provides strong consistency by default for all write and delete operations.
- Eventual consistency can still apply to list operations, where the results of a
LIST
may not immediately reflect recent changes to objects in the bucket.
This change to strong consistency makes it easier to build applications that rely on immediate visibility of updates, such as file uploads, deletions, and updates, without needing to worry about temporary inconsistencies.