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.
Let us think of a Table named Player in SQL Server. There will be properties like following:
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.
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.
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.
In this post we have observed the Schemaless advantage of Cosmos DB.