You should try .NET + libSQL, and here’s why

Hermógenes Ferreira - Jul 15 - - Dev Community

TL;DR: libSQL is a SQLite fork that is a game changer for global distributed databases. .NET 8 Native AOT performance is incredible. But together, they're unbelievably fast.

What is libSQL?

First, let me introduce you to libSQL.

libSQL is a fork of SQLite made by Turso. The goal is to optimize SQLite for low latency and replication, making it a perfect fit for global distributed databases.

From now on, when I mention libSQL, I’m referring to Turso's offering.

SQLite? Really?

Yeah, I thought the same when I first heard about it.

SQLite is mostly used for embedded systems and mobile apps, but I never thought it could be used for server-side applications. But libSQL changes everything.

What makes libSQL so Special?

First, it's fast. Really fast. But I’ll delve into that later.

One of the biggest challenges of global systems is latency. It doesn't matter how fast your system is if you have to wait for the data to travel around the world. If you have a microservice that can process a request in 1ms, it still has to travel from your server to the client and back. This is not negligible. In the best case, it takes more than 200ms for a round trip between Sao Paulo and Europe, for example.

We’ve seen a surge in Edge Computing offerings in recent years, but they all suffer from the same problem: the data is still far from the code.

Turso solves this problem by replicating data to multiple read-only servers around the world. This way, the data is always close to the code that needs it.

Another advantage of libSQL is that it offers a simple HTTP API to access the data. This is very useful for serverless applications, as you can access the data without the need for a database driver, completely stateless.

What About .NET?

.NET is a great platform. It's fast, secure, cross-platform, and open-source.

However, it’s not known for its performance, especially in startup time. This is a big problem for serverless applications, as the cold start can take seconds.

But since .NET 6, things are changing. With the new Native AOT and trimming, the startup time is reduced to milliseconds.

And with .NET 8, the performance is even better.

With the official support of AWS Lambda, creating a serverless application with .NET is easier than ever, and the performance is great.

OK! But How Fast is .NET + libSQL?

I’m glad you asked.

And instead of telling you, I’ll show you.

I made a simple benchmark inspired by AWS .NET samples.

You can find the code of this benchmark on GitHub.

It’s a simple function that performs CRUD operations on a table.

The function is configured to 1GB of memory (but it uses way less than that and could be fine-tuned later).

The test is split into two parts: Write and Read-only.

For the write test, I made around 65 requests per second for 3 minutes.

For the read-only test, I made around 100 requests per second for 2 minutes.

The results are impressive, if I may say so.

Phase 1: Write and Read Test

Cold Start Count Billed Min Avg P50 P75 P90 P95 P99
0 11622 164773 7.586 13.6814 11.0058 12.1101 17.4715 20.006 29.798
1 10 515 345.349 405.552 385.861 441.672 445.478 477 477

In total, 11,632 requests and a total of 165,288 of billed duration.

What’s interesting is that, even though cold start latency is high, given we are using AWS managed runtime, we don’t pay for it.

If we have a similar request rate in a month, this Lambda function would cost around $72. Not bad at all. 65 requests per second is a lot of requests. Almost 170 million requests per month.

Phase 2: Read-only Test

Cold Start Count Billed Min Avg P50 P75 P90 P95 P99
0 11889 147747 7.581 11.9277 10.5759 11.4531 13.1145 15.2582 24.1165

In total, 11,889 requests and a total of 147,747 of billed duration in 2 minutes.

P99 is 24ms. That’s crazy.

Results Combined

Cold Start Count Billed Min Avg P50 P75 P90 P95 P99
0 23,511 312,520 7.581 12.7946 10.7458 11.824 14.4304 18.7705 27.9578
1 10 515 345.349 405.552 385.861 441.672 445.478 477 477

Conclusion

.NET + libSQL is a great combination for serverless applications.

The performance is great, the cost is low, and the development experience is awesome if you are already familiar with .NET.

If you are looking for a global distributed database, libSQL is a great option.

References

.
Terabox Video Player