theagilecoder

theagilecoder

Comparing Phoenix and Firebase for building backends

First of all I love how easy Phoenix make working with rest apis and especially websockets. I have built a few simple android apps with the front end in react native and the back end in either Phoenix or Firebase; and in the process learnt both. I wish to share some of my learnings/questions comparing the two.

  • Real time stuff : Firebase makes showing the real time updates pretty easy. Any updates in the firestore is reflected easily in the front end. Cloud functions make running remote functions quite easy; though more line of code as compared to elixir and also if the app becomes popular then you have to pay up.

  • Dev Ops : Firebase doesnt need you to know devops. Working with phoenix I had to learn how to provision VPSs, install stuff, fight hacking attempts, deployment (boy, took me a week to get deployments working). Though, I cherish this knowledge and was fun learning all this.

  • Remote Push Notifications in android : Even when the backend was in Phoenix I had to integrate Firebase in the project only for push notifs. (I used pigeon elixir library to push notifs to firebase and then firebase pushes it to react native front end)

So I have been asking myself when would building the back end using Phoenix would be better than building it in Firebase for a RN app. I can see when the app has a huge number of users, then VPS would be much cheaper than Firebase. Also the joy of writing code in elixir has me spoiled. Other stuff such as concurrency and fault tolerance are there but I am not that advanced yet, so cant comment on that.

What would you say are the other upsides on building back end in Phoenix vis a vis Firebase?

First Post! Switch mode

krasenyp

krasenyp

I think you mix two concepts. Phoenix is a web framework, you build back-end systems with it and it has no assumptions on a database existence at all. Firebase is before everything else a storage service. Can you define business logic in Firebase? No. It seems you have a very superficial perception of what Phoenix is. There are a myriad of tutorials, articles and many books which can help you dive deeper into the framework.

Most Liked

holgerwiehen

holgerwiehen

Congratulations for comparing your backend options and for getting into Elixir / Phoenix.

I would say there is a significant upsides to a Phoenix backend, when going beyond a proof of concept / learning project. It is important to remember that an application with a real business behind it will face evolving requirements. Those imply in evolving the software.

When it gets to evolving the database schema over the lifetime of a software the differences between Phoenix with its plain relational database (often Postgres) and Firebase will show. They call Firebase a ‘schemaless’ database, right? In reality even a ‘schemaless’ DB has an implicit often even heterogeneous schema, as data has some form. When your changing business requirements demand that you migrate your persisted data to a new shape (schema) you are well covered by those tools the relational database you use with Phoenix offers. Firebase has no efficient solution to migrate the shape of thousands or millions data entries. So you will notice that you are trapped. It will be very difficult to evolve your application as business demands.

And even beyond data persistence, you are better positioned with Phoenix for a long lived project who’s code evolves. Even having serverless functions on Firebase for business logic, with Phoenix you have a cohesive package, full of tools like unit and integration tests. To keep complexity and correctness under control as your app evolves. A Firebase backend is more cobbled together. Cobbeling many simple services together is not simple, especially when maintaining the product on the long run.

In the end it all depends. If your project is a quick proof of concept, that does not back a business or you have no goal to evolve it, Firebase can be a good solution. But, thinking about professional development on a job or with an ambitious side project, you would probably choose a solution that makes software evolution productive and low risk.

I hope my answer contributed to your understanding. What do you think about those questions? How would you choose when you imagine yourself creating a product that backs a business?

Last Post!

holgerwiehen

holgerwiehen

If I remember right, Firebase’s main feature is that it seamlessly syncs value changes from the backend to the frontend, right? If you are interested to somehow replicate this behaviour with Phoenix you might want to read on GraphQL subscriptions as well as GraphQL mutations with the Absinth library for your Phoenix backend. On the frontend you would pair this with a library like Apollo Client.

But I would also like to encourage you to consider simpler solutions when you just need to get things done. Besides existence of well engineered solutions like the Firebase API and GraphQL APIs, you will get a long way with a simple JSON REST API on your Phoenix backend. Pairing this on your React / ReactNative frontend with a simple data loading library like SWR you get a really simple integration between your frontend and the backend with features like: fast and responsive UI, optimistic updates, local data caching with transparent refetching, http caching,…

It is great that you studying technologies like Web Sockets, Phoenix Channels,… that are usually involved when building rich realtime user experiences. But you might be surprised how something simpler like SWR data fetching and a REST API can produce a great user experience also with lot less complexity.

Where Next?

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2976 91332 914
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New

We're in Beta

About us Mission Statement