Saturday, November 5, 2016

Firebase fever

Today I will share my experience and thoughts on Firebase.

Earlier this year someone approached me and asked that if costs (of a mobile app) could be decreased by using Parse.

I had no clue what Parse was, but my guess was that is a backend platform and didn't thought about it. All these years I have made my own Web APIs with PHP and MySQL and have been working great with Flash and Flex apps.

Fast forward in April I read that Parse was closing and everyone was starting looking for alternatives, that's when I investigated what Parse was.

Parse is a Backend as a Service provided by Facebook used my hundreds of thousands of developers. One day they suddenly decided to shut it down. No one knows why but one can speculate the obvious, it wasn't profitable enough.

At the same time I was investigating what was the fuzz about NoSQL and why it has been getting so popular. Basically it allows you save and retrieve simple datasets very fast.

I was starting to look around for a service that had a free tier that was good enough for learning, I found several services but all of them were pretty underwhelming until I found Firebase.

I liked that its free tier was fair and it had a well documented REST API. So I started using it and really liked how easy was to integrate it with ActionScript.

As you know you can't take things from granted, so I said that Firebase was good enough, but I still have my doubts to fully invest on it so I just kept toying around with their platform for the next weeks.

A month later Firebase switched from V2 to V3 and announced that they have been merged with some Google services. That's when I knew Firebase could be a good bet and started to get serious about it.

I developed some in-house projects to see how it compared with my previous stack (PHP + MySQL). And I was pleasantly surprised that the switch was smooth and almost painless.

Firebase offers several services for iOS, Android and Web, but only they have official documentation on Realtime Database using REST.

But that wasn't enough for me, I wanted to have Firebase Auth in my app so I couldn't have to do all the OAuth nonsense by myself (which I have also documented).

I began investigating if there was a method to login using only REST and yes there was a method. You needed to send some parameters to a special URL and listen for the responses.

To learn about this I created a simple app that stores To-Do lists that requires sign-up and sign-in to retrieve them.

Once I finished it I noticed that Firebase V2 was getting deprecated so I said to myself to not release it until I found out how to update it to V3.

Some weeks later someone found a way to do it in V3. When Firebase and Google merged they reused Google Identity Toolkit and named it Firebase Auth. The problem is that they left their documentation a bit incomplete so another round of trial and error was inbound.

This time I grabbed the JavaScript SDK and took a look. I found 4000 lines of minified JavaScript, thankfully string literals are not minified so I only had to search for certain keywords.

I figured out how the requests were made, how and what parameters needed to be sent and so on. I wish Firebase could document this but I now understand why they don't. It really was challenging understanding how their framework works at first, everything relies upon Access Tokens, Auth Tokens, id's, etc.

They made the choice to create very easy to use libraries so anyone could plug and play Firebase into their projects. That's fine and all but they are missing on people that don't use Java, Swift/Obj-C or JavaScript. You can easily use Firebase for a Windows/Mac/Linux game, console game or on a Internet of Things device.

Once I finished porting the ToDo app to Firebase V3, I thought to myself that it could be a waste to keep all this research for myself and that's when I wrote a comprehensive guide on how to use Firebase with only ActionScript and made several examples showcasing the most common uses.

Hopefully my efforts help a lot of people, I really was proud of what I made.