CockroachDB serverless: Free-Tier analysis

Serverless CockroachDB can save you a lot of time and money

Radoslav Vlaskovski
6 min readJul 16, 2022
CockroachDB logo, Reference: https://github.com/cockroachdb/cockroach

I often come up with ideas for small web apps, which can make my life easier or would be fun to work on. Hosting web apps has gotten much easier in recent years, but in my eyes hosting a database is still the largest bottleneck. I recently discovered, that CockroachDB has a free serverless database service. It takes care of database backups, can be monitored and is completely free. The aim of this blog post is to give an overview of the main features for the free tier of CockroachDB serverless.

What is CockroachDB

CockroachDB is a partially open source distributed SQL database. Its focus is on scalability and robustness, hence the name. Behind the scenes it transforms SQL statements to key-value operations. They are executed on key-value tables spread among the cluster. The entire key-value space is segmented in small ranges and replicated on multiple nodes. Higher replication factor means also better fault tolerance. To learn more about the architecture or how transactions are executed, check out the CockroachDB design document or checkout the architecture docs.

What is serverless CockroachDB

CockroachDB serverless is still in beta. However, it is already stable enough to be used by small applications, such as the ones supported by the free tier. It is completely managed, which means that the developers do not worry about updates, autoscaling, fault tolerance, etc. The serverless cluster is deployed in Kubernetes and is available to more than one tenant. The clusters are hosted on multiple different regions on AWS and GCP. Each application can choose the cluster, that best fits its region and cloud system. The free tier is completely free and is only limited by the number of requests, that the database can process monthly. Later on in the post, I will explain how these limitations work.

Getting started

Getting started is very easy — you just need to set up an account. Afterwards you will be prompted to choose your cloud provider and region, like in the image below.

Once the setup is done you will get a password and a certificate for connecting to the database. To connect your apps, CockroachDB has a lot of great examples documented such as this sample code for a Go app.

Pricing

Pricing is based on two factors — storage size and executed queries. In the free tier you get 5GB storage, which is more than enough. If you need more, then every extra GB is only 1$. To measure the execution cost of an SQL query, the CockroachDB team has introduced the metric — Request Unit(RU). Every query is broken down in RUs and then the cost of the service is measured by the amount of used RUs. In the free tier you get a maximum of 250 million RUs per month. This does not mean, that you can execute 250M requests. Through an example, I will try to explain the RU model.

Request Units

The computational and I/O resources spent on executing an SQL query are represented in RUs. Each CockroachDB serverless user has an initial limit of 100 RUs per second. If they are not used, then they stack up until the end of the month. After that the number of available RUs is reset. This does not mean, that the system is slow at the start of each month. There is an initial “burst” capacity of 10M RUs.

Simple Example: If I create my new serverless account on the 10th of the month, this means that I have saved RUs up until that point. You save around 100 RUs * 60 seconds * 60 Minutes * 24 hours = 8.64M RUs per day (if you are not using the service). From the image below you can see I have around 95M RUs on the 10th day. This is from the 86M I have saved in the first 10 days and the additional 10M initial RUs.

I was not able to find a clear “function” for how RUs are measured. Therefore, I built a small app in Go to analyze how many queries can be executed within these limits. I generated two tables in my CockroachDB. The first one represents a duck’s nest with the number of eggs in it. The second table will store the ducks with all their attributes and a link to their nest. Here is the SQL statement:

Then I created two Go packages to execute SQL queries to the server. I will use these operations to measure the amount of Request Units for the different CRUD operations.

The first function is tasked only with creating the duck nests themselves. It generates duck nests with a random number of eggs.

The duck package is where I wrote most of the test queries. They cover the basic CRUD use cases. In addition to that, I wrote a query, which gets the average egg count by duck name. Here is the source code for the different operations:

Function to create random duck and save it to Serverless CockroachDB
Function to get duck by ID from CockroachDB
Function to delete random ducks from CockroachDB
Function to update duck by painting it blue
Function to calculate the average egg count in the nest of duck with a specific name

The full source code can be found here: https://github.com/radoslavvlaskovski/go-cockroachdb-ru-evaluation-app

Results

Using these functions, I conducted several tests. The table below shows the results of the measurements.

The RUs per create are the same for the Nest table and the Duck table, which means, that they are constant at 25 RUs. Updates are also relatively cheap at 20 RUs. The most expensive requests are the ones involving join and aggregation at around 75 RUs. The response time of the system was also very good even when dealing with higher work loads. The average query latency is 10ms. It is also skewed by the response time of the join & aggregate query.

With exactly 30K requests made I was not able to crack 1 million RUs. In other words, these experiments were conducted with around 0.4% of the request volume available per month. This means that within a month it is possible to execute 10M create requests or 125M reads. This could very well be enough to support the database needs of a small business for free.

Additional features

The free tier also has database backups, which are done every hour and kept for 30 days. This is a great feature to have especially in a free version. The cluster is scaled automatically up and down depending on the number of requests coming to the nodes. Therefore, users can always expect fast response times. Furthermore, during the tests I used up to 25 active connections without encountering a problem.

CockroachDB also provides a great dashboard. It lets you monitor the state of the cluster and its usage rate.

Serverless CockroachDB dashboard snippet

Final Words

When I started looking into the free tier of Serverless CockroachDB, I expected a partially limited service, which can maybe be utilized for personal use. However, the results speak for themselves. The service provides great performance at very cheap prices. It is great for private users and small business, because it can save them a ton of money and headaches. With a good Quality of Service in high load scenarios, it can easily be also used in larger use cases.

Thank you for taking the time!

If you liked the post and would like to read more follow me. My focus is Data Engineering and Web Development. Any questions, advice and topic suggestions are more than welcome!

References

Full source code: https://github.com/radoslavvlaskovski/go-cockroachdb-ru-evaluation-app

CockroachDB Design Documentation https://github.com/cockroachdb/cockroach/blob/master/docs/design.md

CockroachDB Architecture Documentation https://www.cockroachlabs.com/docs/stable/architecture/overview.html

CockroachDB Serverless Documentation https://www.cockroachlabs.com/docs/cockroachcloud/architecture.html

CockroachDB Example Golang App https://www.cockroachlabs.com/docs/stable/build-a-go-app-with-cockroachdb.html

--

--

Radoslav Vlaskovski

Software Engineer, Data and Web, Axel Springer, MSc CS @ TU Berlin