Azure

Create a database to store the visitor counter data using Azure CosmosDB
Azure

Create an Azure CosmosDB resource

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.

Azure CosmosDB Free Tier

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

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:

ResourceDescriptionValue
Database IDA database is analogous to a namespace. It is the unit of management for a set of containers.VisitorCounter
Container IDUnique 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 KeyThe 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
Last modified July 21, 2024: update (e2ae86c)