All Projects → pubkey → Event Reduce

pubkey / Event Reduce

Licence: mit
An algorithm to optimize database queries that run multiple times

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Event Reduce

Rxdb
🔄 A client side, offline-first, reactive database for JavaScript Applications
Stars: ✭ 16,670 (+2730.22%)
Mutual labels:  database, realtime-database, realtime
Sapphiredb
SapphireDb Server, a self-hosted, easy to use realtime database for Asp.Net Core and EF Core
Stars: ✭ 326 (-44.65%)
Mutual labels:  database, realtime-database, realtime
Realm Kotlin
Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Stars: ✭ 156 (-73.51%)
Mutual labels:  database, realtime-database
Space Cloud
Open source Firebase + Heroku to develop, scale and secure serverless apps on Kubernetes
Stars: ✭ 3,323 (+464.18%)
Mutual labels:  database, realtime
Realm Cocoa
Realm is a mobile database: a replacement for Core Data & SQLite
Stars: ✭ 14,778 (+2409%)
Mutual labels:  database, realtime
Statecraft
Manage state with finesse
Stars: ✭ 145 (-75.38%)
Mutual labels:  database, realtime-database
Realm Java
Realm is a mobile database: a replacement for SQLite & ORMs
Stars: ✭ 11,232 (+1806.96%)
Mutual labels:  database, realtime-database
Redwood
A highly-configurable, distributed, realtime database that manages a state tree shared among many peers.
Stars: ✭ 218 (-62.99%)
Mutual labels:  database, realtime-database
Realm Dotnet
Realm is a mobile database: a replacement for SQLite & ORMs
Stars: ✭ 927 (+57.39%)
Mutual labels:  database, realtime
acebase
A fast, low memory, transactional, index & query enabled NoSQL database engine and server for node.js and browser with realtime data change notifications
Stars: ✭ 288 (-51.1%)
Mutual labels:  realtime, realtime-database
Opennars
OpenNARS for Research 3.0+
Stars: ✭ 264 (-55.18%)
Mutual labels:  database, realtime
Directus
Open-Source Data Platform 🐰 — Directus wraps any SQL database with a real-time GraphQL+REST API and an intuitive app for non-technical users.
Stars: ✭ 13,190 (+2139.39%)
Mutual labels:  database, realtime
Next
Directus is a real-time API and App dashboard for managing SQL database content. 🐰
Stars: ✭ 111 (-81.15%)
Mutual labels:  database, realtime
Bicing Api
Get statistics and locations of bicycle stations through REST API
Stars: ✭ 149 (-74.7%)
Mutual labels:  database, bdd
React Native Firebase
🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
Stars: ✭ 9,674 (+1542.44%)
Mutual labels:  database, realtime-database
Gun
An open source cybersecurity protocol for syncing decentralized graph data.
Stars: ✭ 15,172 (+2475.89%)
Mutual labels:  database, realtime
Cloudboost
Realtime JavaScript Backend.
Stars: ✭ 1,378 (+133.96%)
Mutual labels:  realtime-database, realtime
Realm Core
Core database component for the Realm Mobile Database SDKs
Stars: ✭ 836 (+41.94%)
Mutual labels:  database, realtime-database
Butterfly Server
The Everything is Real-Time C# Backend for Single Page Applications
Stars: ✭ 247 (-58.06%)
Mutual labels:  database, realtime
Android Ddp
[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Stars: ✭ 271 (-53.99%)
Mutual labels:  database, realtime

Event-Reduce

An algorithm to optimize database queries that run multiple times




  • 1. You make a query to the database which returns the result in 100 milliseconds
  • 2. A write event occurs on the database and changes some data
  • 3. To get the new version of the query's results you now have three options:
    • a. Run the query over the database again which takes another 100 milliseconds
    • b. Write complex code that somehow merges the incoming event with the old state
    • c. Use Event-Reduce to calculate the new results on the CPU without disc-IO nearly instant


Efficiency

In the browser demo you can see that for randomly generated events, about 94% of them could be optimized by EventReduce. In real world usage, with non-random events, this can be even higher. For the different implementations in common browser databases, we can observe an up to 12 times faster displaying of new query results after a write occurred.

How they do it

EventReduce uses 17 different state functions to 'describe' an event+previousResults combination. A state function is a function that returns a boolean value like isInsert(), wasResultsEmpty(), sortParamsChanged() and so on.

Also there are 14 different action functions. An action function gets the event+previousResults and modifies the results array in a given way like insertFirst(), replaceExisting(), insertAtSortPosition(), doNothing() and so on.

For each of our 2^17 state combinations, we calculate which action function gives the same results that the database would return when the full query is executed again.

From this state-action combinations we create a big truth table that is used to create a binary decision diagram. The BDD is then optimized to call as few state functions as possible to determine the correct action of an incoming event-results combination.

The resulting optimized BDD is then shipped as the EventReduce algoritm and can be used in different programming languages and implementations. The programmer does not need to know about all this optimisation stuff and can directly use three simple functions like shown in the javascript implementation

When to use this

You can use this to

  • reduce the latency until a change to the database updates your application
  • make observing query results more scalable by doing less disk-io
  • reduce the bandwith when streaming realtime query results from the backend to the client
  • create a better form of caching where instead of invalidating the cache on write, you update its content

Limitations

  • EventReduce only works with queries that have a predictable sort-order for any given documents. (you can make any query predicable by adding the primary key as last sort parameter)

  • EventReduce can be used with relational databases but not on relational queries that run over multiple tables/collections. (you can use views as workarround so that you can query over only one table). In theory Event-Reduce could also be used for relational queries but I did not need this for now. Also it takes about one week on an average machine to run all optimizations, and having more state functions looks like an NP problem.

Implementations

At the moment there is only the JavaScript implementation that you can use over npm. Pull requests for other languages are welcomed.

Previous Work

FAQ

Is this something like materialized views? Yes and no. Materialized views solve a similar problem but in a different way with different trade-offs. When you have many users, all subscribing to different queries, you cannot create that many views because they are all recalculated on each write access to the database. EventReduce however has better scalability because it does not affect write performance and the calculation is done when the fresh query results are requested, not beforehand.
Is this something like event sourcing or CQRS? No, event sourcing is mostly used to calculate a current state by attaching the full event stream to the starting state. This allows for stuff like time travel and so on. EventReduce solves a completely different (performance-) problem and only shares some common keywords like event.
Isn't this optimization already done by database engines? No. I tested EventReduce with many common databases like MongoDB, MySQL and Postgres. Each of them had better performance with Event-Reduce then just observing the eventstream and running the queries again. If you understand what Event-Reduce exactly does, it comes clear that this optimization can not done by pull-based databases because they have missing information.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].