Space Cloud and Firebase both aim at simplifying the app development process but have different approaches. In this post, we are going to compare Firebase with its open-source alternative - Space Cloud. But before we dive into it, let’s see what both of them has to offer.

What is Space Cloud?

To keep things simple,

Space Cloud is an open-source web server which provides instant realtime GraphQL and REST APIs on the database of your choice.

It provides ready-to-use APIs for databases, file storage, authentication and microservices, which you can consume directly from your frontend in a secure manner. So in most use cases, just making an Angular or React app using the Space Cloud APIs should be the only code you write!

To show your support ❤️, ️️ you can give it a star on Github.

What is Firebase?

Firebase is Google’s platform that helps you build, improve and grow your apps. It covers a range of hosted cloud services like authentication, realtime database, file storage and many more out of the box without you having to manage any infrastructure.

It initially started with the Realtime Database before getting acquired by Google and eventually became a platform. But till date, it is famous for its realtime database to the extent that people often confuse Firebase with a realtime database.

TLDR; Firebase is well suited for building:

  • Realtime applications (syncing data across devices)
  • MVPs since its fully managed.

However, if you are looking to build any advanced or enterprisy stuff, especially for the long run, then you are bound to hit one of the many limitations of Firebase as we are going to discuss throughout this post.

Note: We are limiting our discussion to using the database (Cloud Firestore/Realtime Database) part of the Firebase and not the entire Firebase platform.

Modelling relational data

Most real-life applications have relations. For example, a team can have many users, and a user can be in many teams. The ability to easily model these relations affects productivity and the confidence with which we build apps.

Here’s what Baptiste Jamin said about data modelling in Firebase -

Dealing with relations with NoSQL is hard, dealing with relations with Firebase is pain in the ass.

Modelling relations in Firebase is tricky. It started with the purpose of syncing data in realtime at scale. So relations are not a first-class concept but an afterthought. While other NoSQL databases have some clear guidelines/hacks around it, Firebase still doesn’t have a straightforward approach on this. There are lot’s of it depends scenarios.

Relational data in Space Cloud

The major problem with data modelling in Firebase arises from the fact that Firebase uses its proprietary NoSQL database.

Space Cloud, on the other hand, supports all popular SQL and NoSQL databases out there like Postgres, MySQL and MongoDB. So basically you can apply the decades best practices of modelling data around your favourite open-source database. You can directly create tables on your database using SQL or any of your favourite DB tools, and Space Cloud can introspect your DB schema to provide you with APIs on top of it. To make things easy for you, Space Cloud also provides a GraphQL based SDL so that you don’t have to touch your database for schema creation/modification.

Let’s take an classic example of a blog app where an author can have multiple articles. This is how you can model it in Space Cloud:

type author {
 id: ID! @primary
 name: String!
 articles: [article] @link(table: "article", from: "id", to: "author_id")
}

type article {
 id: ID! @primary
 title: String!
 body: String!
 author_id: ID! @foreign(table: "author", field: "id")
}

Note: Don’t worry if you are new to this syntax, you can read more about data modelling in Space Cloud later. You can also skip this GraphQL schema as it is entirely optional.

The most important benefits of using the above GraphQL SDL to model your data are:

  • Declarative nature: You tell Space Cloud what structure you want, and it enforces it without you worrying about the implementation.
  • Database agnostic: The SDL remains the same, irrespective of the database. Space Cloud handles the database-specific implementation to provide you with a consistent experience.

Querying capabilities

Querying limitations is one of the most complained aspects of Firebase. So if you thought that you are going to have some peace with Firebase after your hard-fought struggle of data modelling, wait till you hear this.

You can’t find all the kittens in your house that are not orange in colour

Wait, what? Yes, you heard it right. A simple NOT EQUAL TO query is also not supported in Firebase even after so many people complaining about its querying capability. And if you thought that you could meet all your kittens born between two dates then… (I don’t need to mention it). Forget about fancy stuff like aggregations and joins. So if your app anticipates even slightest sophisticated querying capabilities, you are better off without Firebase.

Querying in Space Cloud

Space Cloud’s querying capabilities are more flexible and advanced as compared to Firebase. Operators like ==, !=, >, <, >=, <=, in, notIn are all supported out of the box.

Since Space Cloud supports GraphQL, you can also query for multiple entities from your frontend in a single request saving you on bandwidth and network latencies. And if you are using the GraphQL API of Space Cloud, you can fetch relational data without writing the join statements explicitly:

query {
 author @postgres {
  id
  name
  articles {
   id
   title
  }
 }
}

Aggregations are not supported yet in Space Cloud. However, you can easily create views and/or integrate your custom code to perform any complicated stuff on your database that Space Cloud doesn’t support yet. So with Space Cloud, you are only limited to the querying capabilities of your database.

Pricing

Firebase has an always-free tier which you can later upgrade to a pay-as-you-go model. One of the reasons for the popularity of Firebase is - It’s free! You can make your entire app on Firebase and host it for free.

This freemium model of Firebase is what makes it attractive for startups. However, if you don’t want to recieve surprisingly huge bills later when you scale, you should understand its pricing well.

As with any SaaS or PaaS solution, Firebase becomes expensive at scale. But the real problem lies in understanding and predicting your costs.

Your costs with Firebase are drastically affected by the way you model and store your data in Firebase. One mistake while modelling can cost you thousands of dollars at scale. What this means is that you have to cross-check and optimize your data model for costs as well. This beats the whole purpose of rapid prototyping since you can’t just focus on your app any longer.

What’s the case with Space Cloud?

Space Cloud is a self-hosted open-source Backend-as-a-Service. You can download and run it anywhere (even on your laptop). A cloud-agnostic tool means that you are free to choose your favourite cloud provider. (You do need to pay the cloud provider in that case for the compute resources Space Cloud is consuming 😅. )

Tip: With most cloud vendors providing free credits on signup these days, you can easily recreate the freemium experience of Firebase for you in your initial days.

Yes, you do miss on the ease of getting started with Firebase as you would have to put some extra efforts from your side to manage and get your app running in the first place. However, this can go a long way in ensuring that you stay cost-effective at scale. (Added benefit: You don’t have to keep the pricing page open while developing your app 😛)

Note: Space Cloud is in a cloud-native tool. It’s cost-effective to scale Space Cloud as it scales horizontally. In most cases, the database you choose would be the bottleneck. So make sure you choose a cloud-native database like YugabyteDB if scalability is a concern for you.

Vendor Lock-ins

Needless to say that Firebase is a proprietary platform. Neither you know how it works internally nor do you have complete control over it.

And by the time you hit one of its many limitations and want to move away from it, it’s already late. Since Firebase enforces its custom data modelling (collections and sub-collections), porting it to any other database it not that straight forward. Even if you are migrating to some other NoSQL database, you would still have to make some changes to adopt the best practices of that database.

The major challenge, however, lies in migrating your codebase (your frontend) from Firebase. Not just you need to write a backend which was being automated by Firebase earlier, you also need to re-write all your client-side code since Firebase client SDKs can only understand and talk to Firebase. This task can soon become a nightmare if your application is consuming a lot of Firebase features.

Open-source + GraphQL = No vendor lock-ins

First of all, Space Cloud is entirely open-source. It comes with an Apache License like most other open-source tools. Which means Space Cloud is free to use for your lifetime. You can modify it, distribute it or even sell it!

Icing on the cake: You can even shape the roadmap and direction of Space Cloud. You can contribute by pull requests, creating Github issues and feature requests on Github and much more! Join our Discord channel to ask any questions or brainstorm any ideas that you may have!

Second, since you can consume Space Cloud via the standard REST and GraphQL libraries out there, migrating away from it (you wouldn’t want to in most cases 😛) is not that tricky. You would hardly need to change your frontend code. All you would have to do is build a backend that provides the same APIs that you are consuming.

Third, in most cases, you would like to stick to the same database while migrating away from Space Cloud. In such scenarios, you need to migrate your codebase only and not the database. Note that this is an improbable option in Firebase because Database limitations of Firebase are one of the prime reasons for migrations.

Conclusion

For beginners, Firebase is a time saver as it provides a realtime API without having to set up any backend at all. However, if you are a business or startup looking to do some serious stuff, you should seriously consider some other alternatives to prevent hitting the limitations of Firebase.

Space Cloud, on the other hand, is an open-source alternative to Firebase without its restrictions. You are free to choose your favourite database and cloud vendor, and it provides you with a better development experience in the longer run.

Take Space Cloud for a quick spin today and let us know how we can improve it. Don’t forget to give it a star ⭐️ if you like it!