Firebase and Supabase are two of the most popular backend-as-a-service (BaaS) platforms. While at Makerkit we started by using Firebase for our original SaaS kit, we are now also working to support SaaS kits based on Supabase.
In this article, we will compare Firebase vs Supabase to help you decide which one is better for your next project, so you can choose the right kit for your needs.
Makerkit is a SaaS boilerplate to build a SaaS using Firebase or Supabase. It's a complete solution that includes a landing page, a dashboard, and a billing system. It's built with React, Next.js or Remix, Tailwind CSS, and TypeScript.
What is Firebase?
Firebase is a BaaS platform that provides a set of tools and services to help you build and run your app. It is developed by Google and is one of the most popular BaaS platforms.
Firebase offers a wide range of services, including:
- Authentication
- Realtime Database / Firestore
- Storage
- Hosting
- Cloud Functions
- Cloud Messaging
- Performance Monitoring
- Remote Config
- Analytics
What is Supabase?
Supabase is an open-source alternative to Firebase. It is a BaaS platform that provides a set of tools and services to help you build and run your app. It's backed by YC and Mozilla and is one of the fastest-growing BaaS platforms.
Supabase also offers a wide range of services, including:
- Authentication
- Realtime Database / Postgres
- Storage
- Functions
Features
When it comes to features, it's clear that Firebase has the upper hand, as it offers more services than Supabase.
However, Supabase is catching up fast and is adding new features regularly. It's also worth noting that many Firebase services only work for mobile apps, such as Crashlytics, ML, Dynamic Links, and others.
If you're building a web app, Firebase and Supabase will offer you a similar set of features.
Authentication
Firebase and Supabase both offer complete authentication services that offer a variety of authentication methods, including email/password, phone, magic link, Google, Facebook, Twitter, and GitHub.
Firebase also offers anonymous authentication, which is not available in Supabase. This can be useful if you want to allow users to use your app without signing up.
There isn't a large difference Firebase and Supabase when it comes to authentication. Both platforms offer an exceptional set of features and are easy to use.
Database
Firebase offers two database options: Realtime Database and Firestore. Realtime Database is a NoSQL database that stores data in JSON format. Firestore is a document-based database that stores data in JSON format.
Firestore DB
Firestore allows us to write and read data directly from the clients without having to write any server code by writing security rules.
Supabase Postgres
Supabase offers a managed Postgres database.
Postgres is one of the most popular and battle-tested relational databases that stores data in tables.
Supabase also supports client-side reads and writes by allowing developers to protect their database using Postgres Row Level Security (RLS): these rules allow us to control who can read and write data using SQL.
Firestore vs Postgres
Firestore and Postgres are two different types of databases. Firestore is a document-based database that stores data in JSON format. Postgres is a relational database that stores data in tables.
I would recommend using Firestore if you're not experienced with SQL and relational databases. Firestore is simpler to use, and most importantly easier to secure: Firestore security rules are arguably much simpler than Postgres RLS.
However, if you're experienced with SQL and relational databases, then Postgres is the better option. Postgres is a battle-tested database that is used by many large companies, allows us to write complex queries, can allow us to use full-text search, and is better when it comes to data integrity.
Simply speaking, Firestore is better for beginners, and Postgres is better for experienced developers who have already worked with Postgres and SQL.
This does not mean Firestore is not a good option for experienced developers: if your data structure is valid for NoSQL and you don't need to write complex queries, then Firestore is a great option.
Realtime
Firebase and Supabase both offer realtime database services, but there are differences worth noting.
Firebase Firestore Realtime Database
Firebase's realtime queries allow us to listen to changes in the database and receive updates in real-time: the updates include the full snapshot of our query.
The ability to receive real-time snapshots of a query is incredibly useful since we don't need to write any client-side code to manage state and reconcile changes.
The UI will automatically reflect the changes in the database using the snapshot from the realtime query.
Supabase Postgres Realtime Database
Supabase's realtime works differently, and it's not as straightforward as Firebase's realtime queries.
It uses a pub/sub system that allows us to listen to changes in the database and receive updates in real-time. Updates do not return the current snapshot of the original query, but rather they indicate what changed in the database. This means that we need to write client-side code to manage the state and reconcile changes.
The UI will not automatically reflect the changes in the database, but we need to write code to update the UI.
When it comes to real-time changes, Firebase is the clear winner.
Self Hosting
Many developers may want to self-host their app, be it for security reasons or scalability.
When it comes to self-hosting, the answer is simple: Firebase does not allow us to self-host our app, while Supabase does.
If self-hosting is important to you, then Supabase is the better option.
Local Development
Firebase and Supabase both offer a local development environment that allows us to run our app locally. This is incredibly useful since we can test our app locally before deploying it to production.
Firebase offers a local emulator that allows us to run the Firebase services locally: it's a bit of a black box, and we cannot see what's happening under the hood. It works fairly well though, and it's feature-complete these days.
Supabase allows us to run a self-hosted instance locally using Docker. It still lacks some features but is getting better every day.
Both services offer a local development Admin UI.
SDK
Firebase and Supabase both offer a complete set of SDKs. Generally speaking, they're both very valid options.
Firebase's SDK is more mature and has more features. It's split into multiple packages for each feature. This was necessary so that we could tree-shake the library and reduce the bundle size.
Supabase's SDK, instead, has a much smaller API surface, it's more lightweight and simpler to use.
Isomorphic SDK
Firebase's SDK is split between Client SDK and Admin SDK. When we use the SDK in our API functions, or when server-side rendering, we cannot use the client SDK, but we're constrained to use the Admin SDK.
This has a lot of disadvantages, especially when it comes to server-side rendering (SSR): in fact, we are forced to write separate queries for the client and the server, and we cannot use the same query for both. This leads to more code and more complexity.
Instead, the Supabase client SDK is isomorphic, which means that we can use the same SDK both on the client and on the server. This allows us to write less code and have a simpler architecture.
Edge Environments
Supabase has a clear advantage over the Firebase SDK: in fact, it can be used in edge environments, such as Cloudflare Workers and Deno. Instead, Firebase's SDK is only available for Node.js and the browser.
What does it mean? It means that by allowing us to use Supabase in edge environments, we can use Supabase to build serverless applications that run on the edge. This can unlock incredibly fast performance and reduce costs.
SDK: which one is the winner?
While the Firebase SDK is more mature and has more features, the Supabase SDK is more lightweight and simpler to use. Additionally, it allows us to use the same SDK both on the client and on the server and in edge environments which is a huge advantage.
Personally speaking, I prefer the Supabase SDK.
Conclusion
Firebase and Supabase are both great BaaS platforms. They both offer a complete set of features and are easy to use. Ultimately, since they offer a similar set of features, the choice between Firebase and Supabase will depend on your use case, your preferences, and your experience.
When to use Firebase
Here are some examples of use cases where Firebase is a better option:
- If you're building a mobile app, Firebase offers more features than Supabase
- If you're a beginner and you're not familiar with SQL and relational databases, Firestore is a better option than Postgres
- If you prefer not to manage client-side state and rely on real-time features to automatically update the UI, Firebase is a better option than Supabase
- If you prefer to use a more hands-off service, Firebase is a better option than Supabase
When to use Supabase
Here are some examples of use cases where Supabase is a better option:
- If you want to use Postgres and leverage better data integrity, more complex queries, and full-text search, Supabase is a better option than Firestore
- If you want to use the same SDK both on the client and on the server, Supabase is a better option than Firebase
- If you want to use Supabase in edge environments, Supabase is a better option than Firebase
- If you want to self-host your BaaS, Supabase is a better option than Firebase
- If you want to use a BaaS that is open-source and transparent, Supabase is a better option than Firebase