Six months ago, I shipped a production Go service backed by SQLite instead of spinning up a managed PostgreSQL instance. A few teammates thought I was crazy. The app handles roughly 400,000 requests a day—mostly reads, mixed with steady write bursts from background workers and user actions. Week one felt effortless. Then traffic spiked, and our logs filled up with database is locked (SQLITE_BUSY) errors.
I spent the next two weeks benchmarking drivers, connection pool limits, and PRAGMA settings until those errors vanished. Half a year later, that single-node box is still humming along at ~12% CPU. Below is what broke, what fixed it, and the exact Go configuration I run today.
Approach Comparison: How Go Services Handle SQLite Concurrency
Once SQLITE_BUSY errors start showing up, Go developers usually reach for one of three patterns. I tested all three under load before landing on a setup that held up.
1. Default Rollback Journal with Standard database/sql Pooling
SQLite ships with the DELETE rollback journal by default, while Go’s database/sql opens a pool of concurrent connections. That works fine in local tests. Under real traffic, readers block writers and writers block readers. Worse, when two goroutines grab separate connections to write at once, SQLite throws SQLITE_BUSY immediately.
2. WAL Mode with Unbounded Connections
Turning on Write-Ahead Logging (WAL) lets multiple readers and one writer run concurrently without blocking each other. Still, leaving Go’s default connection pool wide open creates a different bottleneck. Ten goroutines will still fight over SQLite’s single write lock from ten separate connections. Even with a busy_timeout, write bursts trigger lock contention and spiky p99 latencies.
3. WAL Mode with Separate Read and Write Pools
Splitting reads and writes at the application layer solves that contention. You cap the write pool at one open connection (SetMaxOpenConns(1)) and let a separate read-only pool scale across multiple connections. Writes queue cleanly inside Go’s pool instead of colliding in SQLite’s C layer. That single change eliminated our locking errors.
Pros and Cons After 6 Months in Production
SQLite is not a silver bullet. Running it in production comes with real trade-offs you should weigh before skipping Postgres.
What Worked Well (Pros)
- Sub-millisecond reads: With the database sitting on the same NVMe drive as the Go binary, there is zero network hop. Simple point lookups consistently finish in 0.2 to 0.4 ms.
- Almost zero ops overhead: You skip RDS upgrades, subnet routing, and a separate database process eating 2 GB of RAM. Backups are just a cron job running
VACUUM INTOor continuous replication via Litestream. - Zero write lock errors: Serializing writes through a one-connection pool in WAL mode dropped our
SQLITE_BUSYrate from dozens per hour to zero.
Where It Hurts (Cons)
- Single-node ceiling: Local SQLite files do not scale horizontally for writes across multiple app servers. If you need multi-region active-active writes, use Postgres or CockroachDB.
- Open reads stall checkpoints: A long-running read transaction prevents SQLite from merging the
-walfile back into the main database. Leave an analytics query open for 20 minutes, and your-walfile can balloon to hundreds of megabytes. - CGO build friction:
mattn/go-sqlite3requires CGO, which slows down Docker builds and complicates cross-compiling. Pure-Go drivers likemodernc.org/sqlitecompile cleanly everywhere, though they run roughly 15–30% slower on CPU-heavy queries.
My Recommended Production Setup
If you are running a single-node Go service, these settings give you the best balance of speed and safety:
- Driver: Pick
github.com/mattn/go-sqlite3for raw speed if CGO works in your build pipeline, ormodernc.org/sqlitefor CGO-free static binaries. - Journal Mode: Set
PRAGMA journal_mode = WAL;so reads and writes no longer block each other. - Synchronous Mode: Use
PRAGMA synchronous = NORMAL;. It is safe in WAL mode and skips the extrafsyncon every commit that makesFULLslow. - Busy Timeout: Set
PRAGMA busy_timeout = 5000;so brief lock contention waits up to 5 seconds instead of failing on the spot. - Foreign Keys & Temp Store: Turn on
PRAGMA foreign_keys = ON;(SQLite disables it by default) and setPRAGMA temp_store = MEMORY;. - Separate Pools: Give writes a dedicated
*sql.DBwithSetMaxOpenConns(1), and give reads a second read-only*sql.DBsized tomax(4, runtime.NumCPU()).
Step-by-Step Implementation Guide in Go
Let’s wire this up in Go. I’m using mattn/go-sqlite3 here, though the same PRAGMAs work with modernc.org/sqlite (just swap the driver name to "sqlite").
go get github.com/mattn/go-sqlite3
1. Configure Separate Read and Write Connection Pools
Wrapping two *sql.DB handles inside a small Store struct keeps read and write traffic cleanly separated. Passing PRAGMAs in the DSN ensures every new connection in the read pool gets the right settings automatically.
package db
import (
"context"
"database/sql"
"fmt"
"net/url"
"runtime"
_ "github.com/mattn/go-sqlite3"
)
type Store struct {
WriteDB *sql.DB
ReadDB *sql.DB
}
func NewStore(dbPath string) (*Store, error) {
writeParams := url.Values{}
writeParams.Add("_journal_mode", "WAL")
writeParams.Add("_synchronous", "NORMAL")
writeParams.Add("_busy_timeout", "5000")
writeParams.Add("_foreign_keys", "on")
writeParams.Add("_cache_size", "-64000") // ~64 MB page cache
writeDSN := fmt.Sprintf("file:%s?%s", dbPath, writeParams.Encode())
writeDB, err := sql.Open("sqlite3", writeDSN)
if err != nil {
return nil, fmt.Errorf("open write db: %w", err)
}
// Serialize all writes through Go's pool to avoid SQLITE_BUSY
writeDB.SetMaxOpenConns(1)
writeDB.SetMaxIdleConns(1)
// Initialize WAL mode on disk and set temp_store on the single write connection
if _, err := writeDB.Exec("PRAGMA temp_store = MEMORY;"); err != nil {
writeDB.Close()
return nil, fmt.Errorf("configure write db: %w", err)
}
// Read pool can open multiple concurrent connections
readParams := url.Values{}
readParams.Add("mode", "ro")
readParams.Add("_busy_timeout", "5000")
readParams.Add("_foreign_keys", "on")
readParams.Add("_cache_size", "-64000")
readDSN := fmt.Sprintf("file:%s?%s", dbPath, readParams.Encode())
readDB, err := sql.Open("sqlite3", readDSN)
if err != nil {
writeDB.Close()
return nil, fmt.Errorf("open read db: %w", err)
}
readConns := max(4, runtime.NumCPU())
readDB.SetMaxOpenConns(readConns)
readDB.SetMaxIdleConns(readConns)
return &Store{
WriteDB: writeDB,
ReadDB: readDB,
}, nil
}
2. Use IMMEDIATE Transactions for Writes
SQLite has a nasty surprise for anyone using Go’s default BeginTx. By default, SQLite starts a DEFERRED transaction, which takes a shared read lock on the first SELECT and only requests a write lock when an INSERT or UPDATE runs. If another connection grabs the write lock in between, SQLite refuses to wait—it ignores busy_timeout and fails with SQLITE_BUSY right away.
Starting write transactions with BEGIN IMMEDIATE acquires the write lock up front. Even with SetMaxOpenConns(1), this protects you if a backup script or CLI session touches the database file.
func (s *Store) CreateOrder(ctx context.Context, userID int64, amount int64) error {
conn, err := s.WriteDB.Conn(ctx)
if err != nil {
return err
}
defer conn.Close()
if _, err := conn.ExecContext(ctx, "BEGIN IMMEDIATE"); err != nil {
return fmt.Errorf("begin immediate: %w", err)
}
_, err = conn.ExecContext(
ctx,
"INSERT INTO orders (user_id, amount) VALUES (?, ?)",
userID,
amount,
)
if err != nil {
_, _ = conn.ExecContext(ctx, "ROLLBACK")
return fmt.Errorf("insert order: %w", err)
}
if _, err := conn.ExecContext(ctx, "COMMIT"); err != nil {
return fmt.Errorf("commit order: %w", err)
}
return nil
}
3. Keep WAL Files Under Control
SQLite automatically checkpoints the WAL file once it hits 1,000 pages (about 4 MB with the default 4 KB page size). Under steady writes, keep an eye on your -wal file size and kill slow read queries early. During quiet hours, you can also run a truncating checkpoint to reclaim disk space:
_, err := store.WriteDB.ExecContext(ctx, "PRAGMA wal_checkpoint(TRUNCATE);")
Finally, close both pools on shutdown so SQLite checkpoints cleanly and removes the -wal and -shm files:
func (s *Store) Close() error {
readErr := s.ReadDB.Close()
writeErr := s.WriteDB.Close()
if writeErr != nil {
return writeErr
}
return readErr
}
Final Thoughts
SQLite in Go handles real production traffic well, provided you work with its single-writer model instead of fighting it. Turn on WAL mode, set synchronous = NORMAL with a 5-second busy_timeout, and split reads and writes into separate pools. For single-server workloads, you get sub-millisecond queries and far fewer moving parts to babysit.

