A backend infrastructure pattern for sourcing blockchain events to update datastores and trigger side effects in Node.js applications.
Demux-js is a Node.js library that implements the Demux pattern for blockchain applications. It sources events from blockchains to deterministically update external datastores and trigger side effects, solving problems like limited query interfaces and scaling issues when retrieving data directly from blockchain state.
Blockchain developers building backend systems for dApps who need to separate blockchain state from frontend query requirements and manage side effects like transactions or external notifications.
Developers choose Demux-js because it provides a deterministic, replayable way to sync blockchain data with scalable databases, enables complex queries without blockchain constraints, and maintains the blockchain as a single auditable source of truth.
💫 Deterministic event-sourced state and side effect handling for blockchain applications
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Offloads queries to databases like Postgres, enabling complex SQL joins and aggregations that are impossible with direct blockchain queries, as highlighted in the README's discussion on scaling front-end data needs.
Updater functions process blockchain actions to update datastores in a replayable manner, ensuring the persistence layer can be regenerated from the blockchain for auditability, a core benefit mentioned in the philosophy.
Effect functions allow triggering asynchronous events like sending emails or transactions based on blockchain actions, integrating non-deterministic systems while keeping core state deterministic, as described in the data flow.
Derives all application state from the blockchain as a single source of truth, eliminating duplicate state management and enabling full audit trails, a key qualification from the overview.
Requires implementing AbstractActionReader and AbstractActionHandler for specific blockchains and databases, increasing initial setup complexity since the library provides only abstract classes and few ready-to-use components.
Officially supported implementations are primarily for EOSIO and Postgres; other integrations like BitShares rely on community contributions, which may be less maintained and documented, as noted in the repository list.
Regenerating datastores from scratch involves processing all historical blockchain blocks, which can be time-consuming and resource-intensive for applications with long chain histories, despite being deterministic.
Effects are non-deterministic and not run during replays, potentially leading to missed side effects like external API calls if the system is reset, complicating debugging and state recovery.