Sonic is a small Rust search backend that intentionally does less than Elasticsearch or Meilisearch — it indexes terms, returns IDs, and stays out of the way. It’s a suggestion/autocomplete engine, not a full-text query engine; the database stays authoritative. This article installs Sonic on Ubuntu, configures the auth password, opens a control connection, and indexes a few documents. Audience is operators looking for an in-memory autocomplete backend with a tiny footprint (single-digit MB resident).
How to verify
After install, confirm Sonic is listening and the password gate works:
systemctl status sonic
journalctl -u sonic -n 50 --no-pager
ss -tlnp | grep 1491
(echo 'START search SecretPassword'; sleep 1; echo 'QUIT') | nc 127.0.0.1 1491
(echo 'PING'; sleep 1; echo 'QUIT') | nc 127.0.0.1 1491
A correct install responds to PING with PONG and rejects START search with a bad password.
What’s happening
Sonic speaks a custom plain-text protocol over TCP (port 1491 by default), not HTTP. Clients open a channel — search, ingest, or control — and issue commands. The backend stores an inverted index of words to object IDs only; it does not store documents. The application is expected to fetch the actual rows from the primary database (PostgreSQL, MongoDB, etc.) using the returned IDs.
This is a deliberate scope: Sonic excels at “suggest me objects matching this typed prefix” workloads, runs in tens of MB, and has near-zero operational surface. It is not a full-text engine — no relevance scoring, no facets, no aggregations.
Indices are namespaced by collection, bucket, and locale. Typical pattern is collection=products, bucket=tenant_42 for multi-tenant separation. Persistence is on disk under /var/lib/sonic/store/.
The procedure
1. Install from the release binary. Sonic doesn’t have a vendor APT repo, so use the GitHub release:
SONIC_VER=1.4.9
curl -fsSL "https://github.com/valeriansaliou/sonic/releases/download/v${SONIC_VER}/v${SONIC_VER}.tar.gz" -o /tmp/sonic.tar.gz
sudo tar -xzf /tmp/sonic.tar.gz -C /opt/
sudo ln -sf /opt/sonic-v${SONIC_VER}/sonic /usr/local/bin/sonic
sudo useradd -r -s /usr/sbin/nologin sonic
sudo mkdir -p /var/lib/sonic /etc/sonic
sudo chown -R sonic:sonic /var/lib/sonic
2. Write the config at /etc/sonic/sonic.cfg:
[server]
log_level = "warn"
[channel]
inet = "127.0.0.1:1491"
tcp_timeout = 300
auth_password = "set-a-long-random-secret"
[store]
path = "/var/lib/sonic/store/"
[store.kv]
retain_word_objects = 1000
[store.fst]
pool.inactive_after = 300
graph.consolidate_after = 180
Replace the password with openssl rand -hex 32. Bind to localhost unless the search client is on a different host on a trusted network.
3. systemd unit at /etc/systemd/system/sonic.service:
[Unit]
Description=Sonic search backend
After=network.target
[Service]
User=sonic
Group=sonic
ExecStart=/usr/local/bin/sonic -c /etc/sonic/sonic.cfg
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable --now sonic
4. Ingest documents over the protocol. Open a netcat session on the ingest channel:
SONIC_PASS='set-a-long-random-secret'
(
echo "START ingest $SONIC_PASS"
sleep 1
echo "PUSH messages user:42 conv:1 \"Welcome to the new product launch\""
echo "PUSH messages user:42 conv:2 \"Quarterly review meeting at 3pm\""
sleep 1
echo "QUIT"
) | nc 127.0.0.1 1491
5. Query the suggest channel:
(
echo "START search $SONIC_PASS"
sleep 1
echo "QUERY messages user:42 \"quarter\""
sleep 1
echo "QUIT"
) | nc 127.0.0.1 1491
The response is a space-separated list of object IDs (conv:2 in this case). Your application then fetches the matching rows from its primary database.
6. Bulk maintenance via the control channel:
(
echo "START control $SONIC_PASS"
sleep 1
echo "TRIGGER consolidate"
sleep 1
echo "INFO"
echo "QUIT"
) | nc 127.0.0.1 1491
consolidate flushes pending FST graph rewrites — run it nightly via cron or after big imports.
Operational notes
- No replication, no clustering. Sonic is a single-node store. For HA, replicate at the application layer: write to two Sonics, fail over reads with a circuit breaker.
- Backups are file copies of
/var/lib/sonic/store/. Stop the service or runTRIGGER backup(writes a snapshot dir), then rsync to object storage. - Memory pressure comes from FST graphs held in pools. Tune
[store.fst] pool.inactive_afterdown if the host has limited RAM. - Protocol clients exist for Node, Python, Go, Rust, PHP, Ruby — pick the official
valeriansaliou/node-sonic-channelfamily or equivalent. Hand-rolling the protocol is doable but tedious. - Index drift. Since Sonic doesn’t know your database, deletes must be replayed: when you delete a row, also send a
POPcommand to remove the term-object mapping or you leak stale IDs into search results.
In the engagements we run, Sonic is an interesting pick when the application already has a strong primary database and the team only needs an autocomplete sidekick — no aggregations, no facets, no analytics. The operational shape is tiny (one binary, one config, one disk path) which makes it well-suited to small VMs and edge sites. For richer search needs, we usually reach for Meilisearch or Typesense instead. See /en/services/managed-operations/ for how we operate search backends alongside the rest of the application stack.