Deploy Sonic
Indexes search text and object identifiers, Elasticsearch alternative
Just deployed
/var/lib/sonic/store
Deploy and Host Sonic on Railway
Deploy this repository as a Sonic search backend on Railway. Sonic indexes search text and object identifiers over the Sonic Channel protocol (TCP port 1491). Your application pushes data with PUSH and queries with QUERY — Sonic returns IDs that you resolve in your own database.
About Hosting
This template runs the official Sonic Docker image with a Railway-ready configuration: listens on 0.0.0.0:1491, stores the index on a persistent volume, and requires an authentication password for all channel connections.
Sonic is not an HTTP API. Connect via TCP (Railway TCP Proxy or private networking). Use client libraries such as node-sonic-channel or pysonic.
Each TCP connection uses one channel mode — you cannot switch modes mid-session:
| Mode | Commands |
|---|---|
ingest | PUSH, POP, COUNT, FLUSHO, FLUSHB, FLUSHC |
search | QUERY, SUGGEST, LIST, PING, HELP |
control | TRIGGER consolidate, INFO, PING |
Networking: services inside Railway connect to ${{sonic.RAILWAY_PRIVATE_DOMAIN}}:1491. External clients use the TCP Proxy host and port from Railway settings — the public proxy port is often not 1491 (Railway maps it to the internal 1491).
Why Deploy
- Lightweight search — Alternative to Elasticsearch/Meilisearch for ID-based full-text search with minimal RAM (~30MB under load).
- Fast lookups — Microsecond-range queries on SSD-backed storage.
- Simple protocol — Push text + object ID, query terms, get IDs back.
- Multi-language — 80+ languages with stop-word handling.
Common Use Cases
- Helpdesk or documentation search (Crisp uses Sonic in production)
- In-app search where full documents live in Postgres/API
- Autocomplete (
SUGGEST) on user input - Low-cost search index for side projects and staging
Dependencies for
This template provides a search index service. Your web app or API depends on it for PUSH (ingest) and QUERY (search) over Sonic Channel.
Deployment Dependencies
- SONIC_AUTH_PASSWORD (required) — Password for
START ingest|search|control. Use${{secret(32)}}in the template so Railway generates a random password on first deploy. - Volume — Mount a volume at
/var/lib/sonic/storeso index data survives redeploys. Without it, indexed data is lost on restart. - TCP Proxy (optional) — Enable Railway TCP Proxy on port 1491 to connect from outside Railway. Other services in the same project can use
${{sonic.RAILWAY_PRIVATE_DOMAIN}}:1491over private networking.
Connecting from Your App
| Variable in your app | Railway reference |
|---|---|
| Sonic host | ${{sonic.RAILWAY_PRIVATE_DOMAIN}} or TCP proxy host |
| Sonic port | 1491 (private) or TCP proxy port (public) |
| Sonic password | ${{sonic.SONIC_AUTH_PASSWORD}} |
Ingest example:
START ingest
PUSH articles default article:42 "Title and body text to index"
QUIT
Consolidate index (required before new data appears in search):
After PUSH, POP, or FLUSH*, run consolidate in control mode — or wait for the automatic cycle (~180s):
START control
TRIGGER consolidate
QUIT
Search example:
START search
QUERY articles default "search terms" LIMIT(10)
QUIT
Smoke test after deploy: PING → PONG, then PUSH a test document, TRIGGER consolidate, and QUERY the indexed term.
See PROTOCOL.md for the full Sonic Channel specification.
Limitations
- No built-in web UI — integrate from your application code.
- TCP only — not compatible with HTTP health checks; use
PINGover a TCP connection instead. - Index stores IDs, not full documents — enrich results from your database.
- Consolidation delay —
QUERYdoes not see freshly pushed data until consolidate runs. POPrequires the exact indexed text and returnsRESULT N(tokens removed), notOK.FLUSHO/FLUSHB/FLUSHCremove an object, bucket, or entire collection — use with care.- SSD-backed volumes recommended for search performance.
Version
Built from valeriansaliou/sonic (default tag v1.5.1, overridable via SONIC_VERSION build arg).
Template Content