Skip to content

Overall Architecture

Sam edited this page Mar 23, 2019 · 2 revisions

Serverless and Firebase

Unlike traditional web applications that have a clearly defined frontend or backend boundary, the Samwise team uses the serverless approach.

Firebase is a serverless solution that abstracts away the need for a server. It does authentication and database operation on the client side, but still enforces security on the Firebase-managed server side via security rules.

In the current version of Samwise, we use Firebase Auth to authenticate users and Firestore to store user information. Data integrity and security are enforced by the firebase security rule here. We adopted Firebase to satisfy our need for an efficient and correct realtime data syncing system.

We also use Firebase functions to perform non-critical analytics tasks.

Current Setup Diagram

[Frontend] <-> (subscribes and push changes) <----
- handle user inputs                             |
- display data                                   |
                                                 |
  -----------------------------------------------|
  |
  \/
[Firestore] --> (push db events) -----------------
- efficient, strongly consistent db              |
- the single source of truth                     |
                                                 |
  -----------------------------------------------|
  |
  \/
[Firebase Functions]
- performs analytics computation based on db events

Discussion

The setup as described by the diagram above fully leverages the advantages of serverless computation.

We are able to get a state-of-the-art data syrchronization system for free due to Firestore. Since Firestore is a fully-managed solution, we do not need to pay the cost of high-performance server dedicated to these real-time syncing when there is little or no users.

The firebase security rules have some limitations that restrict the types of conditions we can check before writing the data. Fortunately, all of our user operations are not affected by these limitations and we can always use Firestore to sync user data in real-time. Correctly and securely writing analytics data is affected by this; however, we can still use Firebase functions to do all the necessary check on the server-side. Although Firebase functions have a cold-start problem, it does not matter since the response time of non-user-facing analytics functions does not matter.