loading...

Exploring Azure Cosmos DB Serverless!

willvelida profile image Will Velida ・4 min read

We can now provision ‘Serverless’ Cosmos DB accounts, only paying for Request Units when we use them!

At Build 2020, the Azure Cosmos DB team announced that they were working on a ‘Serverless’ preview for Cosmos DB, allowing developers to provision Cosmos DB accounts that only use throughput when operations are performed on that Cosmos DB account, instead of having to provision throughput at a constant rate.

Out of absolutely nowhere (it’s been a hell of a week!), the Cosmos DB team announced today that the Serverless preview has been released for the Core API (or SQL)! You can head to Azure right now and provision Cosmos DB accounts without having to provision any throughput.

With Serverless mode, we now have two methods of provisioning throughput in Cosmos DB that we set when we create the account:

  • Provisioned Throughput — Have throughput provisioned at a constant rate, regardless of whether operations are being performed on our Cosmos DB account.
  • Serverless Mode — We only use throughput when operations are performed on our Cosmos DB resources.

What’s so special about Serverless mode?

This is a dramatic change to the way that we provision throughput. Traditionally, we would have to provision throughput at a constant rate. This would be costly, particularly if our applications that use Cosmos DB were idle. It was a nice way to burn money (if that’s your thing) but it turned a lot of developers away from using Cosmos DB.

With Serverless, we now pay for throughput only when we perform operations on our Cosmos DB account.

In terms of capability, there are no differences compared to Cosmos DB accounts that have provisioned throughput. However, with Serverless, we can only have 1 Azure region per Cosmos DB account. We also have a maximum limit of 5000 RU/s and a maximum of 50 GB of storage on our containers.

These are the current limitations of Serverless. I’m hoping once Serverless mode goes GA, the number of Regions per account will increase 🤞

This article discusses some of the features of Serverless that will be available once the service goes GA:https://docs.microsoft.com/en-us/azure/cosmos-db/serverless#performance

Why would we use Serverless?

With Cosmos DB Serverless being more cost effective, we can use it in the following scenarios:

  • Development and building prototypes. Only being charged when we use Cosmos DB will make development a lot cheaper and easier and will hopefully mean that we don’t have to rely on the emulator. I’ve noticed some performance differences between the emulator and using a test account which I’ve destroyed straight afterwards.
  • Testing. I’ve known some developers provision accounts purely for testing purposes using provisioned throughput. In my opinion, this is more reliable than using the emulator, but it’s a pretty expensive alternative. Say if we run nightly tests against our Cosmos DB account, by using Serverless we only spend money when we use it.

Creating a Serverless Cosmos DB account

Creating a Serverless Cosmos DB account is only possible via the Azure Portal at this time. We can only provision Serverless accounts for the SQL API. When creating our account, choose Core (SQL) API as your API and then pick Serverless (preview) under Capacity mode:

Once our account has been provisioned, we can start creating some containers and databases just like we would for provisioned throughput account. The only difference here is that we don’t have to specify how much throughput we want to provision, we will have our limit of 5000 RU/s.

Once our Container has been created, we can set the Time-to-live and indexing policy just as we would in a traditional account, but we aren’t able to change the throughput allocated to it:

What I would like to see in the future

Serverless will dramatically lower the bar of entry into Azure Cosmos DB! I’m really excited at the prospect of seeing more developers use Cosmos DB thanks to this feature. I’m hoping that when Serverless goes GA, we’ll see the following features:

  • The ability to provision Serverless and Provisioned Throughput in the same account. I have a few use cases where I will need to provision throughput on Databases and Containers at a consistent rate, while others could be provisioned as Serverless. It would be awesome to be able to determine how we provision throughput at the resource level, rather than the account level.
  • Multi-regional Serverless Accounts. I doubt that we will be able to provision multi-master Serverless accounts, but it would be nice to specify a read-replica on Serverless accounts.
  • Customization for Request Unit limits. In the current preview, we have a limit of 5000 RU/s. It would be nice to be able to specify a limit that our Serverless accounts can burst to. This would probably have an effect on the pricing model and implementation, but it would be nice to have the option.

Sounds cool! Where can we learn more?

If you want to learn more about Cosmos DB Serverless, check out the following Microsoft docs:

I’m hoping to release a video on Cosmos DB Serverless when live calms down a bit, but if you have any questions in the meantime, please feel free to comment below!

Posted on by:

willvelida profile

Will Velida

@willvelida

Microsoft Data Platform MVP. Software Engineer using .NET to build awesome things in Azure!

Discussion

markdown guide
 

I like this. Having used CosmosDB with my Visual Studio Enterprise credit, the main put-off was the price. So having a pay-for-what-you-use option like this really suits me well 👍