Firebase: Realtime Chat

Firebase provides a robust infrastructure for realtime communications (including, chat, online gaming, monitoring, data streaming and many more). The most popular example of realtime communication is probably chat applications, always. In this article, we are going to go through Realtime Database (RTDB), and Firebase authentication.

Realtime Database

Realtime Database is core behind the realtime infrastructure (although recently, Cloud Firestore is released, which is meant to be the next generation for realtime database). It provides a database which has a JSON-like structure, and for every change to the database, every subscriber receives an update. This is the very fundamental behind realtime database.

Data in database is protected using a simple yet powerful set of rules. An example may look as follows.

{"rules":{"users":{"$uid":{".write":"$uid === auth.uid"}}}}

Firebase Authentication

Firebase authentication, on the other hand, provides the authentication infrastructure for Firebase services. It will be really difficult to skip firebase authentication, and utilize another firebase service, because, these are designed in a way so that they are deeply interlinked.

Firebase authentication allows user to be logged in or signed up using a number of methods which covers pretty much most of the usage scenarios.

For custom authentication, it also supports token based authentication, where app server works as the authentication server, and it feeds firebase authentication a JWT token to authenticate. This method is very flexible, thus supporting majority of the exisiting applications.

That's basically what it takes to prepare a chat application using Firebase. The power here is simplicity, and of course not to mention the completely managed infrastructure.

The entire project is hosted here. Please raise an issue, if you have any trouble with the project.

One of the primary advantages of using Firebase is that, it supports major platforms and provides SDK for several highly popular languages. The infrastructure is supported with good quality documentation, so getting started with a service is mostly hassle free. The learning curve is also not that steep. Finally, for a realtime application, Firebase can be considered as a one stop solution, if cost of the services doesn't matter that much.