genosdb-server
v0.4.0
Published
GenosDB Server: A persistent Node.js peer for the GenosDB distributed graph database. Provides a reliable file-system storage layer, ensuring data durability and network resilience for your real-time, peer-to-peer applications.
Maintainers
Readme
GDB Data Synchronization Server
This repository contains the server-side implementation for a distributed graph database system. It acts as a Persistent P2P Data Synchronization Node/Server, enabling real-time data replication and consistency across a peer-to-peer network, with local file system persistence for data durability.
Core Features
- Real-time P2P Synchronization: Utilizes WebRTC (via GenosRTC) for direct peer-to-peer communication and graph data synchronization.
- Local File System Persistence: Graph data and synchronization state (timestamps) are persisted locally using MessagePack for graph serialization and JSON for timestamps, ensuring data is not lost on restart.
- Automatic Conflict Resolution: Implements a Last-Write-Wins (LWW) strategy for conflict resolution based on Hybrid Logical Clocks (HLCs) to maintain data consistency across distributed nodes.
- Compressed Data Transfer: Graph data is compressed using Pako (zlib compression) before network transmission or local storage to reduce bandwidth and disk space usage.
- Built with Node.js & Express: The server is built using Node.js and includes a minimal Express.js server for potential API extensions or status monitoring.
- SSE for Peer Monitoring: Includes a Server-Sent Events (SSE) endpoint (
/events) and a basic HTML page (/) to visualize real-time P2P connections.
Architecture Overview
The server leverages a combination of technologies to achieve its goals:
- CRDTs (Conflict-free Replicated Data Types) Principles: The LWW approach with HLCs is inspired by CRDT principles to ensure eventual consistency.
- MessagePack (
@msgpack/msgpack): For efficient binary serialization of graph data. - Pako: For GZIP compression/decompression of serialized data.
- GenosRTC: Para la comunicación P2P y sincronización en tiempo real, usando el módulo interno de GenosDB.
- Node.js File System (
fs/promises): For asynchronous local storage operations. - WebRTC Polyfill (
webrtc-polyfill): To ensure WebRTC compatibility within the Node.js environment. - Custom HybridClock: A custom implementation for generating hybrid logical timestamps used in conflict resolution.
Cada instancia del servidor se conecta a una "sala" P2P usando GenosRTC, basada en el nombre de la base de datos configurado. Los cambios se propagan entre los pares conectados y se resuelven usando la estrategia LWW con HLC. El estado del grafo y el timestamp global se guardan periódicamente en disco.
Key Components
GDBServer.js: The main file containing theGDBServerclass, which orchestrates P2P communication, data persistence, and Express server setup.Graph(class withinGDBServer.js): A simple in-memory representation of the graph data structure with methods for node/edge manipulation and serialization.HybridClock.js: Implements the Hybrid Logical Clock for generating timestamps that help order events in a distributed environment.
Getting Started
Prerequisites
- Node.js (version X.X.X or higher recommended)
- npm or yarn
Installation
- Clone the repository:
git clone https://github.com/estebanrfp/gdb-server.git cd gdb-server - Install dependencies:
npm install # or # yarn install
Running the Server
You can run the server using Node.js. You can specify a room name as a command-line argument or via an environment variable.
# Run with the default room name ("default")
node GDBServer.js
# Run with a specific room name
node GDBServer.js my-graph-database
# Or using an environment variable
GDB_ROOM=my-special-room node GDBServer.js
# Console
export GDB_ROOM="todoList"