CosmosDB–Schemaless Scenario

As discussed earlier, the Decision for choosing CosmosDB rather than SQL Server is mostly one of the following:

  • Schemaless Advantage
  • Geo Replication

In this post we can explore the same with few scenarios.

Player Table

Let us think of a Table named Player in SQL Server.  There will be properties like following:

  • ID
  • Name
  • Age
  • Address

Requirement 1

Now, the Player table NEED TO support both Football player & Cricket player.

We resolve this by adding a Type column to differentiate between the players.

image

Requirement 2

The requirement changed that:

  • The Football Player should have a Goals column of type int
  • The Cricket Player should have a Run Rate column of type float

We resole this by adding 2 more columns. 

image

Problems in Design

As you can see, there are few problems in current design:

  • There is unwanted column GOALS being allocated for CRICKET Player
  • There is unwanted column RUN RATE being allocated for FOOTBALL Player

The problem is more complicated when the FUTURE REQUIREMENT to support Tennis Player, Badminton Player also comes through.

How COSMOS DB resolves this issue?

Cosmos DB resolves this issue by using only required columns.

{

“name”: “John”,

“age”: “30”,

“type”: “Football”,

“goals”: 4,

}

{

“name”: “Kevin”,

“age”: “25”,

“type”: “Cricket”,

“runrate”: 5.3

}

Summary

In this post we have observed the Schemaless advantage of Cosmos DB.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s