Best mobile app backend ?

Sergiu Rosu
4 min readJan 27, 2021

I will start with a question and the reason that article exists:

Is it firebase ?

Short answer ? “No! ”

In all transparency, I love Firebase and I was extremely excited to use it and felt like serverless is the future. I didn’t listen to the people saying that you can’t have them all and you need to trade somewhere, I’ll try to highlight what the tradeoffs are and if it is worth it in this article and hopefully you will be a better listener than me.

I have been working on several mobile projects in the last year and “luckily” for me most of them used different backend approaches and this gives me something to base may statements on.

This article is intended for small teams who want to create their own backend for the mobile app… if you are on a enterprise app, there are different approaches.

So, last year I created a brand new mobile app with Flutter and I decided to go serverless with firebase and I used everything I needed for the server part from the Firebase palette:

  • Authentication
  • Firestore
  • Cloud Storage
  • Cloud Functions
  • Crashlytics
  • Analytics
  • Performance
  • Notifications
  • App Distribution

everything is still working as expected there are no upfront problems.

Then why not ?

Performance

Cloud functions have a “cold start” which sometimes takes 7000ms that is huge, the app takes forever to do anything on the server.

Using cloud storage, every asset you load will need 2 steps, first to get the URL that download it, even for absolutely static assets which have to be really fast, they are really slow.

Each component is a micro service, so even if you use cloud functions with firestore and cloud storage, there is additional overhead on the response time.

Cost

Even if you have a free tier for development mode, when you go into production costs go really up.

I did some Cloud sql tests, for a few tests (about 12 hours of running) I got 2$ costs and it was only me testing.

Maintenance

Firebase libraries change pretty often… and in many cases they are not backwards compatible so code changes are required.

My Solution

I got a VM from Digital Ocean, it’s 5$/month which is much cheaper that using firebase.

Setup is easy, you will find tutorials with step by step instructions for everything you need, here is what I got:

  • Ubuntu 20
  • NodeJS
  • NginX webserver
  • letsencrypt SSL
  • mysql database
  • ufw firewall

with this setup I was able to remove most of the paid firebase tools and I’m now just using:

  • Crashlytics
  • Analytics
  • Performance
  • App Distribution

As you can see if you have NodeJS on your server you can just port your Cloud functions to your own server.

Also for search I was using Algolia Search but I’m now able to replace that with Sphinx running on the same machine, so costs will also be reduced on that part.

Performance

Overall in my case everything is almost 100x faster:

  • all static assets, configuration files are delivered by nginx as static assets which is extremely fast.
  • authentication (i added oauth2 on node) is done locally which removes that overhead (about 150ms on each request).
  • local mysql is much faster that cloud sql
  • caching for different queries can be done on server side and served statically

Cost

5$/month upfront, + $1 if you want weekly backups.

Maintenance

This is the only part which is on the “cons” side, as you will have to update everything manually when required, it’s not that often, I would say once every few months…

Scalability

On this part, definitely there is no VM or dedicated machine that will scale as Firebase, but realistically speaking, you can scale your VM high enough… if you get this point you probably have a big team and also a devops team to handle this.

Conclusion

I know that it sounds scary, but having a VM configured is very easy and in the long term you win on so many levels that even if you pay someone to configure it for you first time you still save a lot of time and money.

If you decide to walk the VM road, there are some articles I used to configure my own VM:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sergiu Rosu
Sergiu Rosu

Written by Sergiu Rosu

Software engineer, mainly on iOS with Swift, also working with Flutter for iOS and Android.

No responses yet

Write a response