Exploring TiDB Serverless: How Much Can You Achieve with the Free Tier?

Pongsatorn Manusopit
4 min readAug 8, 2024

--

As a hobbyist looking for a robust yet cost-effective serverless database solution for my project, I initially juggled between TiDB Cloud and PlanetScale. However, with PlanetScale’s recent decision to deprecate their Hobby tier, my focus shifted entirely to TiDB Serverless. Let me walk you through how much you can actually do with TiDB’s free tier.

TiDB offers an impressive free quota that includes

You can create up to 5 clusters.

  • Each cluster can store 5 GiB of row-based data.
  • Each cluster can store 5 GiB of columnar data.
  • Each cluster can consume 50 million Request Units (RUs) per month.

So, per account, you get a total of:

  • 25 GiB of Row Storage
  • 25 GiB of Column Storage
  • 250M Request Units (RUs) per Month

Benchmarks

I used the “Hacker News Curated Comments Dataset”, which can be accessed (https://zenodo.org/records/45901). This dataset contains:

  • Size: 744 MB
  • Row Count: ~ 1 million rows

Schema

Loading the Data

When loading this dataset into TiDB Serverless with Tableplus CVS import, it used approximately 4,000,000 RUs to insert and index the data, consuming around 1 GB of storage. The entire process took about 5 minutes to complete.

Query time

I used queries from the [DB Benchmarks repository](https://github.com/db-benchmarks/db-benchmarks).

TiDB Serverless does not support full-text search out of the box. This limitation might affect certain use cases that depend heavily on text search functionality. After running the test queries, it used approximately 80,000 RUs.

JMeter load test

  • Number of Threads: 100
  • Duration: 300 sec
  • Query: select * from hn order by comment_ranking asc limit 20
  • Return size in bytes: 22961

Result

  • TPS: 1,688 query/sec
  • Peak: 2,850 RU/sec
  • Total query: ~500,000

This load test consumed ~13 million RUs, which is significant considering the free tier allows for 50 million RUs per cluster per month. This means you could run approximately 2M query.

Approximate

Given the results from the benchmarks and load tests, we can approximate practical usage scenarios within the free tier’s limitations.

  • If we conservatively estimate that each query of comparable complexity to the load test query consumes a similar amount of RUs, you could potentially run around 2 million queries per month.
  • This breaks down to approximately 66,666 queries per day, 2,777 queries per hour, 46 queries per minute, and about 0.7 queries per second.

These calculations demonstrate that even under a free plan, TiDB Serverless offers substantial capacity for hobby projects or small-scale applications.

Enhancing Capacity with Caching

To further extend the capabilities of your free tier, you can add a caching layer. Implementing a caching solution like Redis or Memcached can significantly reduce the number of queries made directly to the database, allowing you to handle more load without hitting the RU limits. By caching frequently accessed data or results of common queries, you offload a substantial amount of read operations from the database, maximizing your 50 million RUs per cluster per month.

Background tasks

In addition to user-executed queries, Request Units (RUs) can be consumed by background tasks such as automatic statistics gathering.

The attached graphs show two key metrics over time for my NestJS + Prisma application connected to the database

Total RU consumption fluctuates throughout the period, reaching up to approximately 12 RUs per second during background tasks.

In conclusion

TiDB’s free tier provides impressive capabilities for hobbyist projects, especially given the generous allocation of resources. With the ability to create multiple clusters and a substantial quota for both storage and RUs, TiDB Serverless proves to be a robust and cost-effective choice for your next project

--

--

No responses yet