Monday, September 10, 2018

Azure Cosmos DB 101


What is Cosmos DB?
       Cosmos DB's original name was Document DB. Developers used the Document DB to store documents in JSON format. One day without any notice Microsoft upgraded the Document DB and changed its name to Azure Cosmos DB. Before we go in details, let's make something clear. Azure Cosmos DB is not a relational database and it does not support classic relational database tables.

        Microsoft wants Azure Cosmos DB to be the database of the future and to last for many decades to come. Microsoft really believes in this product. Dr Leslie Lamport worked on Cosmos DB. According to Dr. Leslie Lamport, Cosmos DB is a database system in which the data can be replicated and copies distributed throughout the world.

What problems do it solve? Do we really need another database system?
       Cosmos DB is mainly used for large-scale OLTP solutions and it tries to solve bigger problems of large companies. RDBMS systems are good to centralize the data. If your company will become a  global company one day, you will find out very fast that your relational data models are not going to handle your global business requirements anymore. You need to distribute the large amount of data and If you want to use your own infrastructure, It will cost you a fortune to create scalable, globally distributed system. That's where Cosmos DB comes to help you. It offers 99.99% availability and you can distribute your data in every region of the world very easily.

Multiple Data-Models
     Cosmos DB stores your data in its own way and it lets you to access your data with many different APIs. If you are comfortable with T-SQL, Cosmos DB has an API named SQL API. You can use Gremlin API if you like to write Graph Database queries. If you have Mongo DB, Cosmos DB supports that too. All you need to do is to change your connection string to Cosmos DB and you are ready to use Cosmos DB engine. Also it supports Cassandra API and Azure Table API.

What does that mean for a DBA?
     Cosmos DB is self-maintaned. You can not connect to Cosmos DB directly like how SSMS connects to SQL Server. It indexes its data automatically and guarantees the best performance. There is no schema to manage since all data is in a document. Developers define keys when they create collection of documents. Keys equal to Primary Keys in SQL Server. Developers can tell Azure Cosmos DB to not index any specific properties. Just like SQL Server, indexes take space in Cosmos DB and more space means higher bill in Cloud systems.

How much does it cost?
      Cosmos DB calculates Request Unit(RU) every time you run a query. If I compare Request Unit to SQL Server, It's like the cost of Execution plan. How much I/O, Mem, CPU used to run a query. When you setup a Cosmos Database, you setup the total Request Unit you want to use. Each time you run a query, Cosmos DB subtract the amount from the total Request Unit. You pay for the total Request Unit you requested when you setup your database. Also all data stays in Solid State Disks and you pay for the disk space.
     
     I have been preparing presentation about Cosmos DB and I will continue to cover Cosmos DB in my next posts too.

1 comment:

  1. azure is a cloud service which provides various services. it is user friendly and can be simple to use. get more in microsoft azure certification training

    ReplyDelete