Max Karlsson, smiling at the camera

The search for an alternative to Firebase

Published: August 20th, 2020

Firebase's main advantage is the ease of setup to get a system with real-time data sync, auth and access-control working. However, it's not without its limitations and doesn't fit every project. This post is an introduction to a series about MongoDB Realm and lays the foundation for why I searched it out. The coming parts of the series will dive deeper into the comparison between Realm and Firebase as I gain more experience with my new tools.

Background

I've recently started to work on an application with auth and real-time data requirements. In the past, I would have used Firebase for this, it's quick to get set up with, and it's easy to integrate. However, it doesn't scale well with complex data. It can become a severe bottleneck for your application. I recently read an article that said something along the lines of the time you save during setup with Firebase is just loaned, with sky-high interest rates, from your future self and your application.

I couldn't find that article for reference, so the words aren't exact, but that was the gist of it and something that resonated with my own experience of using Firebase.

I made an app to keep track of scores and stats for a floorball tournament down here in Melbourne last year, and I used Firebase for its real-time capabilities. The intent was to give everyone live updates to the games and scoring leaderboard. However, the data complexity of the stats meant that the more games that were played, the longer the page loads became as the client-side of the app had to fetch data from multiple sources. These sources, in turn, had other relations that needed to be requested. Without a powerful query language, the only way to filter was on the client, and without a way to get projections of relations in the data the client had to request more data from the backend as it filtered the stats.

A lot of those issues are NoSQL related – or related to my structure of the data, especially when it comes to relational data, but not all. In my experience, you can have performant NoSQL databases with relations – as long as the relationships don't become too complicated. So it seems that most of my performance issues with Firebase are related to their implementation, precisely, with the limited query capabilities. Something that almost seems built into their business model.

Search for alternative solutions

So I started to look into alternatives to Firebase and what I loved about the service. Things like real-time data sync between devices, almost automagical auth with multiple third-party providers and access control logic for the data.

I looked into services like HasuraFaunaDBPrisma and AWS AppSync. But neither of them completely satisfied my requirements. Hasura and Prisma are really interesting, each in their own ways, but they're not exactly what I was looking for. FaunaDB was close, but their auth was limited to email and password. AWS AppSync (along with Cognito and Lambda) would have been a match, but there was too much setup, and quite honestly, I want to avoid that awful AWS interface. Not to mention vendor lock-in.

That's when I found MongoDB Realm.

I've always loved MongoDB. It was the first database I used that made sense to me almost right away. I came into backend engineering from a pure frontend perspective. I was used to javascript objects and JSON payloads but had dabbled in SQL through WordPress.

Utterly contrary to traditional University wisdom, my first course that involved backend logic and data storage would use MongoDB, and I was hooked. The document store, object data model made perfect sense to me.

I knew MongoDB offered some sort of cloud service, but from memory, it was a bit complicated or unclear exactly how it worked. That might have been my own inexperience that clouded my understanding, however, so I decided to take another look. I typed in "MongoDB cloud" into Google and clicked the first result. Then it stared me in the face. MongoDB Realm. What was this mythical realm? It promised real-time data sync, auth and access-control, and I could use MongoDB! Of course, there's a certain degree of vendor lock-in with Realm as well, but the underlying database is not. You can host a MongoDB instance – or cluster – anywhere. You even get to chose between the big three cloud providers when you start a Realm project.

I took a few days out of my weekend about a month ago to trial it. While I felt the initial setup was a bit more complicated than that of Firebase, it looks to be far more capable and scalable, which prompted me to push for it in my current project.

If you are interested to know more about Realm and how it stacks up against Firebase, keep an eye on this space, and follow me on Twitter: @BeppeKarlsson.

© 2020 Max Karlsson