Skip to content

Azure Storage grain persistence

The Azure Storage grain persistence provider supports both Azure Blob Storage and Azure Table Storage.

Applies to: Orleans 7.0, Orleans 8.0, Orleans 9.0, Orleans 10.0

Install the Microsoft.Orleans.Persistence.AzureStorage package from NuGet. The Azure Table Storage provider stores state in a table row, splitting the state across multiple columns if it exceeds the limits of a single column. Each row can hold a maximum of 1 megabyte, as imposed by Azure Table Storage.

Configure the Azure Table Storage grain persistence provider using the AzureTableSiloBuilderExtensions.AddAzureTableGrainStorage extension method.

Using a TokenCredential with a service URI is the recommended approach. This pattern avoids storing secrets in configuration and leverages Microsoft Entra ID for secure authentication.

DefaultAzureCredential provides a credential chain that works seamlessly across local development and production environments. During development, it uses your Azure CLI or Visual Studio credentials. In production on Azure, it automatically uses the managed identity assigned to your resource.

using Azure.Identity;
siloBuilder.AddAzureTableGrainStorage(
name: "profileStore",
configureOptions: options =>
{
options.ConfigureTableServiceClient(
new Uri("https://<your-storage-account>.table.core.windows.net"),
new DefaultAzureCredential());
});
siloBuilder.AddAzureTableGrainStorage(
name: "profileStore",
configureOptions: options =>
{
options.ConfigureTableServiceClient(
"DefaultEndpointsProtocol=https;AccountName=data1;AccountKey=SOMETHING1");
});

The Azure Blob Storage provider stores state in a blob.

Configure the Azure Blob Storage grain persistence provider using the AzureBlobSiloBuilderExtensions.AddAzureBlobGrainStorage extension method.

using Azure.Identity;
siloBuilder.AddAzureBlobGrainStorage(
name: "profileStore",
configureOptions: options =>
{
options.ConfigureBlobServiceClient(
new Uri("https://<your-storage-account>.blob.core.windows.net"),
new DefaultAzureCredential());
});
siloBuilder.AddAzureBlobGrainStorage(
name: "profileStore",
configureOptions: options =>
{
options.ConfigureBlobServiceClient(
"DefaultEndpointsProtocol=https;AccountName=data1;AccountKey=SOMETHING1");
});

Applies to: Orleans 8.0, Orleans 9.0, Orleans 10.0

Aspire simplifies Azure Storage grain persistence configuration by managing resource provisioning and connection automatically.

AppHost project (Program.cs):

var builder = DistributedApplication.CreateBuilder(args);
var storage = builder.AddAzureStorage("storage");
var blobs = storage.AddBlobs("grainstate");
var orleans = builder.AddOrleans("cluster")
.WithClustering(builder.AddRedis("redis"))
.WithGrainStorage("Default", blobs);
builder.AddProject<Projects.MySilo>("silo")
.WithReference(orleans)
.WithReference(blobs);
builder.Build().Run();

Silo project (Program.cs):

var builder = Host.CreateApplicationBuilder(args);
builder.AddServiceDefaults();
builder.AddKeyedAzureBlobServiceClient("grainstate");
builder.UseOrleans();
builder.Build().Run();

AppHost project (Program.cs):

var builder = DistributedApplication.CreateBuilder(args);
var storage = builder.AddAzureStorage("storage");
var tables = storage.AddTables("grainstate");
var orleans = builder.AddOrleans("cluster")
.WithClustering(builder.AddRedis("redis"))
.WithGrainStorage("Default", tables);
builder.AddProject<Projects.MySilo>("silo")
.WithReference(orleans)
.WithReference(tables);
builder.Build().Run();

Silo project (Program.cs):

var builder = Host.CreateApplicationBuilder(args);
builder.AddServiceDefaults();
builder.AddKeyedAzureTableServiceClient("grainstate");
builder.UseOrleans();
builder.Build().Run();

For comprehensive documentation on Orleans and Aspire integration, see Orleans and Aspire integration.

Applies to: Orleans 3.x

Install the Microsoft.Orleans.Persistence.AzureStorage package from NuGet. The Azure Table Storage provider stores state in a table row, splitting the state across multiple columns if it exceeds the limits of a single column. Each row can hold a maximum of 1 megabyte, as imposed by Azure Table Storage.

Configure the Azure Table Storage grain persistence provider using the AzureTableSiloBuilderExtensions.AddAzureTableGrainStorage extension method.

siloBuilder.AddAzureTableGrainStorage(
name: "profileStore",
configureOptions: options =>
{
options.ConnectionString =
"DefaultEndpointsProtocol=https;AccountName=data1;AccountKey=SOMETHING1";
});

The Azure Blob Storage provider stores state in a blob.

Configure the Azure Blob Storage grain persistence provider using the AzureBlobSiloBuilderExtensions.AddAzureBlobGrainStorage extension method.

siloBuilder.AddAzureBlobGrainStorage(
name: "profileStore",
configureOptions: options =>
{
options.ConnectionString =
"DefaultEndpointsProtocol=https;AccountName=data1;AccountKey=SOMETHING1";
});