Skip to content
Edit this page View source of this page

Running a public server

By default sylphd serve is meant for a machine you trust: it listens on a Unix socket, has no limits, and sends no CORS headers. Every public-facing feature is opt-in, so local behaviour stays unchanged. This page lists the switches. Read the security notes first: sylphd has no authentication and no TLS by design.

An example deployment behind a reverse proxy:

sylphd serve --db gtdb-r232-c200-dbv2.syl2db --meta gtdb-r232.sqlite \
    --tcp 127.0.0.1:8765 --max-jobs 4 --max-contigs 100 --max-queue 16 \
    --rate-limit 10/min --trusted-proxy 127.0.0.1 \
    --cors-origin https://abrinca.github.io

Listening on TCP and reaching it with --url

--tcp HOST:PORT makes the server listen on plain HTTP. The server only speaks HTTP, so terminate TLS in a reverse proxy and bind sylphd to 127.0.0.1. Clients use the public address with --url, which accepts http:// and https:// URLs with an optional path prefix. Certificates are verified normally and the prefix is kept for every request:

sylphd query --url https://api.example.org/sylphd sample.fq.gz
export SYLPHD_URL=https://api.example.org/sylphd

See Server address.

Reverse proxy deployment

deploy/ contains a complete, reproducible setup for this pattern: a Caddy site block that terminates TLS and proxies to the Unix socket, a hardened systemd unit, an idempotent setup-server.sh, and a sylphd-update script that installs release assets with checksum verification and rolls back a failed health check. The deployment README covers first-time setup, upgrades, logs and changing the domain.

Two details matter behind a proxy. sylphd already gzips JSON bodies of 1 KB or more when the client asks for it, so the site block's encode zstd gzip only covers what sylphd sends uncompressed, and nothing is compressed twice. And the access log is sylphd's own, one line per request at INFO (--log-level warning silences it, see sylphd serve); Caddy's log block adds its own lines to the journal, so both are there when you investigate a report.

Sketches only, or raw sequences too: --allow-sequences

POST /assembly takes the sketch of an assembly, which the web app (in the browser, WebAssembly) and sylphd assembly make locally. That needs no opt-in, and a server started without --allow-sequences never receives a sequence: reads (/profile) and assemblies both arrive as sketches, which hold k-mer hashes and counts only. That is the setup for confidential data.

The optional --allow-sequences additionally accepts a raw FASTA or FASTQ on /assembly and sketches it on the server, so any language can use the server without pysylph or WebAssembly (curl example, sylphd assembly --no-local-sketch). The public instance runs with it, and so does the example policy in deploy/; for your own server it is optional. It costs the server CPU for sketching and RAM per job: an upload may be up to --max-sequence-mb (20 MB by default) and a gzip body may decompress to 5× that, so keep --max-jobs, --max-queue and --rate-limit set on a server that is open to others. Uploads are never logged: only sizes, timings and request outcomes appear in the server log, without client addresses.

Limits

Option Default Applies to Meaning
--max-jobs N 2 /profile, /query, /assembly, /contigs profiling jobs running at once; further jobs queue. A job is one sample of a /profile or /query request, one /assembly upload, or one whole /contigs request (whose contigs then run one after the other in that slot)
--max-contigs N 4096 /contigs contigs in one request (400 above it); one request is one job, so this is also the largest amount of work one client can ask for at once. A public instance should use a small value, 100 in the example below
--max-upload-mb N 512 all POSTs request body limit (413 above it)
--max-sequence-mb N 20 raw /assembly upload limit of a raw sequence before decompression; gzip bodies may decompress to 5× this. Sketch uploads use --max-upload-mb
--rate-limit N/min off /profile, /query, /assembly, /contigs per-client limit (N/min or N/s); over the limit: 429 with Retry-After
--taxonomy-rate-limit N/min off everything under /taxonomy (with --taxonomy-db) per-client limit of the taxonomy lookups alone (every request counts, an omnitax client batches many ids in one); cheap calls, so a higher number than --rate-limit, such as 120/min
--max-queue N unlimited the same jobs allowed to wait for a job slot; beyond that 503 with Retry-After: 1

/health and /info are always served and never limited. At most 4096 sketches fit in one /query or /profile request; /info reports that cap as max_sketches. For /contigs the cap is --max-contigs (4096 by default), reported as max_contigs, plus the largest JSON params part as max_params_bytes.

Set --max-contigs to a small value on a public server — 100 is a sensible one. A whole /contigs request is one job, and its contigs are queried one after the other, so the cap is what bounds how long one client can hold a job slot. The cost of a contig depends on the databases: on a .syl2db it is a few milliseconds, but every plain .syldb is scanned per contig, so on GTDB + UHGV + fungi a single contig costs roughly 0.6 s. With the default 4096, a ~5 MB upload of tiny contigs would occupy one of the two job slots for about 40 minutes; with --max-contigs 100 it is about a minute. Both sylphd assembly --per-contig and the web page batch by the advertised limits.max_contigs, so a client adapts to the value without a flag of its own.

--max-queue counts jobs, not HTTP requests, and a request is accepted or refused as a whole. /query and /profile use one job per sample, /assembly one per upload, and /contigs one per request however many contigs it carries: a hundred contigs are one job and one rate-limit hit, not a hundred. A request that does not fit within --max-jobs + --max-queue gets a 503 before any job runs. A full queue is also detected before the request body is read, so a refused upload costs almost nothing.

Sizing the upload limit

Sketches are small compared with the data behind them, but they grow with sequencing depth (and with sequencing errors). Reference points at c=200:

Input Sketch
bacterial assembly (~2.6 Mb) ~0.1 MB
1.55 GB ONT fastq.gz (2.1 Gb) 5.8 MB
56 GB paired-end reads (uncompressed) 76 MB

On the server, a 200 MB sketch (16.7 million k-mers) decodes in about 0.8 s and needs about 0.8 GB of RAM while it is profiled, so the running jobs need roughly --max-jobs × 0.8 GB at that size. In addition, an accepted upload is held in RAM as raw bytes from the moment it has been read until its job has finished, so the waiting jobs cost their upload size each (multipart parts are spooled to a temporary file while they arrive, but are read back into memory before profiling). With --max-queue set, at most --max-jobs + --max-queue jobs are admitted; without it nothing bounds the number of waiting uploads. The public instance uses --max-upload-mb 200 on a 2-core VM with 10.6 GiB of RAM (MemoryMax 9.5 GiB). These job costs come on top of the resident databases (4.15 GiB for GlobDB, UHGV and fungi), and MemoryMax must also cover the start-up peak: see serve and the GlobDB evaluation. Keep a reverse proxy's body limit a little above --max-upload-mb, so oversized uploads get sylphd's own error message.

Privileged access

To exempt yourself (or a trusted pipeline) from --rate-limit, create a token file readable by the service user and start the server with --privileged-token-file:

openssl rand -hex 32 | sudo tee /etc/sylphd/tokens >/dev/null
sudo chown root:sylphd /etc/sylphd/tokens && sudo chmod 0640 /etc/sylphd/tokens
sylphd serve ... --rate-limit 10/min --privileged-token-file /etc/sylphd/tokens

The file holds one token per line (blank lines and # comments are ignored), so a token can be rotated by adding the new one, switching clients, then removing the old one and restarting. Clients pass the token with --token-file PATH or the SYLPHD_TOKEN environment variable (preferred over a command-line value, which shows up in ps):

sylphd profile --url https://sylphd.example.org --token-file ~/.config/sylphd/token reads.sylsp

A privileged request skips only the rate limit: --max-jobs, --max-queue and upload limits still apply, so the host cannot be overloaded by it. Use HTTPS; the client refuses to send a token over plain http:// to anything but localhost. Treat the token as a password.

A wrong token is reported, not refused. The server treats a request whose token it does not know as anonymous, but every response to a request that carried a token has an X-Token-Valid: true or false header (also on errors and 429s), and GET /info says access.token_valid. The command line and the Python client print a warning once (sylphd: warning: ... does not accept this access token), so a mistyped or rotated-out token does not hide behind a rate limit. The web page shows it next to the server name.

A private server. --require-token (with --privileged-token-file) refuses every request without a valid token with 401 and WWW-Authenticate: Bearer, except GET /, /health and /info, which stay open so clients and the web page can find out that a token is needed (access.token_required in /info). Rate limits then only matter between token holders, who skip them.

In the web page. The key button in the server bar opens the token form. The token is saved in the browser's localStorage under the address of that server and sent only to it (a ?api= override to another server never receives it, and plain http:// only to localhost), so it is remembered on the next visit; Forget removes it. Anyone who can use that browser profile, or run a script on the same origin (all pages under github.io/<user> share one), can read it: do not save a token on a shared computer. A server that requires a token opens the form by itself. The server must allow the page's origin (--cors-origin), which now includes the Authorization header.

Client identity and --trusted-proxy

The rate limit needs to know who the client is. The identity is the socket peer, kept in memory for the rate limit only: no log line of sylphd or of the example Caddyfile contains it. Behind a reverse proxy that would be the proxy itself, so every user shares one bucket. With --trusted-proxy IP (repeatable) the X-Forwarded-For header of that peer is believed, and the rightmost address that is not itself a trusted proxy is used.

  • When the proxy talks to the server over the default Unix socket, use --trusted-proxy unix.
  • Without --trusted-proxy, the header is ignored entirely (a client could otherwise pick its own bucket). Unix-socket peers without a trusted proxy share one bucket called unix.

Usage statistics

--usage-db FILE turns on opt-in usage statistics; without it nothing is recorded. It answers "is this server used, by what, and is it keeping up?" without learning about any user: successful requests per ten-minute window, endpoint and kind of client (web page, sylphd command line and its version, other), with contigs, samples, bases and sketch bytes, a coarse histogram of job time and queue wait, and the peak queue depth. Never IP addresses or hashes of them, unique visitors, names, results or parameters. The totals are public at GET /usage, summarised by the web page in a modal dialog (and at /#usage); the exact fields are in the HTTP API and the flag in sylphd serve.

Because it is a statement to your users, it is announced:

  • /info reports usage.enabled and usage.policy; the web page shows a "usage statistics on" chip in its status line and asks each visitor to agree once per server and policy before anything is uploaded (Cancel sends nothing; "Only sketch" in Reads sends nothing and needs no agreement). Raise POLICY in sylphd/usage.py whenever what is tracked changes so everyone is asked again;
  • the command line prints one note to stderr per run that sends work.

Both rely on what the server says about itself; they do not verify it. Say in your --about text or terms what you do with the numbers. Keep the file on a writable, backed-up directory; it is a small SQLite file (rows only exist for windows with traffic). Combine it with the access log settings above: neither stores a client address.

CORS

A browser page on another origin may only call the API if the server allows its origin. --cors-origin (repeatable) controls this. Preflights allow GET and POST with the Content-Type request header, and Retry-After and X-Request-Id are exposed to JavaScript.

Value Effect
none (default) no CORS headers; browsers on other origins cannot call the API
'*' any origin; answered with Access-Control-Allow-Origin: *
https://example.org that origin only; repeat the flag for several
local localhost, 127.0.0.1, 0.0.0.0 and [::1] on any port, for development

'*' is safe for a public instance because the API uses no credentials or cookies. CORS is a browser rule, not access control: see the security notes.

Describing your instance

--name TEXT and --about FILE let you tell visitors what this server is, for example which database it holds. The web app shows both in a panel at the top of every page under Details ▾: the name as an Operator fact and the full description headed From the server operator. GET /info reports them as name and about (see the HTTP API); both are absent when you set nothing.

sylphd serve --db data/gtdb-r232-c200-dbv2.syl2db --meta data/gtdb-r232.sqlite \
    --name "GTDB r232" --about /etc/sylphd/about.md

with /etc/sylphd/about.md containing, for example:

This sylphd server contains the [official pre-built](https://sylph-docs.github.io/pre%E2%80%90built-databases/)
gtdb-r232-c200-dbv2.syl2db database. It contains 199,923 prokaryotic species from GTDB r232, but no
eukaryotes (fungi, human, etc.).
  • Terms of use: if your instance has any, put them into the about text, or into an info operator message that links to them (the terms of the Abrinca web service are one example). There is no separate setting.
  • Editing without a restart: the server looks at the file's modification time and size on every /info request and re-reads it when they change. If the new file cannot be read (too large, not UTF-8, removed) the last good text stays and a warning is logged once. A bad file at startup is an error, as is a --name over 80 characters. The file may be at most 16 KiB.
  • Markdown, never HTML: the page can be pointed at any server with ?api=, so the text is untrusted. The page renders a Markdown subset with marked and sanitizes the result with DOMPurify and an allowlist: paragraphs, **bold**, *italic*, `code`, code blocks, [text](url) links, lists, # headings (shown small) and > quotes. Only http:, https: and mailto: links are kept, and they open in a new tab. Anything else (raw HTML, images, tables, other link targets) is not rendered; the text of a dropped tag stays as text.
  • Trust: when a visitor has connected to a server other than the page's default, the page adds "This text comes from the server you connected to; sylphd does not verify it."

Operator messages

--messages FILE publishes short notices: a standing licence note, a warning about a slow database, a maintenance announcement. The file is UTF-8 JSON, a list of objects with exactly the keys level, title and message:

[
  {"level": "info", "title": "Data licence",
   "message": "Results contain GlobDB and GTDB data, both licensed [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/). [Details](https://abrinca.github.io/sylphd/terms.html)"},
  {"level": "warning", "title": "Slow today",
   "message": "A database is being rebuilt; expect **longer** waits."},
  {"level": "danger", "title": "Maintenance",
   "message": "The service stops at 22:00 UTC."}
]

deploy/messages.example.json holds the two standing info messages of the public instance.

  • Levels: info (neutral), warning (amber) and danger (red). The web page shows them in a compact area directly under the server status bar. info and warning have a small ×; the page remembers the dismissal in the browser (localStorage) under a hash of level, title and message, so a message whose text you change appears again. danger cannot be dismissed.
  • Command line: sylphd profile, query and assembly (also --per-contig) fetch the messages once per run and print warning and danger on stderr (sylphd: warning: TITLE: text, links as text (url)), but not info. -q silences them where the command has it. A server without the endpoint, a slow one (3 s) or an error never affects the run.
  • Limits: at most 20 messages, title one line of at most 120 characters, message Markdown of at most 2000 characters, file at most 64 KiB. Unknown keys, other levels and non-strings are errors. Markdown is rendered as for the about text (a safe subset, never HTML).
  • Editing without a restart: like --about, the file is re-read when its modification time or size changes. If the new file is invalid the last good list stays and a warning is logged once; a bad file at startup is an error. The web page picks changes up when it connects (reload or reconnect); clients fetch them per run.
  • Public and untrusted: GET /messages is open (see the HTTP API), so do not put anything private in it.

The licence that /info reports per database comes from the catalogue, not from this file.

Using the web app against your server

The web app is a static page in web/ that calls GET /info and POST /assembly of a server (Assembly mode: it sketches in the browser and sends the sketch, so no --allow-sequences is needed), POST /contigs (Assembly mode with Per contig checked, see Identifying an assembly) and POST /profile (Reads mode, see Profiling reads in the browser; it works on any server, with a metadata database for the taxonomy). web/config.js holds two addresses: apiBase, the public server used by the published page (the public instance), and devApiBase (http://127.0.0.1:8765), used only when the page itself is opened from localhost. The published page never contacts the visitor's own machine by default, because browsers ask for "local network access" permission when a public site does that. The ?api= query parameter overrides both per visit:

scripts/preview-pages.sh
# open http://127.0.0.1:8000 (uses devApiBase), or add ?api=http://host:port

The script builds the docs and assembles the site like the Pages workflow (the web app at /, the docs at /docs/), so links from the page into the docs work. It also builds the WebAssembly sketcher (needed by the Reads and Assembly modes, which sketch in the browser) into web/wasm/ (needs cargo and wasm-bindgen-cli; SKIP_WASM=1 skips it). Serving web/ alone with python -m http.server -d web also works, but the docs links then return 404, and without web/wasm/ (rust/sylphd-wasm/build.sh) neither mode can sketch; only a ready-made .sylsp upload works.

For local development start the server with --cors-origin local. The browser must be allowed by the server's CORS origins, and an HTTPS page can only call an HTTPS API (or localhost).

When the page cannot use its server (none configured or unreachable) it shows a banner above the form, and the submit button is disabled. The banner has a Use another server form: enter the API URL of your own server (for example http://127.0.0.1:8765) and press Connect; the page reloads with ?api=<url>. The header then shows the active URL with a reset link that removes ?api=. The server must allow the page's origin (--cors-origin https://abrinca.github.io, or --cors-origin '*'), and for a server on localhost the browser may ask for permission to access devices on your local network.