Sangre - Sangre streams your backend queries in realtime to your clients minimizing the load via diffs

Overview
Logo

Sangre


Sangre streams your backend queries in realtime to your clients minimizing the load via diffs.

Sangre lives with your current backend framework (expressjs, django, rails, etc.)

About The ProjectHow it worksInstallationContactAcknowledgments

Generic badge Generic badge Generic badge

Example

This example is based on dart but feel free to imagine in your own language.

void main() async {
  final app = await setupMyApp(); // expressjs, django, rails

  // Setup node
  final followedNode = await DBNode('users').get('id', 1).joinMany(
        'followeds',
        fromNode: DBNode('users').joinMany(
          'places',
          fromNode: DBNode('places'),
        ),
      );

  // Plug the node to an endpoint
  app.sangre('/followeds', followedNode);

  await app.listen();
}

This exposes a websocket endpoint streaming the user (id==1) with its followed users populated with their places.

The websocket streams the updates as this data changes in the database. See working example here.

About The Project

Sangre provides a generic solution for streaming complex backend queries to clients in realtime.

A complex query is an arbitrary nested query of structured database data and processing of this data in your native backend language (js, python, etc.)

The result of such query is streamed to client using incremental updates, minimizing network load, and enabling offline sync.

Typical use case is a client-server topology, a mobile or web app consuming an API (expressjs, django, rails, etc.) in front of a database (postgres, mongo, mysql, etc.). You want realtime data in your app without all the complexity of developing your own data sync.

Sangre implements all the following features and let the developers focus of business logic.

Features
Realtime processing of relational database query + abitrary transformation ✔️
Client streaming over websocket ✔️
Offline sync for clients ✔️
Minimal network load (incremental updates) ✔️
Can be embedded into an existing project ✔️
You need to adopt a new database

How it works

Sangre is an acyclic graph of operator nodes acting on data. This data flows in those nodes as streams of data for reactivness.

Nodes may be filters, joins, populators. Root nodes provide data from the underling database (typically postgres) and listen to changes (via supabase realtime) in order to spread them down the data flow. Leaf nodes are the endpoints consumed by client apps (via websocket).

Sangre data flow

Limitations (alpha)

Note: Dart is temporary, TypeScript might be the final implementation. I just happened to have my head in Dart when starting the PoC.

At this point, Sangre is just a PoC. A lot of shortcuts have been taken to produce a working example. Here are known limitations, if you think about any other, please reach me out via my contact info.

Limits to overcome Feasibility
Horizontal scalability ✔️
Observability ✔️
Upqueries ✔️
Language agnostic (needs implementation in each)
Strict consistency
Parametrized queries ✔️
Share nodes between similar queries ✔️

Diff algorithm is currently JSON patch. This can be easily changed for a more readable or effecient one (myers, histogram, yours ?)

Installation (TODO)

Note : only postgres supported ATM (more to come)

Note : You can use docker-compose.yml to get a working example running

1. Enable postgres replication (TODO)

ALTER SYSTEM SET wal_level = logical;
CREATE PUBLICATION supabase_realtime FOR ALL TABLES;

2. Install realtime broker (TODO)

insert supabase realtime installation steps

Contact

Generic badge

Project Link: https://github.com/pomarec/sangre

Acknowledgments

You might also like...

A small library support load infinite for ListView - GridView on Flutter.

A small library support load infinite for ListView - GridView on Flutter.

Paging A Flutter package that supports pagination(load infinite) for ListView, GridView Demo DataSource PageKeyedDataSource To create a PagingListView

Dec 4, 2022

Simple flutter package to load and search string.

Simple flutter package to load and search string.

flutter_text_viewer flutter_text_viewer is a simple text viewer package to load and search text from assets,file. Demo Features Load text from assets/

Dec 15, 2022

A command-line application provide an load optimization solution for flutter web

A command-line application provide an load optimization solution for flutter web

一个命令行工具,针对flutter web加载慢和缓存问题提供了一套解决方案。 功能 通过大文件分片和资源文件cdn化方式,优化flutter web页面加载慢问题。 通过资源文件hash化,解决浏览器强缓存导致功能无法更新问题。 开始 局部安装 dev_dependencies: flutte

Dec 29, 2022

Package your Flutter app into OS-specific bundles (.dmg, .exe, etc.) via Dart or the command line.

flutter_distributor Package your Flutter app into OS-specific bundles (.dmg, .exe, etc.) via Dart or the command line. The flutter_distributor source

Dec 24, 2022

A Dart Build Plugin that uploads debug symbols for Android, iOS/macOS and source maps for Web to Sentry via sentry-cli

Sentry Dart Plugin A Dart Build Plugin that uploads debug symbols for Android, iOS/macOS and source maps for Web to Sentry via sentry-cli. For doing i

Jan 4, 2023

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter.

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter.

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter. Need help? Please do not submit an issue for a "

Jan 8, 2023

💳 A Flutter package for making payments via credo central. Provides support for both Android and iOS

💳 Credo Package for Flutter TODO: Put a short description of the package here that helps potential users know whether this package might be useful fo

Dec 26, 2021

Dart wrapper via `dart:js` for webusb

Dart wrapper via dart:js for https://wicg.github.io/webusb/ Features canUseUsb g

Jan 25, 2022

Helper app to run code on Aliucord iOS via websocket.

aliucordebug A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Jan 25, 2022
Owner
P.O.M
P.O.M
Official Sonr Blockchain Node implementation with Frontend Clients to access Wallet.

Sonr Blockchain Sonr-Chain is a blockchain built using Cosmos SDK and Tendermint and created with Starport. Get started starport chain serve serve com

Sonr 625 Dec 29, 2022
Small application where I worked with streams, firebase database, sorting, adding, modifying and deleting data.

messenger_app Small application where I worked with streams, firebase database, sorting, adding, modifying and deleting data. Features Provider: takin

Danil Shubin 2 Dec 19, 2021
Multi-Camera-Dashboard - Flutter App to View RTSP Streams

9.9.2021 update I have updated the firebase db to be read only due to abuse. The save operation works if you import your own firebase and modify proje

Mitch Ross 54 Jan 1, 2023
GeoLocationStreamsExample - Example of using streams with GeoLocator Package

geo_loc_stream A simple Flutter project I used to practice using Streams. Gettin

CypherZox 3 Nov 24, 2022
An Event Bus using Dart Streams for decoupling applications

Event Bus A simple Event Bus using Dart Streams for decoupling applications. GitHub | Pub | Demos and Examples Event Bus Pattern An Event Bus follows

Marco Jakob 700 Jan 4, 2023
A flutter plugin exposing streams to android and iOS enviroment sensors (temp, light, pressure, humidty)

enviro_sensors A plugin that enables calling native device enviroment sensors. Readings are sent over an EventChannel and can be accessed with a liste

Barbadose 6 Feb 10, 2021
Flutter dynamically load translation in your app.

Flutter dynamically load translation in your app.

null 1 Apr 4, 2022
A font loader to download, cache and load web fonts in flutter with support for Firebase Cloud Storage.

Dynamic Cached Fonts A simple, easy to use yet customizable font loader to use web fonts. Demo: https://sidrao2006.github.io/dynamic_cached_fonts ?? I

Aneesh Rao 18 Dec 21, 2022
A library for widgets that load their content one page (or batch) at a time.

A library for widgets that load their content one page (or batch) at a time (also known as lazy-loading and pagination). Features Load data one page a

null 224 Oct 20, 2022
A flutter widget that provides pull-down refresh and pull-up load.

flutter_easyrefresh English | 中文 正如名字一样,EasyRefresh很容易就能在Flutter应用上实现下拉刷新以及上拉加载操作,它支持几乎所有的Flutter控件。它的功能与Android的SmartRefreshLayout很相似,同样也吸取了很多三方库的优点。

KnoYo 3.4k Jan 8, 2023