Connecting external databases to Bubble: Tinybird
If you need to store millions or even billions of records and get counts quickly, you might want to consider using an external database. This week we're looking at Tinybird & Bubble.
Hey there!
Welcome to the No Code SaaS newsletter, where I take you along on my journey of building a profitable SaaS business without code - and share what I learn along the way.
This week we’re looking at external databases, and why they can sometimes help supercharge certain aspects of your Bubble app.
When I first launched my app UserLoop it didn’t have any built-in analytics at all. Eventually, I added some simple analytics which measured how many customers had responded to surveys, completion rates etc.
I did all this by storing records in the Bubble database and then running counts on them. This worked really well to start with and helped me validate the use case for analytics. But as the app grew, and the number of records went into the hundreds of thousands, my analytics started to slow down and became almost unusable for my largest users.
I considered a couple of approaches for fixing this…
Storing calculated fields in Bubble. In some cases, it can make sense to run a daily scheduled job which runs a count of things in a table and then stores that count in a separate table which you can then query from the front end. This means big calculations don’t have to be done on the fly and are effectively pre-processed., so the front end just has to pull the calculated result.
Using Bubble’s Approximate Count feature. I experimented with using Bubble’s built in ‘approximate count’ feature which is supposed to return a super fast result for larger queries, with the caveat that the calculated result is not super accurate. During my testing I found the count to be wildly inaccurate and not usable in a production setting so this wasn’t an option for me.
Using a Third Party Database. I then decided to investigate third-party databases which might be suitable for powering the analytics in my app. I didn’t want to move the whole app database, just the parts with performance and scale issues. In my case, this is a particular table which stores all the survey responses. After testing out Xano and Supabase I landed on Tinybird after a recommendation from Ab Advany.
Benefits of using an external database with Bubble
After running some initial tests I was impressed - and have been using it in production to power my Bubble app for the last 4 months.
Some of the benefits I’ve experienced of this approach:
Massive increase in query speed on analytics operations. This has been a big benefit to my larger customers, as they can query hundreds of thousands of records, apply filters and get results back in under a second. Previously some of these counts could take over 20 seconds using the standard Bubble DB!
Reduced WU usage. This approach of using a third party database for this part of my app has reduced the amount of complex database queries my app has to make inside Bubble, as these queries are now made via the API connector to Tinybird I need much less processing power to do them.
Unexpected benefits. I’ve also experienced some unexpected benefits and discovered new features I can now build by using Tinybird as my database. Being able to do more complex database joins, and being able to query data very quickly has helped me improve other areas of my app outside of analytics.
How To Set up Tinybird with Bubble
I decided to make a video tutorial to walk you through how to set up Tinybird and connect it to Bubble.
In the video we make a super simple comment app which stores comments in Tinybird and then returns a count back to the Bubble front end.
In the video we cover…
Signing up for Tinybird and creating a workspace
Sending data from Bubble to Tinybird using the API connector
Formatting the event payload using JSON
Building an API endpoint in Tinybird
Consuming the Tinybird API in Bubble
I hope you find it helpful in inspiring you of new ways to work with data in Bubble, and how you can scale certain parts of your app by using external services.
Let me know if you like the video tutorial style instead of a written guide - I’m experimenting of different ways of making the content for the newsletter.
Until next time - happy building!
James.
Hey James! I found this article helpful since we're close to launching our MVP and have visibility into needing more scale from Bubble to handle our datasets (tables with 1M+ rows). I'd love to hop on a quick call or start an email thread if you're available to chat.
James, this video is gold! I have been looking at external services to try with Bubble to see what data can be stored outside of Bubble. I caught wind of Tinybird via your podcast and found this article after the fact. It's amazing that you created a video and - using that - I was able to create two forms in Bubble and post data to Tinybird in two separate data sources. I'm fairly new to Bubble and just experimenting with a few things but quite familiar with SQL and databases at a low level. I'm curious about how I might handle capturing id and timestamps (Unix timestamps) in Tinybird from Bubble. The idea is that I can create data source relations by id and capture record creation and update times. It seems Tinybird hands that control to you so I think I need to add that to Bubble via the API connector. Do you have any experience with capturing id and timestamps in Tinybird and how that is handled via Bubble? Any help or advice is appreciated. Thanks! Tom