brillout / research

5 stars 0 forks source link

A new kind of database: event-based + computed props + full-stack reactive + solid business model #2

Open brillout opened 2 years ago

brillout commented 2 years ago

Someone shares an image on Facebook:

  1. Database saves event "User X shared image https://example.org/image.jpg".
  2. Facebook defined a computed prop that downloads the image and meta data.

Someone clicks on the like button of the image:

  1. Database saves event "User Y likes image".
  2. Facebook defined a computed prop "total amount of likes" (the computed prop is just a JavaScript function that runs Math.sum() over the array of "User like" events) => the databse automatically re-runs the computed prop function => the computed prop is automatically updated.
  3. Row-level permissions:
    // Read
    export async function read({ row, context }) {
      if (context.user.role === 'admin') {
        return true
      }
      if( row.rolesAllowed.includes('public')) {
        return true
      }
      // Forbidden
      return false
    }
    // Mutations
    export async function write({ row, rowBefore, context }) {
      if (row.authorId === context.user.id) {
        return true
      }
      // `rowBefore` is `null` if mutation is `INSERT`
      if (rowBefore === null) {
        return true
      }
      return false
    }
  4. The database has a built-in ORM with deep UI framework (React, Vue, ...) integrations.

     import { useDb } from '@new-kind-of-database/react'
    
     function Image({ id }) {
       // `useDb.findOne()` is a React Hook (=> works with Suspense parent loader component)
       const { src, totalLikes } = useDb.findOne(id, select: {
         src: true,
         // We mark `totalLikes` as reactive => when `totalLikes` changes, the ORM
         // automaticallly updates the component (using React's hook system)
         totalLikes: 'reactive'
       })
    
       return <>
         <img src="{src}" />
         <p>
           Number of likes: {totalLikes}
         </p>
       </>
     }

    Everything is done automaticallly, e.g. the database automaticallly creates a socket connection to the server in order to listen to the corresponding database updates.

This leads to many drastic DX improvement, especially for user-centric highly-reactive apps such as Twitter or Facebook.

Solid business model: offer a SaaS with all bell and whistles (automatic scale, automatic backup, etc.). That said it's of paramount importance to fully support self-hosted, and open sourcing the entire source code (include of the SaaS). We are not afraid of AWS doing a SaaS clone; users will prefer the original over the AWS copy-cat.

If you feel drawn to work on this, let me know. Also, I'm ok with you being the CEO and me only being the "master mind" behind the whole thing.

trusktr commented 2 years ago

cc @davedbase this is what we're were talking about with solid.js primitives