Azure
Categories:
3 minute read
Create an Azure CosmosDB resource
INFO
Azure Cosmos DB provides several data models, including Document, Key-Value, Graph, and Column-Family. Each data model is designed for specific use cases, and the choice of data model depends on the nature of the data and the application’s requirements.I’m using Cosmos DB for NoSQL API
to store the visitor counter value because it’s easy to set up and use, provides low-latency access to data, and integrates well with other Azure services, like Azure Functions, which I can use to run the Python API that interacts with the JavaScript frontend and this CosmosDB backend.
For the Account Name
you need to choose something that is unique. The name will be prepended to documents.azure.com to create the URI.
Using provisioned throughput model
for the Capacity Mode
allows me to take advantage of the free pricing tier, which is perfect for this size of the project, basically a demonstration.
Remember to check the Free Tier Discount
option.
If this system required it, I could take advantage of the global distribution
options to send the data to globally disparate endpoints, allowing clients to connect automatically to their nearest copy of the data. This is not needed, but cool to know it exists.
For Networking
, I’ll allow all networks and leave the TLS at 1.2 which is the current latest.
As this is a managed service, it comes with Backups
, and it cannot be turned off. To keep it simple, I’ll set the backup policy to the lowest values of one backup every 24 hours
, 2 day retention
, and with LRS
for the backup copies storage.
I don’t need to complicate things with customer-managed keys for encryption
, so I will use Microsoft managed (service managed key).
Create the Database and a Container
INFO
A container is a unit of scalability in Azure Cosmos DB. It holds items (documents) that share the same partition key. We need a container to store the visitor counter data, which will be represented as a JSON document. Containers also help manage and query data efficiently.When the CosmosDB resource has been created, open it. From the you can use the Data Explorer
setting to work with the containers. We need to create a new container as follows:
Resource | Description | Value |
---|---|---|
Database ID | A database is analogous to a namespace. It is the unit of management for a set of containers. | VisitorCounter |
Container ID | Unique identifier for the container and used for id-based routing through REST and all SDKs. A container in Azure Cosmos DB is a schema-agnostic container for data items. It’s somewhat similar to a table in a relational database, but without a fixed schema. Each container is associated with a partition key and an optional set of indexing policies. | Count |
Partition Key | The partition key is used to automatically distribute data across partitions for scalability. Choose a property in your JSON document that has a wide range of values and evenly distributes request volume. For small read-heavy workloads or write-heavy workloads of any size, id is often a good choice. | /id |