Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the integration with Firebase #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Implement the integration with Firebase #25

wants to merge 4 commits into from

Conversation

GavinQ1
Copy link
Collaborator

@GavinQ1 GavinQ1 commented Mar 10, 2024

What's changed:

  1. Implements the integration with Firebase

    • Saving and loading now use Realtime database
      • Save:
        Data is saved to the Realtime database under the arbitrarily defined /machines.json.
        Each record is defined as "<id>": { "machineJsonBlob": "<serialized machine state>" }.
        The <id> is generated by the Realtime database if none exists.

        The reason behind this design is that the Realtime database discourages nesting data structure [ref].
        Since our use case here is very simple, i.e., saving/fetching machine state by id, flattening the state to a JSON string seems to be the most straightforward implementation.
        We also wrap it in an object so that if we want to add some metadata in the future, we can add quickly without disrupting the existing structure.

        Note: optimization isn't really taken into consideration in the current design, given the constraints posed by the legacy code and the expected traffic/usage (which I think we can keep under free tier of firebase easily?).

          1. If the machine is new, issue a POST request and remember the unique return "name" as the newly introduced field machineId in the machine state.
          1. If the machine has id, issue a PATCH request to update the value. (a small improvement to the old mechanism which always saves as a new machine irrc)
      • Load:
        It finds the matched id from url and issues a GET request and load fetched machine if found, otherwise redirecting to /machine_not_found.

    • App is now serverless
      • Integrated with Firebase hosting
      • Unrelated code deleted (MongoDB, Express, Node backend).
  2. Setup deployment (manually)

    • Detailed in Readme.md

Caveats:

  1. Lack of the Realtime database security policy (database.rules.json)
    • Now it is accepting all clients for read/write. It can be potentially abused. (probably setup alerts if that's a concern; Firebase provides some nice integration I think)
  2. Other functionalities are only simply tested since their code are not touched. But since it is now Firebase Hosting, it'd be interesting to see a one time test on upload/download tests after deployment (though at least in my production deployment, they function without issue).

What's not changed:

  1. Still React 15
  2. No peer packages upgraded

What's not in scope of this cl:

  1. Clean up (a separate cl)
  2. Migration of data (not sure if that's needed, but I imagine it to be fairly simple script to load data from MongoDB, transform each record in the new structure (add machineId and then flatten), and post to Realtime db.

@GavinQ1 GavinQ1 requested a review from jodeleeuw March 10, 2024 20:21
@GavinQ1 GavinQ1 changed the title Implement integration with Firebase Implement the integration with Firebase Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant