Code Monkey home page Code Monkey logo

marmot-pocketbase-flyio's Introduction

Combining Marmot + PocketBase + Fly.io

What is Marmot?

Marmot is an distributed SQLite replicator that runs as a side-car to you service, and replicates data across cluster using NATS.

What is PocketBase?

PocketBase is an open source backend consisting of embedded database (SQLite) with realtime subscriptions, built-in auth management, convenient dashboard UI and simple REST-ish API.

What is Fly.io?

Fly is a platform for running full stack apps and databases close to your users. Compute jobs at Fly.io are virtualized using Firecracker, the virtualization engine developed at AWS as the engine for Lambda and Fargate.

Why should I care?

This demo effectively shows how PocketBase can be pushed closer to the edge. After developer has done local development, and finalized schema, a literal copy of the DB can be deployed in production. These nodes scale up or down based on traffic, and write from everywhere. This can horizontally scales your PocketBases close to the user. With NATS embedded into Marmot, a sharded RAFT is used to capture changes, and replay them across the fly nodes (multi-primary replicas).

Important Notes:

  • Cluster instances have to start with same DB snapshot - Since Marmot doesn't support schema level change propagation, tables, indexes you will be creating, deleting won't be picked up. Marmot only transports data right now! This repo ships with sample data snapshot that was created using local PocketBase instance, so it should give you good starting point. You only need schema of tables + indexes in order to see replication working. This should not be a no big deal because one can easily write a script to apply migrations (recommended way), use the backup to import old data, and deploy it as part of Docker image.
  • Change propagation is dependent on PocketBase committing to disk - Marmot can only propagate changes that are written to disk! Marmot does not use any hooks or anything into PocketBase process. As a matter of fact Marmot doesn't even care whats running along side with it.
  • This example doesn't use persistent volume - Base snapshot and logs in Marmot nodes should be enough to get you up and running every-time. You can configure Marmot with S3/Minio snapshots for higher reliability.

Install Flyctl

Deploy and Scale

  • Create Fly app using fly app create, fill in the information on prompts.
  • Deploy on app using fly deploy -a <application-name>, here application-name will be the name of app you created
  • Scale the app to multiple pods you fly scale count 3 -a <application-name>. At least have 2 pods for Marmot to start a cluster (in current configuration), otherwise Marmot would keep waiting for more nodes to come up.

Create Admin

Once cluster is started go to http://<application-name>.fly.dev/_/ to launch admin panel, it will prompt you to create an admin account. Choose your email and password. Once you hit create, it will create your admin account.

PocketBase might show you an error saying invalid token. If that happens just wait for a second or so to let changes propagate. Try reloading http://<application-name>.fly.dev/_/ until you see login form. If issue persists try creating account again.

Use the APIs

Now you can play with your app's API using http://<application-name>.fly.dev/api/. Checkout PocketBase Docs for deep dive.

marmot-pocketbase-flyio's People

Contributors

ducphuclee avatar javdl avatar maxpert avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.