- Published on
Introduction to Azure Table Storage
Table of Contents
- What is Azure Table Storage?
- When to use Azure Table Storage?
- What kind of a NoSQL Store is Azure Table Storage?
- Azure Table Storage vs Cosmos DB
- Azure Table Storage Concepts
- Account
- Table
- Entity
- Property
- System Properties of an Entity
- Role of Partition Key and Row Key
- Creating a Table
- Adding an Entity
- Azure Table Storage Limits
- What's Next
- FAQs
- How much data can be stored in a single table storage account?
- What are the elements of an Azure Table Storage key?
What is Azure Table Storage?
Azure Table Storage is a cloud based NoSQL datastore that stores non-relational data in a structured format (tables and columns).
It's a key-value store and offers schemaless data model, which helps us quickly adapt our data as our application evolves.
In terms of cost-efficiency, it is an cost-effective solution, as it costs way lower than traditional SQL databases for storing same volume of data.
It's a part of Azure Storage, so if we have a storage account then we can use Azure Table Storage.
If you are looking to integrate Azure Table Storage in your C#/.NET application then refer Getting Started with Azure Table Storage.
When to use Azure Table Storage?
Table storage could be used when:
- We don't require any relational features such as joins, foreign keys, etc.
- We need to query data using a clustered index (i.e.
PartitionKey
andRowKey
). - Data can be denormalized.
Since it is a NoSQL datastore, it doesn't support any relational feature and being a key-value store, it provides quick access to items using the keys, otherwise it performs a table scan. Also, since it stores data in structured format (tables and columns), we need to denormalize or serialize nested data before saving.
What kind of a NoSQL Store is Azure Table Storage?
A NoSQL datastore or database, stores data differently than relational databases. The term "NoSQL" originally referred to "non-SQL" or "non-relational", but it is now called as "Not only SQL" to emphasize database's support SQL-like query languages.
A NoSQL datastore is categorized by the data model it uses. The main types of NoSQL datastores are:
- Key-value
- Object database
- Document store
- Wide-column store
- Graph database
Now, returning to Azure Table Storage, it is a key-value datastore.
Azure Table Storage vs Cosmos DB
If I had to choose between Azure Table Storage and Cosmos DB, I would select Cosmos DB for scenarios requiring high throughput and low latency, such as when developing a public-facing application. However, if that was not the case, I could then consider Azure Table Storage due to its relatively lower price.
The table below presents some notable distinctions between Azure Table Storage and Cosmos DB.
Feature | Azure Table Storage | Cosmos DB |
---|---|---|
Throughput | Upper limit of maximum 20,000 operations per second. | No upper limit on throughput and can scale upto 10 million operations per second. |
Latency | No upper bound. | Offers single-digit millisecond latency for reads and writes. |
Indexing | Only primary index on PartitionKey and RowKey . No secondary indexes. | Automatic indexing on all properties. |
Distribution | Single region with one optional secondary read region. | Supports global distribution from one to 30+ regions. |
Consistency | Strong in primary region and eventual in secondary region. | Supports 5 consistency levels to choose from. |
Azure Table Storage Concepts
Table storage contains the following components:
Account
All tables are created under an Azure Storage account.
Table
Inside a storage account, we can create multiple tables. Tables in Azure Storage are schema-less which means we can even store entities with completely different properties in same the table.
Entity
An entity is an object which is stored inside the table. It contains a set of properties and two properties (PartitionKey
and RowKey
) act as the clustered index. The size of an entity can be upto 1 MB only.
Property
Property is name-value pair. Each entity can have upto 252 user-defined properties.
System Properties of an Entity
Each entity also has four system properties - PartitionKey
, RowKey
, Timestamp
and Etag
. PartitionKey
and RowKey
form the clustered index. Timestamp
is managed by the Storage itself and is used to keep the track when an entity was last updated. Etag
is a concurrency token and is used when we are updating an Entity.
Role of Partition Key and Row Key
Tables in Azure Table Storage are partitioned and stored on different nodes for performance and scalability. Each node can have one or more partitions stored in it. A partition is a collection of entities that share the same partition key. And row key is the unique identifier of an entity within a given partition.
So, in order to target an entity, we have to specify both it's partition key and row key. Both keys combined act as the clustered index for an entity.
To achieve good performance carefully choose your PartitionKey
, so that you have more partitions and traffic is evenly distributed among different nodes.
Creating a Table
- Open Azure Portal and go to storage account.
- On the sidebar, under the Data storage section, click on Tables. This is where we will see the list of all the tables created inside table storage. Initially, it will be empty.
- Now, to create a new table, click + Table button and enter the table name. This will create a new table.
Adding an Entity
- On the sidebar, click on the Storage browser, select Tables, and select the table we just created.
- To add an entity click on the + Add entity button.
After adding the properties click Insert and this will add the new entity into the table. As you might have noticed, both, PartitionKey
and RowKey
are required. Also, Timestamp
property will be added automatically after insertion.
Azure Table Storage Limits
Below are some of the limitations that one should keep in mind when working with Azure Table Storage.
Limit Type | Target |
---|---|
Number of Tables | Limited by the storage account's capacity. |
Size of a Table | 500 TiB (549.755813888 TB) |
Size of an Entity | 1 MiB (1.04858 MB) |
Number of user-defined properties in an Entity | 252 |
Size of Partition Key | 1 KiB (1.024 KB) |
Size of Row Key | 1 KiB (1.024 KB) |
What's Next
Refer Getting Started with Azure Table Storage in .NET to learn integration and performing basic operations on Azure Table Storage in a C# application.
Learn Design Patterns for Query Optimization when working with Azure Table Storage.
FAQs
How much data can be stored in a single table storage account?
You can create any number of tables and store any number of entities upto the limit of the storage account.
What are the elements of an Azure Table Storage key?
Both PartitionKey
and RowKey
together form the unique key in Azure Table Storage.