A Little Kindling for Your Firebase

Published Jun 16, 2017
A Little Kindling for Your Firebase

Firebase is a database that I’ve avoided for a long time. I believed that the more specialized, optimized, and scalable the database was, the better. But I met a user on Codementor that reminded me the beauty and importance of simplicity.


The Firebase Console

PhpMyAdmin, an open source administration tool, was wonderful for understanding how my tables were structured and modifying data directly. Since alternative databases are trendy, many don't use anything with the same level of GUI control. But within the Firebase console, you can view the following:

Screen Shot 2017-06-09 at 6.39.34 PM.png

Firebase was Made for Live Environments

In today's UI world, it is important and convenient to have a database that reacts to events, immutable states, and services. With Redux, it becomes easy to set up Firebase to directly set giant objects with new values. Or if you're listening to single values, that too can be done.

Another advantage is that Firebase was made as a minimum viable product, so the setup is incredibly simple.

The Firebase Ecosystem:

  • Hosting with Firebase app
  • Lambdas with Firebase functions
  • Notifications with Firebase cloud messaging
  • KV database with Firebase
  • Blobs with Firebase storage



This has been one of my biggest gripes and has led me to believe I may be better off implementing a pub/sub with Firebase functions rather than doing it in the client. The filtering and sorting is relatively simple and only works on single keys.


More often than not, you will want to specify keys (and maybe a summary) of other items on an item, then make additional Firebase requests as you need them.


Say I have a list that I want to be kept up to date with another list:

var listRef = firebase.database().ref("/my-list");
listRef.on("value", function(snapshot){

Simple enough. But I only want to subscribe to them 10 at a time:

var currentNum = 0;
var prevRef = null;
var refs = [];
var totalSnapShot = {};
var lastKey = null;
function nextPageRef(cb){
  var ref = firebase.database().ref("/my-list")
  currentNum += 10;
  prevRef = ref.limitToFirst(currentNum);
  return prevRef;

However, the above code doesn't consider how you want to deal with duplicate values, removals, or updates. It simply provides you a list with the next ten.


  var value = snapshot.val();
  handleArray(Object.keys(value).map((k)=> value[k]));

Almost every time I want to use a list as a list, this is a must. Lodash's support for objects looks much more appealing when the code starts to be to filled with this boilerplate code.

Having the Automated Key Available on Each Item

var ref = firebase.database().ref("/some-page").push({})
  key: ref.key

I haven't looked into if this makes two HTTP calls or just one, but this has become quite normal for when I am helping others.

Additional Resources

Discover and read more posts from Sam Tobia
get started