DEV Community

Sardar Mudassar Ali Khan
Sardar Mudassar Ali Khan

Posted on • Edited on

Microsoft Azure Cosmos Database Service

Introduction:

A NoSQL database with strong consistency is Cosmos DB. It lacks a schema, enables SQL-like querying, and even contains JavaScript-written stored procedures, triggers, and UDFs (User Defined Functions). It’s Microsoft's response to systems like MongoDB, Cassandra, Couchbase, and others. For at least 99 percent of requests, Cosmos DB promises latencies of fewer than 10 milliseconds for reads and less than 15 milliseconds for writes. With that level of performance assurance, Cosmos DB is poised to rule the planet.
For Cosmos DB, Microsoft also supportss.NET, Node.js, Java, and a Python SDK. It is fully managed and operates on Azure. All the data is automatically replicated across any number of global regions. It offers several different consistency levels.

Features Of Azure Cosmos Database

Strong Consistency:

With an RDBMS, it is consistent. Clients should always expect to receive the most recent acknowledged writing when they ask to. However, this is slow, and using it requires linking the Cosmos DB account to more than one region.

Bounded Staleness:

This level ensures that the readings may be delayed by the client by no more than x versions of the document or a specific amount of time. The user will always receive the most recent two versions of a page, for instance, if the client specifies x=2. With time, it remains the same. If the time is set to five seconds, it will be ensured that the resource has been written to all replicas once every five seconds so that the following queries can see the most recent version.

Session:

The most well-known option, this one is focused on a client session as the name implies. Imagine that a user of an eCommerce website commented on a product. The user who left the comment ought should be able to read it, however, it will take some time before other page visitors can.

Eventual:

The clones will eventually converge, as the name implies, in the absence of any further writes. This option is the fastest of all, but it also has the worst read consistency.

Consistent Prefix:

You can make sure that the order of writes is always reflected during subsequent reads by using this option.

Multi-model API Support:

In keeping with its planet-scale approach to problem-solving, Cosmos DB offers five of the most widely used categories of APIs for data processing and storage.

High Availability:

It provides financially supported SLAs that guarantee resource availability up to the 99th percentile.

The spectrum of Consistency Models:

We have immediate or delayed replication, as was said above in the history lesson. However, Cosmos DB also gives us the option to select between these two opposites of consistency.
Near-zero Replication Effort:
With a simple click, users and developers may replicate the database to additional locations. The remainder is taken care of by Cosmos DB.

Know HOW, WHEN, and WHY?

Creating a globally distributed application undoubtedly involves comparable challenges. Consider the hypothetical sports channel XYZ that provides real-time information on football games. Its user base is dispersed over more than 50 nations on 5 continents. Watching live updates for their favorite fixtures on the channel is available to viewers from all over the world. The business is based in North America, where its servers are also located. It appears to be straightforward at first, but the devil is in the details.

Let's imagine that there is a football game taking place right now. When user A from North America opens the channel, live updates begin to appear. Due to the servers being deployed there as well, they will experience minimal to no delay. However, if user B from Australia requests live updates, they can experience more delays, depending on the network and the volume of traffic. As a result, the user experience in each country will be very different from one another. To address this issue, the sports channel chooses to replicate its servers across the world to improve user experience and minimize latency for its viewers.
It has a special set of problems that are intrinsic to any replication problem, in addition to the administrative work needed to replicate these servers. When asked how soon the data should be replicated, we must give a detailed answer. You might want to rethink saying "immediately" if you did. Let's say the channel has 60 servers scattered around the globe. If we wish to alter the score on one of these servers, we will need to update the score on each of these 60 servers. If we want to complete this replication instantly, or as we like to say, "in real time," we must write to those 60 servers right away. Our writing expenses had unexpectedly gone up by $60. After conversion, this
We can avoid this expense, though, provided we can afford a slight delay in replication. For instance, we don't have to immediately write to every server. Data can be replicated one at a time, which again lowers replication costs. However, because the replication is now done one at a time, this method runs the danger of exposing certain users to outdated data. The classic trade-off between latency and throughput is represented by this balancing act.
We can avoid this expense, though, provided we can afford a slight delay in replication. For instance, we don't have to immediately write to every server. Data can be replicated one at a time, which again lowers replication costs. However, because the replication is now done one at a time, this method runs the danger of exposing certain users to outdated data. The classic trade-off between latency and throughput is represented by this balancing act.

Let’s See the Architecture in pictorially

Image description

Workflow in Azure Cosmos Database

  • An application is accessed by a user through a specific client.

  • To direct the user's connection to the appropriate place for accessing the application, Azure Traffic Manager uses a routing profile or layered profiles.

  • The application creates a database session and connection in the area where the user is directed.

  • Applications with varied degrees of complexity can be supported by the solution. The app might, for instance, be a straightforward, static page. Or it might be a Kubernetes-hosted micro services-oriented application.

  • An Azure Active Directory (Azure AD) user manages the connection between the application landscape and Azure Cosmos DB by retrieving the Azure Cosmos DB keys from the Azure Key Vault.

  • Using the Azure Cosmos DB multi-homing APIs, the application can deliver queries to the nearest region because it is aware of it. Without altering settings, the nearest region is found. Your application doesn't need to be redeployed or suspended as regions are added and removed from your Azure Cosmos DB subscription. The application is still quite accessible. On the backend, Azure Cosmos DB manages the data replication and global distribution based on the number of defined regions. The system switches to the region with the greatest failover priority if the automatic failover option is enabled and a region becomes unavailable. For this failover, no user action is necessary. Changing the region priority is possible when automatic failover is enabled.

Worldwide Popular Projects Using Azure Cosmos Database

In applications where lower latency is essential and data is scattered, Cosmos DB performs exceptionally well. This comprises:

  • IoT devices now using Cosmos Database

  • Gaming Devices and Applications using Cosmos Database

  • Social Media Applications Using Cosmos Database

Microsoft Products Using Microsoft Azure Cosmos Database
Numerous Microsoft products, including the following, have been using Azure Cosmos DB:

  • Skype

  • Xbox

  • Office 365

  • Azure

Potential use cases

Industries that operate globally and need to keep data close to their users may consider this approach. The media, entertainment, travel, and hospitality sectors are among the examples. Examples of situations where globally distributed applications are used are:

  • streaming video for consumers.

  • services that use apps to pick up and deliver people and goods.

Conclusion
It was discussed in this introduction to Azure Cosmos DB why and how it was created, as well as how it changed from Document DB to Cosmos DB, which we are familiar with today. We also examined the service's use cases and features.

Top comments (0)