I've fallen in love with Firebase

Post date: Mar 31, 2015 6:48:3 AM

Last week we attended an event at Google France on Firebase: "Firebase and Angular - Build Realtime Apps" - thanks a lot to the GDG Paris team for organizing those events ;) Firebase is a BaaS solution (Backend as a Service), acquired by Google last October and targeting developers who need to store and sync data in realtime (eg chat apps).

In a previous post, Time-consuming tasks and Google Apps Script Add-ons, we've seen how to process big tasks in small batches with Apps Script and the HTML Service.

If you take a look at the list of add-ons available for Google Sheets, you'll see a lot of them do one of two things:

Those tasks can take some time to complete. Usually up to a few minutes and it's important to let the user know what's going on. So previously we were doing some back and forth requests between client and server to update a status / number of items processed. But it was a bit slow and inefficient (we were incrementing numbers stored as Properties in Apps Script but they aren't meant to be updated in realtime). Now with Firebase, it's very easy to let the user know in realtime what's going on.

On server side (in your .gs file), you can use the UrlFetch service to write in Firebase and on the client side (in HTML Service), you can use Firebase JS client library to watch for changes and automatically retrieve new values (thanks to the IFRAME mode in the HTML Service that let you use external JS libraries!)

var ref = fb.child(userKey+"/nbOfEmailsSent");

ref.on("value",function(data){

document.getElementById("nbOfEmailsSent").innerHTML =data.val();

});

on() is used to listen for data changes at a particular location. This is the primary way to read data from Firebase. Your callback will be triggered for the initial data and again whenever the data changes. Use off( ) to stop receiving updates. See Reading Data from Firebase for more details.

It's very easy to play with Firebase from Apps Script but we will also soon share an example + library to connect to Firebase from Apps Script (server side) to make it as simple as possible.

Note that, like a lots of other BaaS solutions (Parse Core,...), Firebase has a free plan available, so you should be able to use it for free. For me, the first limitation was the number of concurrent users: in the free version you can't have more than 50 people requesting data stored in your Firebase database at the exact same time, and YAMM has apparently more concurrent users than that (peak at 68 as of today) :P

This is just one example of using Firebase with Apps Script but we should soon share a lot of other use cases!