Deep Dive into Pure Go Zero-CGO & SQLite High-Concurrency Architecture

Traditional dynamic CMSs rely heavily on MySQL/PostgreSQL and complex external runtimes, while early Go SQLite setups suffered from cumbersome CGO cross-compilation and SQLITE_BUSY lock contention under concurrent writes. cms studio builds a 100% Pure Go, zero-CGO high-concurrency SQLite architecture from the storage layer up.

1. 100% Pure Go Zero-CGO Compilation

The entire stack is built on the Pure Go driver github.com/glebarez/sqlite and the standard library with CGO_ENABLED=0, requiring zero host C dynamic libraries (such as glibc or libsqlite3).

  • Single-Binary Delivery: The admin frontend bundle is embedded directly into the executable via //go:embed; in production you only copy one binary file to run.
  • Instant Cross-Compilation: Whether cross-compiling Linux amd64/arm64 binaries on Windows or building natively, packaging completes in seconds.

2. Dual Connection Pool Read/Write Splitting & WAL Tuning

To eliminate SQLite write-lock contention at the root, the kernel splits database initialization into two independent connection pools:

  • Write Pool (WriteDB): Enforces SetMaxOpenConns(1) so every INSERT, UPDATE, DELETE, and schema migration queues serially at the Go runtime layer, preventing concurrent write conflicts.
  • Read Pool (ReadDB): Configured with SetMaxOpenConns(runtime.NumCPU() * 2) so high-concurrency frontend reads, full-text search, and API queries execute in parallel.
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
PRAGMA busy_timeout = 5000;
PRAGMA cache_size = -64000;
PRAGMA temp_store = MEMORY;

Combined with WAL (Write-Ahead Logging), reads and writes never block each other. Layered with the in-memory PageCache and built-in FTS5 virtual full-text search tables, a single lightweight VPS handles thousands of QPS effortlessly.

3. VACUUM INTO Single-File Safe Hot Backup

Ops Pitfall Warning: In WAL mode, cms.db, cms.db-wal, and cms.db-shm coexist on disk. Copying only the main file to another machine risks triggering malformed database schema corruption.

cms studio's built-in backup tool uses VACUUM INTO inside an isolated temporary directory to produce a consistent snapshot, then explicitly runs PRAGMA journal_mode = DELETE; and PRAGMA integrity_check; before cleaning sidecar files—guaranteeing a single-file, zero-residue, ready-to-use database backup.