A distributed SQLite server with MySQL wire compatible interface
A distributed SQLite server with MySQL wire compatible interface
Marmot v2 is a leaderless, distributed SQLite replication system built on a gossip-based protocol with distributed transactions and eventual consistency.
Key Features:
LOAD DATA LOCAL INFILE with distributed commit semanticsMySQL active-active requires careful setup of replication, conflict avoidance, and monitoring. Failover needs manual intervention. Split-brain scenarios demand operational expertise. This complexity doesn't scale to edge deployments.
Marmot excels at read-heavy edge scenarios:
| Use Case | How Marmot Helps |
|---|---|
| Distributed WordPress | Multi-region WordPress with replicated database |
| Lambda/Edge sidecars | Lightweight regional SQLite replicas, local reads |
| Edge vector databases | Built-in ANN search + distributed embeddings with local query |
| Regional config servers | Fast local config reads, replicated writes |
| Product catalogs | Geo-distributed catalog data, eventual sync |
# Start a single-node cluster
./marmot-v2
# Or run as daemon (background)
./marmot-v2 -daemon -pid-file=/tmp/marmot/marmot.pid
# Connect with MySQL client
mysql -h localhost -P 3306 -u root
# Or use DBeaver, MySQL Workbench, etc.…Marmot can run distributed WordPress with full database replication across nodes. Each WordPress instance connects to its local Marmot node, and all database changes replicate automatically.
Marmot implements MySQL functions required by WordPress:
| Category | Functions |
|---|---|
| Date/Time | NOW, CURDATE, DATE_FORMAT, UNIX_TIMESTAMP, DATEDIFF, YEAR, MONTH, DAY, etc. |
| String | CONCAT_WS, SUBSTRING_INDEX, FIND_IN_SET, LPAD, RPAD, etc. |
| Math/Hash | RAND, MD5, SHA1, SHA2, POW, etc. |
| DML | ON DUPLICATE KEY UPDATE (transformed to SQLite ON CONFLICT) |
cd examples/wordpress-cluster
./run.sh upThis starts:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ WordPress-1 │ │ WordPress-2 │ │ WordPress-3 │
│ :9101 │ │ :9102 │ │ :9103 │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Marmot-1 │◄─┤ Marmot-2 │◄─┤ Marmot-3 │
│ MySQL: 9191 │ │ MySQL: 9192 │ │ MySQL: 9193 │
└─────────────┘ └─────────────┘ └─────────────┘
└──────────────┴──────────────┘
QUORUM ReplicationTest it:
Commands:
./run.sh status # Check cluster health
./run.sh logs-m # Marmot logs only
./run.sh logs-wp # WordPress logs only
./run.sh down # Stop clusterMarmot v2 uses a fundamentally different architecture from other SQLite replication solutions:
vs. rqlite/dqlite/LiteFS:
How It Works:
| Aspect | Marmot | MySQL Active-Active | rqlite | dqlite | TiDB |
|---|---|---|---|---|---|
| Leader | None | None (but complex) | Yes (Raft) | Yes (Raft) | Yes (Raft) |
| Failover | Automatic | Manual intervention | Automatic | Automatic | Automatic |
| Split-brain recovery | Automatic (anti-entropy) | Manual | N/A (leader-based) | N/A (leader-based) | N/A |
| Consistency | Tunable (ONE/QUORUM/ALL) | Serializable | Tunabale (ONE/QUORUM/Linearizable) | Strong | Strong |
| Direct file read | ✅ SQLite file | ❌ | ✅ SQLite file | ❌ | ❌ |
| JS-safe AUTO_INCREMENT | ✅ Compact mode (53-bit) | N/A | N/A | ❌ 64-bit breaks JS | |
| Edge-friendly | ✅ Lightweight | ❌ Heavy | ✅ Lightweight | ⚠️ Moderate | ❌ Heavy |
| Operational complexity | Low | High | Low | Low | High |
Marmot v2 supports distributed DDL (Data Definition Language) replication without requiring master election:
Cluster-Wide Locking: Each DDL operation acquires a distributed lock per database (default: 30-second lease)
Automatic Idempotency: DDL statements are automatically rewritten for safe replay
CREATE TABLE users (id INT)
→ CREATE TABLE IF NOT EXISTS users (id INT)
DROP TABLE users
→ DROP TABLE IF EXISTS usersSchema Version Tracking: Each database maintains a schema version counter
Quorum-Based Replication: DDL replicates like DML through the same 2PC mechanism
[ddl]
# DDL lock lease duration (seconds)
lock_lease_seconds = 30
# Automatically rewrite DDL for idempotency
enable_idempotent = truemydb.users instead of users)Marmot v2 uses Change Data Capture (CDC) for replication instead of SQL statement replay:
EncodedCapturedRow records and stored in Marmot's CDC segment log/cdc_manifest/{txnID} only after their segment ranges are known; recovery validates and truncates segment tails at record boundariesFor UPDATE and DELETE operations, Marmot automatically extracts row keys:
Marmot can publish CDC events to external messaging systems, enabling real-time data pipelines, analytics, and event-driven architectures. Events follow the Debezium specification for maximum compatibility with existing CDC tooling.
…Events follow the Debezium envelope structure:
{
"schema": { ... },
"payload": {
"before": null,
"after": {"id": 1, "name": "alice", "email": "[email protected]"},
"source": {
"version": "2.9.0-beta",
"connector": "marmot",
"name": "marmot",
"ts_ms": 1702500000000,
"db": "myapp",
"table": "users"
},
"op": "c",
"ts_ms": 1702500000000
}
}Operation Types (per Debezium spec):
| Operation | op |
before |
after |
|---|---|---|---|
| INSERT | c (create) |
null |
row data |
| UPDATE | u (update) |
old row | new row |
| DELETE | d (delete) |
old row | null |
Topics follow the pattern: {topic_prefix}.{database}.{table}
Examples:
marmot.cdc.myapp.usersmarmot.cdc.myapp.ordersNo open issues yet, or sync has not completed.