RapidLink is a distributed messaging system built in Python for local multi-node execution. It combines Raft-based leader election and replication, durable message logs, direct messaging APIs, time synchronization utilities, and a browser-based control console.
The project is designed to run without Kafka, Docker, or any external broker. A FastAPI gateway starts and manages the cluster, streams node terminal output to the browser, and exposes REST and WebSocket flows for direct messaging and live updates.
- Multi-node cluster with start, kill, and restart controls
- Raft-based leader election, heartbeats, and log replication
- Durable commit logs with deduplication support
- Direct messaging conversations with history retrieval
- FastAPI gateway with REST endpoints and WebSocket streaming
- Browser UI for cluster control, message history, and live terminals
- Physical time sync, Lamport clocks, and message ordering helpers
- Unit and integration tests for cluster, replication, API, and time modules
src/cluster/- node runtime, RPC, Raft, heartbeats, and failure detectionsrc/replication/- persistent commit log, dedup cache, and replication helperssrc/api/- wire protocol handling and direct message topic helperssrc/time/- time synchronization, Lamport clocks, and ordering utilitiesscripts/dm_gateway.py- FastAPI gateway and browser UI entry pointscripts/run_node.py- run one node by idscripts/run_cluster.py- start the full cluster locallyscripts/failover_demo.py- demonstrate leader failover and recoverypublic/- web UI assets and screenshotstests/- unit and integration coverage
The default cluster is defined in config/cluster.yaml:
n1->127.0.0.1:9101n2->127.0.0.1:9102n3->127.0.0.1:9103
Each node also opens:
- an RPC port on
node_port + 1000 - a time sync port on
node_port + 200
- Create a virtual environment.
python -m venv .venv- Activate it.
source .venv/bin/activatePowerShell:
.venv\Scripts\Activate.ps1- Install dependencies.
pip install -r docs/requirements.txtpython scripts/dm_gateway.pyThen open:
http://localhost:8081/
From the UI you can:
- start the configured cluster
- kill or restart individual nodes
- watch each node's terminal output live
- send direct messages and inspect history
python scripts/run_node.py --id n1Optional arguments:
--configto use a different cluster config file--data-rootto choose a different storage directory
python scripts/run_cluster.pyThis starts all configured nodes, checks inter-node communication, and reports leader election status.
python scripts/failover_demo.pyThis script starts a small cluster, publishes before and after failover, cancels the current leader, waits for a new leader, then restarts the old node and verifies history recovery.
By default, runtime data is written under .data/.
Typical node artifacts include:
.data/<node_id>/logs/console.log.data/<node_id>/logs/node.log.data/<node_id>/logs/metrics.log.data/<node_id>/raft/
The gateway reads the console logs to stream the browser terminals in real time.
RapidLink supports leader-based publish and history retrieval over the node wire protocol and through the FastAPI gateway.
Main operations include:
PUBfor publishing a messageSUBfor subscribing to a topicHISTORYfor reading committed message history- direct-message conversation ids generated from two participant names
The gateway converts browser actions into broker commands and returns structured responses for message history and live updates.
The project also includes time coordination features for distributed message ordering:
- SNTP-style offset measurement
- per-node time sync server and client
- Lamport clock support
- vector-clock-aware helpers
- bounded message reordering utilities
Demo code for this lives in src/demos/time_sync_demo.py.
Run the test suite with:
pytest tests -qThe repository includes tests for:
- config loading
- API and gateway helpers
- RPC communication
- Raft election and replication
- commit log persistence
- time synchronization and logical clocks
- integration behavior across nodes
Optional environment variables include:
GATEWAY_PORTto change the web UI and API portBROKER_HOSTandBROKER_PORTto point the gateway at a primary nodeBROKER_NODESto provide a fallback list of node addressesNODE_DATA_ROOTto change where node runtime data is stored
You can also place a local .env file in the project root. The gateway loads simple KEY=VALUE pairs on startup.

