Backend for frontend developers: BaaS

Backend as a service( or BaaS) is a kind of service that lets developers ease the process of developing a backend. It is a cloud-based service that provides developers with a ready-to-use database, a notification system, automated oAuth system etc.

There services are becoming very popular these days. A good example of such a service is Firebase by Google. So in this article, we are going to talk about how Firebase can make the lives of front-end developers easier and also help in quickly prototyping an idea and building a working demo.

The main features of Firebase include a real-time database, authentication, storage, hosting and much more. these features can easily be managed with the help of Firebase console.

Summary of some of the features:

  • The real-time database as the name suggests is a database that allows real-time syncing of data, with the front-end, right out of the box. It follows the noSQL format which is also in trend these days. A noSQL format stored data in the JSON format unlike SQL where data is stored in tables.
  • Authentication with Firebase uses oAuth2 and is very simple to use. It comes with simple email/password login and social logins like Google+, Facebook, Twitter etc. It also provides a table of users that have registered for your app. This table is searchable and capable of adding and deleting users.
  • Storage allows users to upload their file to firebase.
  • Hosting allows developers to host their static content on firebase itself. Static files include HTML files, CSS files, JavaScript and assets like images.
  • These features take a lot of time to build from scratch. So it is easier to just use these services to quickly build a prototype or a demo.

Firebase provides SDKs for a lot of different languages. The JavaScript SDK it provides is so easy and fun to use. Especially with the real-time database, the website/web app can be made dynamic very easily.

The database doesn’t just allow you to fetch data, but it also provides a listener that fires when any modification is made to the database. This is really cool since it is very difficult to do that also from scratch.

I personally like using a combination of JavaScript and Firebase in hackathons as it helps you rapidly implement the idea that is in your mind. This helped me secure the 2nd place in 2 hackathons where I built very lite web apps.

Since most of the work happens on the client side with JavaScript, the data transfer to and from the cloud is very less. So the required bandwidth is also less. Also, it works flawlessly in a 2g connection.

Now for some sample code:

  • Storing data in the database
    function writeUserData(userId, name, email, imageUrl) {
      firebase.database().ref('users/' + userId).set({
        username: name,
        email: email,
        profile_picture : imageUrl
      });
    }
  • Retrieving data from the database
    var starCountRef = firebase.database().ref('posts/' + postId + '/starCount');
    starCountRef.on('value', function(snapshot) {
      updateStarCount(postElement, snapshot.val());
    })

Resource for learning:

The best resource for learning to use Firebase is the playlist on Firebase on the web by the official Firebase channel.

Really amazing a disruptive tech can be built with these kinds of services. Although it may not be too stable for use in production, it can definitely be a rapid prototyping tool. So what will you build with firebase or any other “Backend as a service”? Let me know in the comments.

Arjun Mahishi
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments