Build in a weekend. Scale to millions?

Introduction to supabase — Recap of the MD Tech Meetup at UniNow

Philipp Ucke
UniNow Engineering
3 min readSep 30, 2022

--

Supabase Logo
https://supabase.com/

Introduction

Supabase claims to be a Firebase alternative and offers a Postgres database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, and Storage. While Firebase currently offers additional features such as Firebase ML, Crashlytics, and Cloud Messaging, Supabase shines with lower costs, no vendor lock, a relational database, and performance. And actually, it was a pleasure to work with supabase so far.

We at UniNow, decided to use Supabase in the backend of our internal office app, called "UniNowtenApp". The main goal of the meetup was to showcase what supabase is capable of. (Spoiler: A lot!)
To do so, we extended the app with a new feature called "LunchBuddy", which goal was to display, in real-time, who was on the lunch screen. And within a press of a button a random buddy, which is also visiting the lunch screen, is assigned to you. The pair can now have lunch together.

(This feature is of course only for demonstration purposes and employees at UniNow can spend their lunch as they wish)

Create a real-time database

At first, we need a table, where we store the users, which are currently on a specific screen in the app. For that purpose, we need two columns.

  • id as the user id (foreign key to our user's table)
  • lunch_buddy as the user id of our lunch buddy (foreign key to our user's table, nullable)
Create meetup_lunch_buddy table

In supabase the access of tables and rows is managed by row-level security policies (RLS). We enabled this in our new table because we want to restrict access to authenticated users only.
Notice how easy it was to equip our table with real-time communication capabilities — just a tick.

Create Postgres function to get a random row

To match users randomly we want to retrieve a random row (except mine) of our lunch buddy table. We accomplished this task by defining a Postgres function.

And you can access the function on the client like this:

Create row-level security policies

We want to restrict access to our lunch_buddy table to authenticated users only, so no guest can steal information about who is lunching with whom.

For those who prefer a visual way of configuring, supabase covered you. They also provide templates to quickly get started with RLS.

Conclusion

Thanks to the auto-generated API, wiring all together is as easy as copying and pasting can be. And in no time we successfully created a new table, enabled real-time communication, configured row-level security policies, extended our Postgres with a new function to return random rows, and advanced the "UniNowtenApp" with the "LunchBuddy" feature.

As you can see, developing with supabase can be a real jump start for your project!

Thanks for reading!

We hope you learned something new about supabase and we want to encourage you to try it out by yourself — you won't regret it!

If you want to hear us live — take a look at the upcoming events.
https://uninow.io/

--

--