How-to

Use Azure Blob for swarm storage

Applies to: .NET SDK Last updated: 2026-06-11

Pattern

Implement IQuorumStorage with the Azure SDK. TryCreateNewAsync must use UploadAsync with IfNoneMatch: "*" access conditions for atomic create:

public sealed class AzureBlobQuorumStorage : IQuorumStorage
{
    private readonly BlobContainerClient _container;

    public async Task<bool> TryCreateNewAsync(string path, byte[] data)
    {
        var blob = _container.GetBlobClient(path);
        try
        {
            await blob.UploadAsync(new MemoryStream(data),
                new BlobUploadOptions {
                    Conditions = new BlobRequestConditions { IfNoneMatch = ETag.All }
                });
            return true;
        }
        catch (RequestFailedException ex) when (ex.Status == 409)
        {
            return false;
        }
    }
}

See also