Giter VIP home page Giter VIP logo

mps3's Introduction

MPS3

โš ๏ธ Under development

Vendorless Multiplayer Database over any s3-compatible storage API.

  • Avoid vendor lock-in, your data stays with you.
  • Built for operational simplicity
    • no infra to setup and manage apart from the storage bucket.
  • Designed for correctness
  • Web optimized, 10x smaller than the AWS S3 browser client.
  • Offline-first, fast page loads and no lost writes.

Tested with S3, Backblaze, R2 and self-hosted solutions like Minio. Interactive demo available on Observable

Concepts

MPS3 is a key-value document store. A manifest lists all keys in the DB as references to files hosted on s3. Setting a key first writes the content to storage, then updates the manifest. To enable subscriptions, the client polls the manifest for changes. To enable causally consistent concurrent writes, the manifest is represented as a time indexed log of patches and checkpoints which is resolved on read.

Read more

MPS3 is built on strong theoretical foundations. Technical articles are written in /docs, some highlights:-

API

To use this library you construct an MP3S class.

mps3 class

Quick start (Codepen)

import {MPS3} from 'https://cdn.skypack.dev/[email protected]?min';

const mps3 = new MPS3({
  defaultBucket: "<BUCKET>",
  s3Config: {
    region: "<REGION>",
    credentials: {
      accessKeyId: "<ACCESS_KEY>",
      secretAccessKey: "<SECRET_KEY>"
    }
  }
});

mps3.put("key", "myValue"); // can await for confirmation

mps3.subscribe("key", (val) => console.log(val)); // causally consist listeners

const value = await mps3.get("key"); // read-after-write consist

CORS

For the client to work properly some CORS configuration is required on the bucket so the Javascript environment can observe relevant metadata.

[{
    "AllowedHeaders": ["*"],
    "AllowedMethods": ["GET", "PUT", "DELETE"],
    "AllowedOrigins": ["*"],
    "ExposeHeaders": ["X-Amz-Version-Id", "ETag", "Date"]
}]

Authorization

There is no in-built authorization. Every use-case needs different authorization. A malicious user could sabotage the manifest file if they have unrestricted write permissions to the manifest file, but not all use-cases have malicious users. There are a few options:-

  • Share access key only to trusted personal.
  • If using S3 and IAM, issue STS tokens that grant access to a subpath of a bucket per user/team
  • For public use, use a third-party auth solution and a authenticating proxy. Verify manifest changes are valid during passthrough, there is an example of an proxy configuration here that hides credentials from the browser using a CloudFlare worker.

Advanced Usage

Consult the API Documentation for advanced usage.

  • atomic batch operations
  • multiple manifests

mps3's People

Contributors

jaymakes11 avatar tomlarkworthy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jaymakes11

mps3's Issues

R2 test

Shoudl work with R2 but not tested yet

offline-first

We should serialize state for fast boot and for working offline

Fix causal consistency issues

Randomized testing is showing failures of the causal consistency checks. There seems to be a few race conditions when fetching content during notify.

import / forget and move keys

To help people connect existing content into the database, we should support importing a key (just a manifest update). The inverse is forgetting a key, and to help archiving keys we should have a move.

Detect clock skew

We can use the AWS created at timestamp to validate the manifest timestamp on read.

Bug: clock skew can break causal consistency

a participant can write into the future, making a local write mask the write until committed, when it then pops back into existence as the commited local write ends up temporally behind the existing future record. The invariant that local writes will end up at the head of the log is broken.

auth

its not super clear how to secure this. We should provide examples

If-not-changed

To build towards merge functionality, we should be able to conditionally write a document if there have been no changes to some other keys

Structured tracing

We should log in a structured way, maybe something like zipkin with a trace_id passed through on reads which can be added on puts for end-to-end tracing across clients.

gzip

we should optimize our bandwidth costs

Refactor manifest representation

Its a bit overfitted to the KV of JSON in s3 use-case, we should allow content-types, query ranges and arbitrary web-urls under a common logical keyspace.

Cache requests

We fetch the same immutable resources. Lets put an LRU in there

getAll method

GET should include a batch get which is a consistent snapshot. Would help testing too (e.g. parrallel puts)

Make offline/online togglable

We should be able to switch to offline mode dynamically. This should terminate any hanging GET requests and throw Offline exceptions.

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.