Design two containers in Azure Cosmos DB for anonymous and sign-in users

AzureGuru 40 Reputation points
2024-05-17T18:27:02.2933333+00:00

We want to store the user's click on website into Azure Cosmos DB. We want to design two containers in a single Azure database, SampleDB. One container is to store the documents for anonymous user clicks on product detail page, one container is to store the documents for sign-in user clicks on product detail page. Later if an anonymous user sign in, we add the anonymous user's product views document into sign-in user's document container, then delete the document from anonymous user's document container. The sample anonymous user's product detail view looks like this:

{
    "anonymous_id": "12345678",
    "product_views": [
        {
            "sku": "123",
            "view_datetime": "2023-07-15 14:11:15"
        },
        {
            "sku": "456",
            "view_datetime": "2023-06-15 13:13:12"
        }
    ],
}

The sample sign-in user's product detail view looks like this:

{
    "signin_id": "12345678",
    "product_views": [
        {
            "sku": "124330",
            "view_datetime": "2024-01-03 14:41:32"
        },
        {
            "sku": "124330",
            "view_datetime": "2024-01-03 14:42:31"
        }
    ]
}

Is designing two separate containers in a single database for storing above two types of documents a good design practice in Azure Cosmos database?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,483 questions
0 comments No comments
{count} votes

Accepted answer
  1. GeethaThatipatri-MSFT 28,297 Reputation points Microsoft Employee
    2024-05-17T21:16:10.98+00:00

    @AzureGuru Welcome to Microsoft Q&A thanks for posting your question.

    Looks like you have already engaged on SO forum on the same issue,

    First thing I want to understand why you want two different containers - may be the document structure would be the same - I would probably have intuitively used an approach where userId has a prefix like "anonymous_id:12345" or "signin_id:12345" if you want to store them differently and use just a single container but if you want to isolate RU/s between anonymous and signed/in/paid - then you can keep using two containers.

    Regards

    Geetha

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. AzureGuru 40 Reputation points
    2024-05-20T13:37:31.3666667+00:00

    Yes, I asked the same question on SO just in case I don't get any reply, I posted here.

    I'll create two containers and create corresponding Javascript to compare one container vs. two containers. I'm not sure if we need two containers to isolate RU/s limit.

    Thank you for your reply!

    Xinhuan