How Supabase fits into your stack
Recently I considered replacing the Talkyard comments solution on my notes here with something I’ve built myself. To do that I need a database. I was looking at different Postgres hosting options when I recalled I had seen buzz from developers on Twitter about Supabase. I wondered if that could be my database host?
Supabase’s tagline starts with “Supabase is an open source Firebase alternative.” That didn’t tell me much because it has been years since I used Firebase and I could barely remember how it worked or what it offered. I’ve done some reading of the Supabase docs and thought I would share my understanding of how Supabase can help on a new project.
When I think about how a website or app is set up, it looks something like this:
- The server renders the page.
- The client sends subsequent requests to a back-end application on the server.
- The application connects to a database and retrieves/writes data, and returns a response to the client.
Or, in the case of this particular project I was designing:
- The Astro SSR page is rendered via a Netlify function.
- The client sends subsequent requests to an API provided by a Netlify function.
- The serverless function code connects to a database and retrieves/writes data, and returns a response to the client.
In both cases, it’s the same client -> server -> DB flow, except serverless functions are standing in for an app on a server in the second case.
I was looking for something to fulfill the database section of that design, and Supabase does provide Postgres DB hosting, but it is also trying to remove the need for you to code a server-side application to control the flow of data in your project. You can write code on the client that interfaces directly with the database via the API provided by Supabase.
When I saw that the flow of information in a Supabase Project goes from client to DB (via a thin ready-made API layer), my first thought was, what about authentication? Don’t you need to write server-side code to make sure the person who is sending the data is allowed to put that in the database? Supabase allows you to set policies on DB table rows so you can control access to reading, creating, updating and deleting rows on tables.
On the subject of authentication… one of the features of the Supabase JS client is that it provides shortcuts to building “Sign Up and Log In” solutions for your app. That’s pretty cool as most apps require user authentication and it is a tedious thing to get right when you’re coding it from scratch.
Anyway, I think I will use Supabase as the DB solution for my new project. Even if I don’t go all-in on client-side functionality with the Supabase JS client (I’m trying to make progressive enhancement a priority), I can use their REST APIs with Astro SSR functionality. It still looks like an easy enough (and affordable) option for adding a Postgres database to my project.
Can’t you hear that
Boom, badoom, boom, boom, badoom, boom, bass?
He got that super bass)
Comments
Stefan Judis
December 9, 2022 at 7:43 AM
I have the same inner fight every third day!
Looking forward to see how Supabase will work for you, because I also had a brief look already and was on the exact same path. 🫣
Rach Smith OP
December 9, 2022 at 9:48 PM
I'll share updates here. Instead of making a whole comments system first I'm going to build some "reaction buttons" as a proof of concept and see how that goes.
Stefan Judis
December 9, 2022 at 10:00 PM
Looking forward! Unsurprisingly, I'm playing with this idea, too! 🫣
Kelsey W
October 11, 2023 at 9:24 PM
Hi Rach! I discovered your blog while searching for ways to use Supabase with a project I'm working on. I'm so glad I found it! I love your writing and am grateful you're sharing all your learnings -- technical and otherwise -- with us. This is also simply a beautiful website and a pleasure to scroll through 💜
About this post in particular: I see the comments are still hosted with Talkyard. Were you able to try out Supabase and what was your experience with it? I personally have used Firebase for some past projects but am thinking of using Supabase to try something new. Thanks!
Rach Smith OP
October 12, 2023 at 1:12 AM
Hey Kelsey, thanks for your kind words about the site. I didn't end up pursuing a comments solution with supabase. I'm actually working on just using a Netlify form for comment submission and adding the comments to my Astro site as a JSON content collection. But I have been trying out Supabase with Sveltekit in a little habits app project I'm building for myself. I am loving that combination of tech, they make the data side of getting a web app working really fast.
Kelsey W
October 12, 2023 at 4:18 AM
Got it, thanks! I haven't heard of Sveltekit before but will check it out along with Supabase.
Leave a Comment
💯 Thanks for submitting your comment! It will appear here after it has been approved.