This repository provides a set of demos that demonstrates how to migrate a relational database for a simple ecommerce application to a distributed, NoSQL database like Azure Cosmos DB, designed to scale out as the number of users grow.
This repo contains a Powerpoint presentation that walks through the data modeling concepts demonstrated by the sample application. You can watch the presentation from Igloo Conf 2022 to get an idea of how these concepts apply to modeling data for this type of database.
The main components of this sample include:
-
Program.cs: A console application. The menu items coincide with demos for the presentation that highlight the evolution of the data models from a normalized relational data model (v1) to a fully denormalized NoSQL data model (v4).
-
ChangeFeed.cs: The class implements Cosmos DB's change feed processor to monitor the product categories container for changes and then propagates those to the products container. This highlights how to maintain referential integrity between entities.
-
Models.cs: This project contains all of the data models (and versions) for the entities.
-
CosmosManagement.cs: This class contains the Cosmos DB management .NET SDK classes used to delete and recreate the databases and containers. This class doesn't provide any data modeling concepts but is provided to allow users to delete the Cosmos resources when not in use and recreate them when needed.
Choose one of these options to get started:
- Run in VS Code Dev Containers - Consistent dev environment using containers
- Run locally - Traditional local development experience
No matter which method you choose, you will need to Deploy to Azure (AZD) to create the Azure Cosmos DB account and resources, as well as create an appsettings.development.json file necessary to run this sample.
Prerequisites
- Install Visual Studio Code
- Install the Dev Containers extension
- Install Docker:
- Windows/macOS: Docker Desktop
- Linux: Docker Engine + Docker CLI (ensure your user can run
docker)
Steps
-
Click the Open in VS Code Dev Containers badge at the top of this README
-
Wait for the dev container to build and start (this may take a few minutes the first time)
-
Deploy to Azure using Deploy to Azure (AZD)
-
Once deployed, open the integrated terminal and run:
cd src dotnet run -
On the main menu, press 'k' to load data
-
Explore the different functions by pressing the corresponding menu keys
-
Open the Cosmos DB Data Modeling Deck
-
Follow the slides to learn the concepts
-
For each of the demo slides, refer to the speaker notes
Prerequisites
- Visual Studio Code (or another IDE/editor)
- .NET 9 SDK
- Azure Developer CLI (AZD)
- An Azure subscription with permission to create resources
Steps
-
Clone the repository
git clone https://github.com/AzureCosmosDB/CosmicWorks.git -
Deploy to Azure using Deploy to Azure (AZD)
-
Run the application:
cd src dotnet run -
On the main menu, press 'k' to load data
-
Open the Cosmos DB Data Modeling Deck
-
Follow the slides to learn the concepts.
-
For each of the Demo slides, refer to the Speaker notes.
-
Execute the demos by pressing the corresponding menu keys in the app.
This option deploys a serverless Cosmos DB account with all required databases and containers, and sets up RBAC permissions for both a managed identity and the current user.
The deployment will automatically:
- Create a serverless Cosmos DB account
- Set up RBAC permissions
- Create an
appsettings.development.jsonfile in the src folder - Configure everything needed to run the application
Run these commands once per environment (and any time you need to reprovision):
az login
azd auth login
azd upImportant
This solution doesn't charge for RU when not in use but there are data storage costs of $0.25 USD per container per month for a total of about $5.50 USD. To keep costs minimal, from the main menu of the application, select option 'L' to delete all the databases. When you return, recreate these with option 'M', then reload the data with option 'K'.
The data used in this sample represents 4 versions of our data model as it progresses through the migration from a normalized relational database to a partitioned NoSQL database which scales easily as the number of users increases. It can be enlightening to see this progression by looking at how the data model changes below through successive versions: