Skip to content

Commit

Permalink
Merge pull request #28 from markjbrown/main
Browse files Browse the repository at this point in the history
Refresh all
  • Loading branch information
markjbrown authored Jul 18, 2024
2 parents f749672 + ba7f29d commit 25646ff
Show file tree
Hide file tree
Showing 108 changed files with 1,319 additions and 3,125 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/data-binning/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
"workspaceFolder": "/workspace/data-binning/source/",
"postAttachCommand": "dotnet build Cosmos_Patterns_Bucketing.csproj",
"postAttachCommand": "dotnet build DataBinning.csproj",
"customizations": {
"codespaces": {
"openFiles": [
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/distributed-counter/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
"workspaceFolder": "/workspace/distributed-counter/source/",
"postAttachCommand": "dotnet build Cosmos_Patterns_DistributedCounter.sln",
"postAttachCommand": "dotnet build DistributedCounter.sln",
"customizations": {
"codespaces": {
"openFiles": [
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/distributed-lock/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
"workspaceFolder": "/workspace/distributed-lock/source/",
"postAttachCommand": "dotnet build consoleapp/Cosmos_Patterns_GlobalLock.sln",
"postAttachCommand": "dotnet build GlobalLock.csproj",
"customizations": {
"codespaces": {
"openFiles": [
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/event-sourcing/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
"workspaceFolder": "/workspace/event-sourcing/source/",
"postAttachCommand": "dotnet build Cosmos_Patterns_EventSourcing.csproj",
"postAttachCommand": "dotnet build EventSourcing.csproj",
"customizations": {
"codespaces": {
"openFiles": [
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/preallocation/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
"workspaceFolder": "/workspace/preallocation/source/",
"postAttachCommand": "dotnet build Cosmos_Patterns_Preallocation.csproj",
"postAttachCommand": "dotnet build Preallocation.csproj",
"customizations": {
"codespaces": {
"openFiles": [
Expand Down
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
appsettings.development.json
appsettings.production.json
appsettings.*.json
local.settings.json

# User-specific files
*.rsuser
Expand Down Expand Up @@ -356,7 +357,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/distributed-lock/source/consoleapp/appsettings.development.json
/distributed-counter/source/Visualizer/appsettings.Development.json
/distributed-counter/source/ConsumerApp/appsettings.Development.json
/data-binning/source/appsettings.development.json

/document-versioning/source/website/appsettings.Development.json
/schema-versioning/source/website/appsettings.Development.json
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,14 @@ Design patterns play a crucial role in building robust applications and modeling
### Key Benefits of Using Design Patterns

- **Efficiency and Best Practices**: Design patterns encapsulate proven solutions, saving you time and effort by leveraging established best practices.

- **Scalability and Performance**: Many patterns are optimized for scalability, ensuring your application can handle growth without compromising performance.

- **Consistency and Maintainability**: Patterns promote consistent architecture, making codebases easier to understand, maintain, and extend.

- **Reliability and Resilience**: Patterns address fault tolerance and error handling, resulting in applications that gracefully recover from failures.

- **Flexibility and Adaptability**: Patterns facilitate changes, enabling your application to evolve and adapt to new requirements seamlessly.

- **Reusability and Accelerated Development**: Patterns encourage reusable components, speeding up development and reducing the risk of bugs.

- **Effective Data Modeling**: In NoSQL databases like Azure Cosmos DB, choosing the right pattern ensures efficient data modeling for enhanced performance.

- **Documentation and Communication**: Patterns provide a shared vocabulary, aiding communication and collaboration among team members.

- **Adherence to Best Practices**: Design patterns ensure applications adhere to security, data integrity, and maintainability best practices.

- **Reduced Learning Curve**: Developers familiar with patterns quickly understand and contribute to projects, reducing onboarding time.


Expand Down Expand Up @@ -74,15 +65,31 @@ Dive into the `schema-versioning` folder to learn how to manage changes to your

## Getting Started

Navigate to the individual folders of each design pattern for a dedicated `README.md` file that provides step-by-step instructions on how to implement and work with the pattern in your applications.
### Using the Terminal:
- Open the terminal on your computer.
- Navigate to the directory where you want to clone the repository.
- Type `git clone https://github.com/Azure-Samples/cosmos-db-design-patterns.git` and press enter.
- The repository will be cloned to your local machine.

### Using Visual Studio Code:
- Open Visual Studio Code.
- Click on the **Source Control** icon in the left sidebar.
- Click on the **Clone Repository** button at the top of the Source Control panel.
- Paste `https://github.com/Azure-Samples/cosmos-db-design-patterns.git` into the text field and press enter.
- Select a directory where you want to clone the repository.
- The repository will be cloned to your local machine.

### Using GitHub Codespaces

Nearly all of these samples are configured to run from [GitHub Codespaces](https://docs.github.com/codespaces/overview).

### Trying Out the Design Patterns with Azure Cosmos DB for Free
Navigate to the individual folders of each design pattern for a dedicated `README.md` file and look for the GitHub Codespaced badge.

You can try out these design patterns using a **free Azure Cosmos DB account**, making it easy to experiment with Azure Cosmos DB before making a commitment. No credit card is required to get started, and your account is free for 30 days. After the initial 30-day period, you can create a new sandbox account. Additionally, you have the option to extend the trial beyond 30 days for an additional 24 hours. If you decide to upgrade, you can do so at any time during the 30-day trial period.
### Setting up Azure Cosmos DB

**Sign up for your free Azure Cosmos DB account at [aka.ms/trycosmosdb](https://aka.ms/trycosmosdb).**
All of these design patterns are built to run from a single Serverless Azure Cosmos DB account. Before running any of the samples, click the Deploy to Azure button below to create a Serverless Azure Cosmos DB account. You will need the URI Primary Key and Connection String for these. Keep those handy as you prepare each sample to run.

This opportunity provides a risk-free environment to explore these design patterns and see how Azure Cosmos DB can enhance your application development and data modeling efforts. Whether you're an experienced developer or just getting started, the free trial allows you to discover the benefits firsthand.
[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fgithub.com%2FAzureCosmosDB%2Fdesign-patterns%2Ftree%2Fmain%2Fazuredeploy.json)

Happy coding with Azure Cosmos DB and these powerful design patterns!

Expand Down
47 changes: 21 additions & 26 deletions attribute-array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,38 +176,19 @@ You can try out this implementation by running the code in [GitHub Codespaces](h

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/azure-samples/cosmos-db-design-patterns?quickstart=1&devcontainer_path=.devcontainer%2Fattribute-array%2Fdevcontainer.json)

## Create an Azure Cosmos DB for NoSQL account
## Set up application configuration files

1. Create a free Azure Cosmos DB for NoSQL account: (<https://cosmos.azure.com/try>)
You need to configure **two** application configuration files to run these demos.

1. In the Data Explorer, create a new database named **CosmosPatterns** with shared autoscale throughput:
1. Go to your resource group.

| | Value |
| --- | --- |
| **Database name** | `CosmosPatterns` |
| **Throughput** | `1000` (*Autoscale*) |
1. Select the Serverless Azure Cosmos DB for NoSQL account that you created for this repository.

**Note:** We are using shared database throughput because it can scale down to 100 RU/s when not running. This is the most cost efficient if running in a paid subscription and not using Free Tier.
1. From the navigation, under **Settings**, select **Keys**. The values you need for the application settings for the demo are here.

1. Create a container **AttributeArrays** with the following values:
While on the Keys blade, make note of the `URI` and `PRIMARY KEY`. You will need these for the sections below.

| | Value |
| --- | --- |
| **Database name** | `CosmosPatterns` |
| **Container name** | `AttributeArrays` |
| **Partition key path** | `/productId` |

## Get Azure Cosmos DB connection information

You will need connection details for the Azure Cosmos DB account.

1. Select the new Azure Cosmos DB for NoSQL account.

1. Open the Keys blade, click the Eye icon to view the `PRIMARY KEY`. Keep this and the `URI` handy. You will need these for the next step.

## Prepare the app configuration

1. Open the application code, create an **appsettings.Development.json** file in the **/source** folder. In the file, create a JSON object with **CosmosUri** and **CosmosKey** properties. Copy and paste the values for `URI` and `PRIMARY KEY` from the previous step:
1. Open the attribute-array project and add a new **appsettings.development.json** file with the following contents:

```json
{
Expand All @@ -216,6 +197,20 @@ You will need connection details for the Azure Cosmos DB account.
}
```

1. Replace the `CosmosURI` and `CosmosKey` with the values from the Keys blade in the Azure Portal.
1. Modify the **Copy to Output Directory** to **Copy Always** (For VS Code add the XML below to the csproj file)
1. Save the file.

```xml
<ItemGroup>
<Content Update="appsettings.development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
```

## Run the app

1. Open a terminal and run the application:

```bash
Expand Down
5 changes: 2 additions & 3 deletions attribute-array/source/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

IConfigurationBuilder configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.Development.json", optional: true);
.AddJsonFile($"appsettings.development.json", optional: true);

Cosmos? config = configuration
.Build()
Expand Down Expand Up @@ -37,8 +37,7 @@
);

Database database = await client.CreateDatabaseIfNotExistsAsync(
id: "CosmosPatterns",
throughputProperties: ThroughputProperties.CreateAutoscaleThroughput(1000)
id: "AttributeArrayDB"
);

Console.Write(
Expand Down
42 changes: 42 additions & 0 deletions azuredeploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"accountName": {
"type": "string",
"metadata": {
"description": "Azure Cosmos DB account name, max length 44 characters"
}
}
},
"resources": [
{
"type": "Microsoft.DocumentDB/databaseAccounts",
"apiVersion": "2022-05-15",
"name": "[toLower(parameters('accountName'))]",
"kind": "GlobalDocumentDB",
"location": "[parameters('location')]",
"properties": {
"databaseAccountOfferType": "Standard",
"locations": [
{
"locationName": "[parameters('location')]",
"failoverPriority": 0
}
],
"capabilities": [
{
"name": "EnableServerless"
}
]
}
}
]
}
45 changes: 19 additions & 26 deletions data-binning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,38 +174,19 @@ You can try out this implementation by running the code in [GitHub Codespaces](h

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/azure-samples/cosmos-db-design-patterns?quickstart=1&devcontainer_path=.devcontainer%2Fdata-binning%2Fdevcontainer.json)

## Create an Azure Cosmos DB for NoSQL account
## Set up application configuration files

1. Create a free Azure Cosmos DB for NoSQL account: (<https://cosmos.azure.com/try>)
You need to configure an application configuration file to run this app.

1. In the Data Explorer, create a new database named **CosmosPatterns** with shared autoscale throughput:
1. Go to your resource group.

| | Value |
| --- | --- |
| **Database name** | `CosmosPatterns` |
| **Throughput** | `1000` (*Autoscale*) |
1. Select the Serverless Azure Cosmos DB for NoSQL account that you created for this repository.

**Note:** We are using shared database throughput because it can scale down to 100 RU/s when not running. This is the most cost efficient when running at very small scale.
1. From the navigation, under **Settings**, select **Keys**. The values you need for the application settings for the demo are here.

1. Create a container **DataBinning** with the following values:
While on the Keys blade, make note of the `URI` and `PRIMARY KEY`. You will need these for the sections below.

| | Value |
| --- | --- |
| **Database name** | `CosmosPatterns` |
| **Container name** | `DataBinning` |
| **Partition key path** | `/DeviceId` |

## Get Azure Cosmos DB connection information

You will need connection details for the Azure Cosmos DB account.

1. Select the new Azure Cosmos DB for NoSQL account.

1. Open the Keys blade, click the Eye icon to view the `PRIMARY KEY`. Keep this and the `URI` handy. You will need these for the next step.

## Prepare the app configuration

1. Open the application code, create an **appsettings.Development.json** file in the **/source** folder. In the file, create a JSON object with **CosmosUri** and **CosmosKey** properties. Copy and paste the values for `URI` and `PRIMARY KEY` from the previous step:
1. Open the data-binning project and add a new **appsettings.development.json** file with the following contents:

```json
{
Expand All @@ -214,6 +195,18 @@ You will need connection details for the Azure Cosmos DB account.
}
```

1. Replace the `CosmosURI` and `CosmosKey` with the values from the Keys blade in the Azure Portal.
1. Modify the **Copy to Output Directory** to **Copy Always** (For VS Code add the XML below to the csproj file)
1. Save the file.

```xml
<ItemGroup>
<Content Update="appsettings.development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
```

## Run the demo

Open a new terminal and run the included Console App (Program.cs) which generates events, saves them bucketed by device and minute:
Expand Down
Loading

0 comments on commit 25646ff

Please sign in to comment.