A message queue in a single SQLite file.
Peek-Lock delivery, retries, dead-letter queues, scheduling, dedup, FIFO groups and topic fan-out — embedded in your Go process or served as a tiny HTTP broker. Same engine, same file, your choice.
Three problems that keep re-appearing in every backend.
Zero infrastructure. Want HTTP later? The same engine runs as one ~30 MB process.
The queue is your SQLite DB: business write + enqueue commit atomically.
status column and a polling loop slowly regrow locks, retries, dead-letters — untested.Peek-Lock, retries → DLQ + redrive, FIFO groups, delays, dedup — pinned by a conformance suite.
Design priorities, in order — when they conflict, the earlier one wins.
One pure-Go binary over one SQLite file. No broker cluster, no sidecar, no CGO. Start embedded; move the same code to a broker, or the storage to replicated Turso, without rewriting your app.
Default Peek-Lock delivery is honestly at-least-once; explicit receive-and-delete chooses at-most-once broker removal. New settlements require a current token and unexpired lease; send deduplication when configured, bounded receive/settlement replay, single-broker crash recovery, and O(log n) claims on a deep backlog. FIFO groups stay ordered even across consumer crashes and lock expiry.
Every operation is one HTTP POST with a JSON body — 29 routes, curl-able by
construction, exactly one settlement verb per outcome (Complete /
Abandon / Reject / Defer), no aliases. Easy for people; easy for
agents.
Peek-Lock, group_id sessions, DLQ + redrive, scheduling and duplicate detection feel
familiar from Azure Service Bus — in an idiomatic-Go shape, with the
whole model documented and its public compatibility
invariants pinned by a conformance suite.
Because the queue is your SQLite database, a business write and its event commit in one transaction. Creating the order and its initial queue event succeeds or rolls back together — no dual-write race, no CDC pipeline, no poller.
package main
import (
"context"
"log"
"github.com/mqlitehq/mqlite"
"github.com/mqlitehq/mqlite/engine"
)
func main() {
ctx := context.Background()
mq, err := mqlite.OpenEmbedded(ctx, "file:./app.db")
if err != nil {
log.Fatal(err)
}
defer mq.Close()
if err := mq.CreateQueue(ctx, "order-events", mqlite.QueueConfig{}); err != nil {
log.Fatal(err)
}
err = mq.Tx(ctx, func(tx *engine.EngineTx) error {
// Demo schema; application migrations normally create this table.
if _, err := tx.SQL().ExecContext(tx.Context(),
`CREATE TABLE IF NOT EXISTS orders(id INTEGER PRIMARY KEY, total INTEGER NOT NULL)`); err != nil {
return err
}
// 1) the business write, on the SAME transaction. Use tx.Context(), not the
// ctx you passed to Tx — a statement interrupted mid-transaction wedges
// a local SQLite database.
if _, err := tx.SQL().ExecContext(tx.Context(),
`INSERT INTO orders(id, total) VALUES(?, ?)`,
42, 1999); err != nil {
return err // rollback: nothing enqueued
}
// 2) enqueue — commits atomically with it:
_, err := tx.SendOne("order-events",
engine.OutMessage{Body: []byte(`{"order":42}`)})
return err
})
if err != nil {
log.Fatal(err)
}
// A nil result confirms that the order and its event committed together.
}
The snippet starts with a fresh app.db and inserts order 42 once.
Atomicity keeps the business write and enqueue together; it does not make external
side effects exactly-once or prove that a timed-out remote commit failed. Reconcile
an uncertain outcome before retrying. See transactional enqueue.
Two delivery targets, one storage story: a topic stores nothing — the thing that stores, is consumed, and can dead-letter is always a queue.
The publisher sends order.created to the implicit events topic.
order.created to the implicit events topic.audit and fulfillment each receive an independent backing-queue copy: same message ID, different sequence numbers.Receive changes its copy from active to locked and increments delivery_count to 1.audit completes, so only its message copy is removed; the subscription remains. Below the delivery limit, fulfillment abandons with delay, moving its copy locked → scheduled without incrementing the count.Receive locks the copy and increments delivery_count to 2.Animation timing is illustrative, not broker latency. A final ordinary claim may still renew and complete at the delivery limit. It enters the DLQ if explicitly rejected, or if that final lock is abandoned, expires, or is explicitly reclaimed. See shutdown and restart boundaries.
Published historical measurements from specific workloads; remeasure the current release with your payloads, concurrency and monitoring enabled before sizing production. Methods and limits: docs/benchmark.md. Historical Turso environment and comparison: PR #67.
| Setup | Measured | Read this as |
|---|---|---|
| Local file DB, 12-core machine | 15,926–17,963 msg/s single · 35,146 batched | historical local results; rerun the workload before sizing |
| 1-vCPU / 256 MB cloud box, embedded engine | 6.0–6.7k msg/s batched | batching amortized commit cost in this measured setup |
| Remote Turso (co-located) | ~45 ms p50 per single durable send | historical co-located run; remote commit latency dominated this path |
| Memory / disk | 27–34 MB peak RSS · freed DB pages are reusable | file reclamation is gradual; size disk for peak backlog and measure your workload |
| If you need… | Use instead |
|---|---|
| Log streaming, replay, consumer groups over history | Kafka · Redpanda · NATS JetStream |
| A clustered, highly-available multi-node broker | NATS · RabbitMQ |
| A queue inside the Postgres you already run | pgmq · River |
| Sustained six-figure msg/s on one node | not this — the single-writer model is the point, not a bug |
| Exactly-once external side effects | default Peek-Lock delivery is at-least-once; make handlers idempotent |
The boundaries, evidence and executable contract behind the overview — rendered from the same source Markdown so people and machines read the same facts in either language.
Three ways in — they all drive the same engine. These installation examples use the latest published modules and image; verify the installed version and use its matching release documentation; see Deployment for installation and runtime settings.
Writing a broker-only Go application? The official
MQLite Remote Client for Go
(mqlite-go) is standard-library-only and keeps a Go 1.13
source floor: go get github.com/mqlitehq/mqlite-go@latest. Use
the full SDK below for embedded queues, transactional outbox, observation,
or managed access-key administration.
No server at all: one import, one file — the queue lives inside your process. go get github.com/mqlitehq/mqlite@latest (documented source floor: Go ≥ 1.21; check the installed release's go.mod).
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/mqlitehq/mqlite"
)
func main() {
ctx := context.Background()
mq, err := mqlite.OpenEmbedded(ctx, "file:./mq.db")
if err != nil {
log.Fatal(err)
}
defer mq.Close()
if err := mq.CreateQueue(ctx, "orders", mqlite.QueueConfig{
LockDuration: 30 * time.Second,
MaxDeliveryCount: 5,
}); err != nil {
log.Fatal(err)
}
// produce
if _, err := mq.SendOne(ctx, "orders", mqlite.OutMessage{Body: []byte(`{"id":42}`)}); err != nil {
log.Fatal(err)
}
// consume (Peek-Lock): receive, do work, then settle
msgs, err := mq.Receive(ctx, "orders", mqlite.RecvOpts{Max: 10, Wait: 5 * time.Second})
if err != nil {
log.Fatal(err)
}
for _, m := range msgs {
fmt.Printf("got: %s\n", m.Body)
// Abandon retries below max (DLQ at max); Reject sends directly to DLQ.
if err := m.Complete(ctx); err != nil {
log.Fatal(err)
}
}
}
One tiny process, secure by default: it generates a mqk_… token and prints it if you don't set one. Every operation is one POST.
go install github.com/mqlitehq/mqlite/cmd/mqlite@latest # latest published broker
# start the broker on :6754 with a known token, in the background
MQLITE_TOKENS=mqk_dev MQLITE_DB=file:./mq.db mqlite serve --addr :6754 &
export TOKEN=mqk_dev # (omit MQLITE_TOKENS to have the broker generate + print one)
# create a queue, send, receive — curl-able by construction
curl -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
--data '{"name":"orders","config":{}}' \
localhost:6754/mqlite.v1.AdminService/CreateQueue
curl -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
--data "{\"queue\":\"orders\",\"messages\":[{\"body\":\"$(printf hi | base64)\"}]}" \
localhost:6754/mqlite.v1.QueueService/Send
curl -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
--data '{"queue":"orders","max_messages":1,"wait_time_ms":5000}' \
localhost:6754/mqlite.v1.QueueService/Receive
A named volume keeps queue data across container replacement. The admin console is available at /ui; opening the root URL in a browser enters that console while curl and JSON clients keep the discovery card. The console groups subscriptions by topic and shows permanent or fixed lifetimes against the broker clock; its five-second loop calls only Observe, while lifecycle inventory refreshes on connection, explicit refresh and configuration changes.
This example follows the latest published image. Pin a verified tag or digest for reproducible deployments. For production configuration and recovery, follow Deployment and the operations runbook.
docker run -d --name mqlite -p 127.0.0.1:6754:6754 \
-e MQLITE_TOKENS=mqk_dev \
-e MQLITE_DB=file:/data/mq.db \
-v mqdata:/data \
ghcr.io/mqlitehq/mqlite:latest serve --addr :6754
curl http://localhost:6754/ # discovery card (no auth)
# opening that root URL in a browser enters the admin console
Keep a configured administrator token and issue separate application keys at runtime, with no broker restart.
Permissions apply across one broker. Tokens are shown once; the database stores only their digests. Manage keys through the Go SDK, HTTP API, CLI, console or MCP.
Start with one broker over a persistent local SQLite file. Choose a durability setting and rehearse recovery before putting messages into production.
Prometheus collection is off by default. Enable --metrics or MQLITE_METRICS=on to serve authenticated /metrics on the API port, and give the collector a separate MQLITE_MONITOR_TOKENS credential. Keep collection on a private network; if the API has public ingress, deny /metrics there. Use mqlite_queue_retained_messages and mqlite_queue_oldest_message_age_seconds. The starter includes Prometheus, Grafana, a dashboard and verification scenarios.
GET /, an
MCP server (mqlite-mcp, 22 tools in the documented source), and
llms.txt / llms-full.txt
for anything that reads the web. Copy-paste prompts and setup:
For AI agents →