Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does aws s3 handle overwriting a file and access?

So I'm new to amazon s3 and was wondering if somebody could help answer this questions.

I have a set of static API / JSON files that are used to power a mobile app, while the JSON data for the most part is static an update can be triggerd at any time, causing the data to be updated and the JSON file as such updated as well.

My questions is, how does amazon handle file updates in regards to access, what I mean by that is if a person is accessing the file at the time I wish to write will it be blocked or does amazon employee some file cache to prevent this from happening.

Thanks!

like image 912
proxim0 Avatar asked Jan 03 '17 16:01

proxim0


2 Answers

You won't be blocked but you can get stale data if the object already exists and has been recently replaced or deleted.

S3 provides read-after-write consistency for PUTS of new objects.

S3 provides eventual consistency for overwrite PUTS and DELETES. What this means is that user2 could get a stale version of the JSON even though user1 replaced it (sub-second).

like image 99
Dave Maple Avatar answered Sep 30 '22 02:09

Dave Maple


You cannot actually update objects in S3. All you can do is store, retrieve, and delete an entire object. To 'update' the contents of an object, you replace the entire object.

If client A uploads a replacement object and, before that upload is acknowledged, client B accesses the same object key then client B will get the original object.

Here is a supporting quote from the Amazon S3 data consistency model:

Updates to a single key are atomic. For example, if you make a PUT request to an existing key from one thread and perform a GET request on the same key from a second thread concurrently, you will get either the old data or the new data, but never partial or corrupt data.

As of 2020-12-13, S3 now offers strong consistency:

After a successful write of a new object, or an overwrite or delete of an existing object, any subsequent read request immediately receives the latest version of the object. S3 also provides strong consistency for list operations, so after a write, you can immediately perform a listing of the objects in a bucket with any changes reflected.

like image 36
jarmod Avatar answered Sep 30 '22 01:09

jarmod