Tips for getting started with Supabase

June 10, 2024

I’ve been playing around with Supabase for a side project recently. It’s a super convenient platform for things like this because it’s really easy to get up and running. I haven’t personally used it for anything in production so I can’t really comment on the value prop or whether it works at scale.

In my time using it, there’s a few things I’ve discovered or run into that I think would be useful knowledge to share.

1. Add dbdev to your instance

Dbdev is a database package manager for trusted language extensions for Postgres. It allows you to install extensions for things like generating IDs and role-based access control to your Supabase Postgres instance. Supabase provides a certain set of built-in modules in their extensions page for your database. Adding dbdev to your instance allows you to access even more.

You can install it by following the instructions here. There is also a built-in template for installing dbdev in the SQL Editor.

2. Use the SQL Editor directly

Supabase provides a very nice UI for a lot of Postgres including editing tables. However, I have found that in most cases it’s worth learning how to do things directly in the SQL Editor. You’ll get a better understanding of what the commands are doing and learn the pgsql syntax at the same time.

I think this is especially useful when creating tables. Supabase abstracts away some specifics of how column types work and values are autogenerated. This caused me some issues when first getting started using it that were much clearer once I looked at the SQL directly.

3. Use better UUIDs than the default

By default, Supabase only supports UUIDv3 and v4. However, the modern spec goes all the way up to v7 and there are alternative IDs available, like Segment’s ksuid. It’s generally better to use something like UUIDv7 or ksuid: they’re sortable without leaking information like sequential IDs and they’re shorter than older format UUIDs.

You can do this by installing the kiwicopple@pg_idkit module from dbdev. The install instructions provided on the website don’t work correctly on Supabase though. You can install it by running the following commands in the SQL Editor:

select dbdev.install('kiwicopple-pg_idkit');
drop extension if exists "kiwicopple-pg_idkit";
create extension "kiwicopple-pg_idkit";

Then, you can use the generation methods directly in SQL commands, like gen_random_ksuid_microsecond().

4. Use some other cloud serverless provider over Edge Functions

Supabase Edge Functions is not well-explained as a feature in my opinion. It’s basically a standard serverless provider that allows you to run small services without a full backend. Unfortunately, I have found that Supabase Edge Functions is rather less useful than many of the other modules. The runtime is required to be Deno which adds some annoying restrictions. For example, some of the Google Javascript SDKs will not work because Deno does not currently implement the Node APIs for Http2Session. There does not currently seem to be a way to run Node apps or containers with other runtimes.

Given all this, I recommend using one of the other cloud serverless providers if you need access to cloud lambdas, like AWS Lambda or Azure Functions.