This blog post talks about the use of Table API in Cosmos DB for a key-value data model.
The Table API emulates Azure Table Storage which is one of the storage services that came up with Azure in 2010. It came in with the Windows Azure which we now know as Microsoft Azure. It is a no SQL non-relational database where we model our data as key-value pairs.
But wait, what is Key-value Data Model?
Key-value Data Model
A data model which simply stores the items as pairs of keys and values by setting a unique key for an item and retrieving its value using that key. To understand it in terms of the Azure Table Data Storage, the key is made up of actually two different keys. What are those?
Key = Partition Key + Row Key
So basically, every key is a unique combination of a partition key and row key which later gets the value that is associated with this key from the table. This is similar to how documents in a collection are a unique combination of the partition key and ID properties. Another important thing to notice here is that unlike relational databases, we can store items of different types in the same table.
The core usage of Table API is the seamless migration of back-end to the service. But there are some of the limitations that Azure Table Storage suffers from, which Cosmos DB helps with.
- Throughput which is totally unpredictable in Azure Table storage is provisioned in Cosmos DB depending on the number of Request Units (RUs).
- We can geo replicate our tables in Cosmos DB when we have to globally distribute our documents.
- We have automatic indexing in Cosmos DB which has a default indexing strategy automatically indexing every value in the table.
Why use the Table API?
We have several APIs to choose from when working with Cosmos DB since it is a multi-model database. We can also switch from one API to another over the same data because everything is placed over the ARS storage.
The primary usage of Table API is when you want to migrate your data from the Azure Table Storage to Cosmos DB Table API. We really do not need to change any code in our applications.
Just changing the connection string works to migrate your data from Azure Table data storage to Cosmos DB, however, it still uses the Azure Table Data Storage SDK so it is better to upgrade it to the Cosmos DB SDK.