Following our recent changes, which made SOS strongly consistent allowing true read-after-write operations to be executed, we keep on following AWS pace by adding support for conditional writes. Adding this feature to Exoscale SOS only 2 months after it was announced by AWS is key for S3 compatibility. In this article we’ll explore the use cases that the conditional writes feature addresses.
About Object Storage
Object Storage is a widely used technology which allows storing virtually unlimited amounts of unstructured data. It is horizontally scalable by design, making it a great choice for use-cases like machine learning, where large datasets need to be stored and made highly available. It is also heavily used to store media content including images, sound files, videos, and backups.
Each piece of data is stored as an object, defined by a unique identifier (its path in the Object Storage bucket) and some associated metadata. An Object Store has a flat storage structure, objects are all at the same level in a Bucket, and not organized in folders like regular filesystems.
The main advantages of Object Store are:
- scalability: it is designed to store large amounts of data
- cost: it is usually much cheaper than traditional block storage
- redundancy: objects are duplicated ensuring resilience and fault tolerance
- accessibility: objects are accessed through APIs (HTTP based REST APIs, AWS S3 API, …)
The problem
By default, Object Store does not prevent race conditions when several clients try to create the same object concurrently. For example, Client 1 and Client 2 might both create an object at dataset/user_data_2024.txt issuing PUT requests at the same time as illustrated below.
While Client 1 assumes the object contains its data, the actual content of the object was overwritten by the data from Client 2. This is even more likely to occur when Client 1 uses a PUT request and Client 2 uses a Multipart-Upload operation to create the same object at dataset/user_data_2024.txt
As in the previous example, Client 1 assumes the object contains its data, while it actually contains data from Client 2. With Multipart-Upload, the object creation happens in several steps, which increases the window for a potential race condition.
To prevent race conditions, which can lead to data inconsistency and corruption, mechanisms like object locking or other synchronization methods are often used. However, these approaches often rely on external code and introduce an additional layer of orchestration.
Conditional writes
Conditional writes offers a simpler solution. It acts as a verification step, preventing accidental overwrites in concurrent write scenarios like the ones we detailed before. It is managed directly by the Object Store, removing the need for an external synchronization mechanism. This feature is now available in Exoscale SOS.
With conditional writes, if Client 1 and Client 2 use PUT operation at the same time to create an object at dataset/user_data_2024.txt, only the request from Client 1 will result in a success. Client 2 will receive a 412 HTTP status code preventing its object to be created.
Under the hood, the creation request uses the if-none-match HTTP header. In the current implementation, this header only supports ‘*’ as a value. It cannot be used to provide an ETag (the hash of an existing object) thus only allows the creation of an object if none exists at the specified path.
A similar behavior occurs when Client 1 uses PUT method and Client 2 uses the Multipart-Upload.
In this case the header is checked in the completion step, which is the last step of the Multipart-Upload process.
With conditional writes there is no more risk that the object created by Client 1 is overwritten with the one created by Client 2. On the other side Client 2 directly knows the object cannot be created as it already exists.
Summary
Conditional writes is a key feature now available in Exoscale SOS as it removes the need to manage an external synchronization process for handling the race conditions. You can get started using Exoscale SOS now by sign-in or register on Exoscale.