Skip to main content

SEO

How Turso Brings Globally Distributed Databases Closer to Users

Turso

When we think about globally distributing an application to increase its performance, we usually consider deploying our front or back end in a serverless architecture, a CDN, or perhaps in an edge network. But, while these approaches work and give the expected results, we can go further and try to increase performance even more. What about distributing our database as well? 

Introduction to Turso

That is where Turso comes in handy! Turso is a database tool that helps us create and manage SQLite production ready databases. But where Turso really shines is with its ability to create globally distributed instances of our data, so that our application can access the information from the location closest to the user, significantly reducing latency and improving the user experience. 

Edge Computing and Turso

Turso relies on the Edge Computing concept, which enables it to be fast and scalable. However, as it lives on the edge, it also has some implications that must be considered. For example, to see some significant improvement against a non-edge solution, all the user connections would have to either connect with Turso directly or rely on a distributed backend. Using a distributed database with a single location backend wouldn’t make any significant difference. In Perficient, we explored Turso with its generous free tier to get to know more about this tool and to have firsthand experience of its advantages and disadvantages. 

Research and Metrics

In our research to gather metrics and understand the benefits of Turso, we implemented two APIs: one with Express and the other with Next.js, enabling us to create edge functions. To evaluate the performance of both APIs, we used KeyCDN, a tool that allows us to assess API responses from different locations worldwide, as shown in Figure 1. 

Turso

Turso

Figure 1: KeyCDN Tool 

Latency Validation

Using TTFB (Time to First Byte), we validated how latency varies when utilizing Turso. In the first scenario with the Next.js app and edge functions, we created a database located in Bogotá, Colombia, and measured the latency from different parts of the world. In the second scenario, we set up a distributed database in Sydney, Australia, to measure latency improvements. 

Results with Next.js and Edge Functions

In Figure 2, you can observe high latencies, such as 7.21 seconds at the “planets” endpoint in Frankfurt, due to the database being located in Bogotá, Colombia. 

Turso Figure1

Turso

Figure 2: Results using database in Bogotá, Colombia with Edge 

Latency Improvements with Distributed Databases

When the database is distributed and brought closer to users by locating a replica in Sydney, as shown in Figure 3, the latency at the same endpoint in Frankfurt drops to 563.83 milliseconds, significantly reducing latency. 

Figure2

Figure 3: Results using database in Bogotá, Colombia and Sidney, Australia with Edge 

Results with Express Application

For the Express application, the same approach was taken. The Turso database was located in Bogotá, Colombia, and results were consistent with expectations: high latencies, such as 7.18 seconds to Frankfurt, as seen in Figure 4. 

Figure3

Figure 4: Results using database in Bogotá, Colombia with Express  

Further Improvements with Distribution

Distributing the database and bringing it closer to users, as shown in Figure 5, significantly improves latency times. Although latency remains relatively high in locations like Singapore (1.16 seconds), overall performance is better than using a single database in Bogotá. 

This is different from edge functions, which aim to bring data as close to the user as possible, reducing latency significantly. With Turso, the database can be seamlessly distributed to multiple locations, providing faster data access and improving performance. 

Figure4

Figure 5: Results using database in Bogotá, Colombia and Sidney, Australia with Express 

Benefits of Turso

Furthermore, Turso is built using libSQL, a fork of SQLite, making it a database that can be replicated and massively scaled at low costs. Additionally, Turso is open source and open to contributions. Moreover, Turso offers a feature called Embedded Replicas, which allows mobile apps to provide robust functionalities without relying on constant connectivity. This feature can be particularly useful for IoT systems that operate in environments with limited connectivity and can also benefit global app development platforms and fintech companies. 

Future Prospects with Turso

While there are no direct implementations of Turso at Perficient, this research highlights an opportunity for the company to provide clients with high-performance database solutions. Exploring Turso positions Perficient to offer innovative solutions that bring databases closer to users and reduce latency. 

Ease of Implementation and Recommendations

Our experience with Turso led us to the conclusion that it’s an easy technology to implement in new projects, especially with the help of Turso CLI. However, if the intention is to migrate to Turso from another database, there is currently no available tool for such migration. In such cases, one can opt to write a migration script using Drizzle to facilitate the process. 

Conclusion and Best Practices

To get better benefits from Turso, the recommendation is to analyze which countries and places around the world use the application and distribute it accordingly. Let’s remember, if the application and the database are close to the user, the latency will be better, making the interaction satisfactory and fast. 

Turso is a technology that allows us to achieve better latency in our application, albeit with some limitations such as capacity and migration possibilities. 

In the future, this could be a great solution for distributing our database for specific applications, enabling us to achieve better latency in our applications. 

Article written in collaboration with Sebastián Herrera Hernández and Juan José Parra Díaz.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Melissa González Nebrijo

Melissa is based in Cali, Colombia. A software developer with approximately two years of experience, she specializes in front-end development and is deeply committed to her professional growth. This commitment drives Melissa to tackle diverse technical challenges that enhance her programming and problem-solving skills. With a keen interest in creating seamless user experiences and robust back-end functionalities, she is on a path to becoming a proficient full-stack developer.

More from this Author

Follow Us