Syncing from a national terminology service
A national terminology service publishes its releases in an Atom syndication feed: one entry per downloadable item, with the canonical identifier, the version, the date, and a digest. Some services keep their FHIR resources behind their FHIR API instead, and the sync lists that API as if it were a second feed. The FerroTERM sync service reads both on a schedule, takes what you subscribed to, builds or stages it, and asks the server to reload. It runs beside the server and never inside it, and it moves content in one direction only.
What one run does
- It reads each configured feed, and the FHIR API of a source that has one
(a search per
CodeSystem,ValueSet, andConceptMap, paged to the end), and compares what they offer with what you already serve: the releases under your index root, the resources in your managed directory, and the ledger of what the service itself put there. - It takes the entries you subscribed to that you do not hold yet, streams each one to the staging directory, and refuses any whose digest does not match what the feed advertised. A resource read from a FHIR API carries no advertised digest; the run records the digest of what arrived instead.
- An RF2 archive goes through
ferroterm-buildinto a staging directory and is renamed into the index root as a new release beside the previous one. A FHIR resource is written as a file in the managed resource directory, corrected first when its service needs a correction. - It asks the server to reload, then prunes the releases retention no longer keeps and tells the server about that too.
- It writes one JSON record of everything above and posts a summary to your webhook, whether the run worked or not.
A run that fails leaves the served set exactly as it was. A build that fails
never reaches the index root, and a reload the server refuses is rolled back,
including a resource file the run had replaced. A delivered resource is served
at the id it carries, so a delivery whose id another loaded or persisted
resource of the same type already answers on is one of the reloads the server
refuses (see
What a code system version is served as). Nothing is deleted except by
retention, and the server’s own write store (FERROTERM__TERMINOLOGY__RESOURCES) is never
touched.
Running it
The service runs as its own image, ghcr.io/ferrohealth/ferroterm-sync,
carrying ferroterm-sync and ferroterm-build, and the Compose overlay runs
it beside the server over one volume. Every release publishes the
image for linux/amd64 and linux/arm64, with the same provenance and SBOM
attestations as the server image (Verifying releases),
and compose.sync.yaml pulls it at the release’s tag.
To run a commit no release carries, build the image
from docker/Dockerfile.sync. The file copies the two binaries from a staged
dist/linux/<arch>/ tree, built for the musl target of your platform (on
Linux, with musl-tools installed):
cargo build --release --locked --target x86_64-unknown-linux-musl \
-p ferroterm-sync -p ferroterm-build
mkdir -p dist/linux/amd64
cp target/x86_64-unknown-linux-musl/release/ferroterm-sync \
target/x86_64-unknown-linux-musl/release/ferroterm-build dist/linux/amd64/
docker buildx build -f docker/Dockerfile.sync --platform linux/amd64 \
-t ghcr.io/ferrohealth/ferroterm-sync:0.4.9 --load .
The tag is the one compose.sync.yaml names, so Compose runs the image you
built. With a published release, skip the build and run the overlay:
FERROTERM_SYNC_DATA=/srv/ferroterm FERROTERM_SYNC_CONFIG=/srv/sync.toml \
docker compose -f compose.yaml -f compose.sync.yaml up
One directory on one filesystem holds index/, codesystems/, staging/,
records/, and state/. That is not a convenience: a run stages a release and
then renames it into the index root, and a rename works only inside one
filesystem. The server mounts index/ and codesystems/ read-only; the sync
mounts the whole tree and writes to it as uid 65532.
The overlay also sets FERROTERM__ADMIN__LISTEN=127.0.0.1:8081 on the server,
because POST /reload on that listener is how the sync asks for the new
release to be served, and runs the sync in the server’s network namespace, so
it reaches that listener and the FHIR base over loopback. Nothing outside that
namespace reaches the admin listener or the sync’s own listener, the console
included; the console page says what that means for Reload and
the run findings. That listener is a guarded surface, so the server starts only once
[auth] names an issuer in an [auth.issuer.<name>] table, with
[server_admin.credentials.oauth] in the sync configuration, or turns
authentication off (see
Configuration).
ferroterm-sync run-once performs a single run and exits, which is what a
first run and a cron-style deployment use.
Configuration
One TOML file, named by --config <path> or by FERROTERM_SYNC_CONFIG (the
container image sets /etc/ferroterm/sync.toml). A variable
FERROTERM_SYNC__<SECTION>__<KEY> sets one key over the file
(FERROTERM_SYNC__RETENTION=4, FERROTERM_SYNC__SCHEDULE__AT=03:00), and
--set key=value sets one over both. Every key is optional and falls back to
the value below; a key, or a FERROTERM_SYNC__ variable, that the service
does not know is refused at start-up rather than ignored. ferroterm-sync config check
prints every key with where it came from, every secret as ***.
A refused configuration ends serve, run-once and config check with exit
code 78 (EX_CONFIG, sysexits(3)), and healthcheck with not up and 1.
| Key | Default | What it names |
|---|---|---|
listen | 127.0.0.1:8181 | the service’s own admin listener |
[server_admin] | url = "http://127.0.0.1:8081", timeout = "30min", one try | the server’s admin listener, which serves POST /reload (see The outbound endpoints) |
[fhir] | none | the server’s FHIR base, which the revalidation reads |
index_root | /data/index | the index root the server reads |
resources | /data/codesystems | the managed resource directory the server reads |
staging | /data/staging | where a run downloads and builds |
records | /data/records | one JSON record per run |
state | /data/state | what the service remembers between runs |
retention | 2 | release directories kept per code system |
activation | auto | auto or manual |
[webhook] | none | where one JSON summary per run is posted |
timezone | UTC | the zone a daily schedule is read in |
build_command | ferroterm-build | the offline build, on PATH or by path |
listing_limit | 64MiB | the most bytes one listing answer takes, the feed or one page of a FHIR API search; a listing is read into memory to be parsed, so its bound sits far below download_limit, which bounds bytes streamed to disk |
download_limit | 4GiB | the most bytes one download takes, a data size; a larger item is refused, its partial file removed, and the run record names it |
[auth] | on, no issuer | the credentials the admin listener admits (see The admin listener); [auth] post_quantum_only = true holds every issuer to ML-DSA-44, ML-DSA-65 or ML-DSA-87 (RFC 9964), as on the server |
[nts] | url = "https://terminologieserver.nl", timeout = "1h", the realm’s issuer, no client | the NTS the add-on calls and the client it authenticates as (see Credentials) |
[telemetry] | auto format, no export | the console log’s format and filter (RUST_LOG sets the filter too), and the OTLP export of the service’s metrics, the same section the server reads (see Telemetry) |
A [[source]] entry names the add-on that reads a service and carries that
add-on’s own block:
index_root = "/data/index"
resources = "/data/codesystems"
staging = "/data/staging"
records = "/data/records"
state = "/data/state"
retention = 2
activation = "auto"
timezone = "Europe/Amsterdam"
[server_admin]
url = "http://127.0.0.1:8081"
[fhir]
url = "http://127.0.0.1:8080/r4b"
[schedule]
at = "03:00"
[[source]]
kind = "nts"
[source.config]
systems = ["http://snomed.info/sct/11000146104", "http://loinc.org"]
An add-on whose service keeps resources behind its FHIR API lists that API by
default; the NTS block takes fhir_api = false to keep a run to the feed and
fhir_api_url to point at another endpoint.
The file needs no secret in clear. The NTS account’s secrets can each be a
mounted file (password_file, client_secret_file) or a variable, and the
reload call reads its own from the file [server_admin.credentials.oauth]
names, so the file can stay safe to commit and safe to show.
The outbound endpoints
Every URL the service sends a credential to, or takes content from, is
https, or plain http on a loopback host (localhost, 127.0.0.1 or
::1): [server_admin], [webhook], [nts], the issuer and token endpoint
of each client credentials grant, and a source’s feed_url and
fhir_api_url. Any other plain http URL refuses the start, naming the key,
the rule the server holds for its own issuer and usage report collector. To
reach a server’s admin listener on another host, give it [server.tls]
(The HTTP server) and the sync
[server_admin.tls].
[server_admin], [fhir], [webhook] and [nts] are the family’s outbound
endpoint table, the keys every FerroHEALTH product writes for a call it
makes: url, timeout, connect_timeout, retry (max_attempts,
initial_backoff, max_backoff; a call that did not connect, timed out or
met a 5xx is tried again), tls (the outbound TLS table of
Configuration) and credentials. A key a
table leaves out keeps its default: [server_admin] keeps the defaults
above (timeout = "30min", one try, since a reload takes as long as a
server start), [nts] keeps its own (see Credentials), and
[fhir] and [webhook] take the family’s
(timeout = "10s", three tries).
The credential of the reload call
The server’s admin listener requires a credential carrying its admin scope
(Configuration), and
[server_admin.credentials.oauth] names the one the sync presents: a token of
the OAuth 2.0 client credentials grant (RFC 6749 §4.4) from an authorization
server the server trusts, fetched before the call, kept until shortly before it
expires, and fetched once more when the server answers 401. The reload is a
machine’s call and a Basic user is a person, so the sync takes no Basic
credential:
[server_admin.credentials.oauth]
issuer = "https://auth.example.org/realms/tx" # or token_endpoint = "…"
client_id = "ferroterm-sync"
client_secret_file = "/run/secrets/sync-client-secret"
scope = "__ferroterm.admin"
| Key | Meaning | Default |
|---|---|---|
oauth.issuer or oauth.token_endpoint | where the token endpoint is read from, or the endpoint itself; exactly one | none |
oauth.client_id | the client at the authorization server | none |
oauth.client_auth | client_secret_basic, client_secret_post or private_key_jwt | client_secret_basic |
oauth.client_secret or oauth.client_secret_file | the client secret; exactly one | none |
oauth.private_key_file, oauth.kid, oauth.assertion_alg | the PEM key, kid and algorithm of a private_key_jwt assertion (RFC 7523) | the RFC 7638 thumbprint, the algorithm of the key |
oauth.dpop_key_file | the PEM key the tokens are bound to with DPoP (RFC 9449): a P-256 or P-384 key signs its proofs ES256 or ES384, an ML-DSA key its parameter set (RFC 9964) | none (bearer tokens) |
oauth.scope, oauth.resource, oauth.audience | the token request’s scope, RFC 8707 resource and audience parameters | none |
oauth.refresh_margin | how long before the token expires a new one is fetched | "30s" |
oauth.timeout | how long one call to the authorization server may take | "10s" |
[server_admin.credentials.oauth.tls] | the outbound TLS table of the token calls (see Configuration) | none |
A client that authenticates with private_key_jwt signs its assertion with
the algorithm of its key. An ML-DSA-65 key (RFC 9964), made with OpenSSL 3.5
or later as openssl genpkey -algorithm ML-DSA-65 -out sync-assertion.pem,
signs ML-DSA-65; register its public half at the authorization server as an
AKP key. A DPoP key works the same way: a second ML-DSA-65 key, made as
openssl genpkey -algorithm ML-DSA-65 -out sync-dpop.pem, signs every DPoP
proof with ML-DSA-65, and the authorization server binds the tokens to it:
[server_admin.credentials.oauth]
issuer = "https://auth.example.org/realms/tx"
client_id = "ferroterm-sync"
client_auth = "private_key_jwt"
private_key_file = "/run/secrets/sync-assertion.pem"
dpop_key_file = "/run/secrets/sync-dpop.pem"
scope = "__ferroterm.admin"
With the table empty the call carries no credential, which only a server with
[auth] turned off accepts. There is no static token, and the table takes no
Basic user or password.
The schedule
Two shapes, and no cron syntax:
every = "24h"measures from the end of the last run. It is a duration: a whole number and a UCUM unit (ms,s,min,h,d), such as"90min"or"7d".at = "03:00"is a time of day intimezone.
An interval of zero ("0s") is refused at start, naming schedule.every:
each run would be due the moment the last one ends, and the service would
never wait. A value that is no such duration, the ISO 8601 "PT24H" and the
friendly "1h 30m" among them, refuses the start too.
With both, the earlier due time wins. With neither, the service runs only when you ask it to. The end of the last run is written to the state directory, so a restart between two runs does not replay the run that already happened: a service that ran at 03:00 and restarts at 04:00 is next due at 03:00 the following day. A window the service was down for is due at once.
A run also starts on POST /run on the admin listener, and as
ferroterm-sync run-once.
Activation
In auto the run renames what it built into the index root and asks the server
to reload, in the same run. In manual the run stops after staging: nothing is
served, the run record says how many items wait, and POST /activate puts them
in front of the server when you are ready. What is staged survives a restart,
and a later run does not build it again.
An activation is not a synchronisation run: it gets its own run record, and it leaves the schedule where it was, so the next scheduled run still starts at its own time.
What a new release did to your own content
A release can retire a code your own value set enumerates, remove it, or leave
it outside the value set it was included through. After a release is activated
the service revalidates every locally authored ValueSet and ConceptMap
against the set now being served and writes what it found into the run record.
It reports and never edits. A finding is a decision for a terminologist, and the service changes nothing in your content, ever.
Set [fhir] url to the server’s FHIR base, such as
http://127.0.0.1:8080/r4b, to turn the check on. Its last segment (r4,
r4b, r5 or r6) names the FHIR release the check writes its requests in;
a base whose last segment names none refuses the start. Without [fhir]
the run record says the check did not run. The check reads the server’s public FHIR API,
ValueSet/$validate-code and ValueSet/$expand, both with activeOnly, so it
sees exactly what any client sees:
- a code that is still a member but is no longer active is
inactive; - a code the code system no longer carries is
absent; - a code that is still in the code system and no longer falls inside the value
set is
outside-value-set.
Each finding names the resource, the system, the code, and the release this run
activated for that system. A run that finds nothing says so in one sentence,
and that sentence and the finding count travel in the webhook summary.
/metrics carries ferroterm_sync_revalidation_findings as a gauge per
locally authored resource, so a resource that is clean reads zero rather than
disappearing.
The check reads the first 1000 codes of a resource and expands at most 1000 members, which keeps one run bounded; a larger resource is noted in the log.
Retention
After a successful reload the service keeps the newest retention release
directories per code system and removes the rest, then asks the server to
reload once more so the removed release leaves the served set. A release that
is still there is what you roll back to, so keep at least two. A retention of
0 removes nothing. Each run record says what was removed, how many bytes it
held, and how many bytes the index root uses afterwards.
Retention judges only directories that carry a manifest.json, so a build in
progress is never touched, and it groups them by the code system edition the
manifest names.
The admin listener
The service binds listen and serves six routes:
| Route | What it does |
|---|---|
POST /run | performs one run and answers its summary when the run has finished |
POST /activate | puts what is staged in front of the server |
GET /runs | the runs this service performed, newest first |
GET /runs/{id} | one whole run record |
GET /metrics | the Prometheus exposition |
GET /health, GET /health/liveness, GET /health/readiness | the FerroHEALTH health routes (Health) |
Every route but the three health routes requires a credential carrying the product
scope, __ferroterm.sync unless [auth] product_scope names another. The
[auth] table is the one the server reads (Configuration):
an [auth.issuer.<name>] table with its kind and audience for each issuer whose
access tokens it accepts (checked as JWTs, or at the issuer’s introspection
endpoint under mode = "introspection"), people under [[auth.basic.users]]
with their scopes in [basic_grants], or both. A machine, such as a monitor,
calls with a client credentials token, and a Basic user granted a system/
scope refuses the start. A refused
request answers 401 with a challenge naming the realm ferroterm-sync (or
[auth] realm), or 403 for a credential without the scope, with a JSON
error body.
The service refuses to start while [auth] admits no credential, unless the
file says enabled = false, which only a network that trusted callers alone
reach should:
# The console signs people in at this issuer and calls with their tokens;
# a monitor calls with its own client credentials token.
[auth.issuer.tx]
issuer = "https://auth.example.org/realms/tx"
audience = ["ferroterm-sync"]
# or a person with HTTP Basic, the hash an Argon2id PHC string:
[[auth.basic.users]]
user = "operator"
password_hash_file = "/run/secrets/operator.phc"
[basic_grants.operator]
scopes = ["__ferroterm.sync"]
Keep the listener unpublished whatever [auth] says; the Compose overlay
leaves both listeners reachable only inside the compose network.
The console’s history screen reads GET /runs and GET /runs/{id} to show
what the last run found about the resource a terminologist has open
(The console). The console’s own server makes the call, at
[ferroterm.sync] url, with the signed-in reader’s access token, so a reader
sees the findings when the identity provider grants them the product scope
and lists the sync’s audience in the token. A visitor, a reader without the
scope, or a console with no [ferroterm.sync] sees no findings.
/metrics carries ferroterm_sync_runs_total{outcome="ok"|"failed"},
ferroterm_sync_last_run_timestamp_seconds,
ferroterm_sync_entries_taken_total, ferroterm_sync_bytes_staged_total,
ferroterm_sync_index_bytes, and ferroterm_sync_revalidation_findings per
locally authored resource.
What a run record contains
One JSON file per run under records, named by the run identifier, which sorts
by time. It carries:
- the trigger, the start and end, the duration, and the outcome;
- per source: the feed address, how many entries it offered, the FHIR API
address and how many resources it listed when the source has one, what was
taken (with its origin, feed or FHIR API, the bytes, the download time, the
build time, and the corrections that were applied), what was left behind
with the reason for each one, such as a release you already serve, a delta
rather than a snapshot, Ontoserver’s binary index, or a
CodeSystemwhose content isnot-present, a count per origin (feed or FHIR API) of the entries left behind only because your subscription does not name their system or category, which a service’s FHIR API lists by the thousand, and the subscribed canonicals no listing carried at all, which means the account could not see them and never that the service lacks them; - the activation: the mode, what reached the server, what is still staged, what the server answered to each reload, and whether the run was rolled back;
- the revalidation: how many locally authored resources were read and how many codes were checked, one sentence saying what it found, and a line per local code the release made inactive, removed, or left outside its value set;
- what retention removed and how many bytes the index root uses;
- every error, in the order it happened.
The summary that /runs lists and the webhook receives counts the two kinds
apart: entries_skipped for the entries left behind with a reason of their
own, and entries_not_subscribed for those outside the subscription. The
webhook receives one POST per run end, on success and on failure. A delivery that fails is logged and never fails the run.
NTS (Nationale Terminologie Server)
The NTS
is the Dutch national terminology service, run by Nictiz. It serves FHIR R4 and
publishes its content at
https://terminologieserver.nl/synd/syndication.xml. The feed is challenged:
the listing itself answers 401 with a bearer challenge, so the add-on
authenticates before it can even see what is on offer.
The account and the licences
You need a personal account on the NTS. Nictiz issues it after you accept its terms, and each licensed system is unlocked per account. Seen from the outside, that scoping looks like this:
- The syndication feed lists Ontoserver binary indexes of the SNOMED CT
Netherlands edition, each marked
onto:permissionsnomed.read, and no RF2 archive and no FHIR resource or package, so the feed alone gives the sync nothing it can build or serve. The FHIR content lives behind the FHIR API of the same service, which the add-on lists beside the feed. The SNOMED CTCodeSystemresources there carrycontentnot-presentand are reported, never served. - The feed identifies SNOMED CT as
http://snomed.info/sctand carries the edition in the version URI (http://snomed.info/sct/11000146104/version/20260831). - A system the account holds no licence for is hidden, not absent:
$lookupon LOINC or the NHG tables answers404naming the current version (http://loinc.org|2.83,http://hl7.org/fhir/sid/icpc-1-nl|12), and a search by that URL returns zero resources. SNOMED CT, ICD-10-NL, the Labcodeset LOINC supplement and its three maps, UCUM, and the zib value sets are visible to an account that accepted the SNOMED CT terms only.
Ask Nictiz for each licence you need and check what your account sees before you subscribe to a canonical. The content stays licensed by its publisher. FerroTERM distributes none of it, and a deployment brings what it is licensed for.
Credentials
The add-on authenticates with the OAuth 2.0 client credentials grant (RFC 6749 §4.4), as a confidential client Nictiz issues to your deployment; ask Nictiz for one beside your account. The NTS realm publishes the grant, and Nictiz’s own authentication examples use it (https://github.com/terminologieserver/ontoserver_authentication_examples). The password grant the Nictiz manual describes for a personal account is not supported: RFC 9700 §2.4 says it MUST NOT be used.
[nts] is the family’s outbound endpoint table (see
The outbound endpoints) for the service every
nts source calls: its base url, timeout ("1h", since a download of a
whole edition is one call), connect_timeout ("30s"), retry, tls, and
the client under [nts.credentials.oauth]. A key the table leaves out keeps
that default, so a deployment writes only its client. The secret is set
inline or through its _file sibling, which names a mounted file; setting
both refuses the start. Keep the secret out of the file you commit: set it
as a variable or mount it.
| Key (variable) | What it holds |
|---|---|
nts.credentials.oauth.client_id (FERROTERM_SYNC__NTS__CREDENTIALS__OAUTH__CLIENT_ID) | The OAuth 2 client identifier Nictiz issued |
nts.credentials.oauth.client_secret (FERROTERM_SYNC__NTS__CREDENTIALS__OAUTH__CLIENT_SECRET), or client_secret_file | Its client secret |
[nts.credentials.oauth]
client_id = "your-client"
client_secret_file = "/run/secrets/nts-client-secret"
The add-on reads the token endpoint from the realm’s OpenID Connect Discovery
document, at
https://terminologieserver.nl/authorisation/auth/realms/nictiz/.well-known/openid-configuration
(nts.credentials.oauth.issuer, which defaults to that realm), sends the
secret in the request body (client_auth = "client_secret_post"), and fetches
a new token a minute before the cached one expires
(refresh_margin = "1m"), so an unattended run on any day needs no person.
No run against the live NTS has used the client credentials grant: the token
endpoint and the listing were checked with a personal account’s password
grant, which the add-on does not offer.
The first run
Two scripts in scripts/live/ run the first hops on your own machine and
never in CI, because both need your personal licensed account:
scripts/live/nts-feed.sh reads the feed with your credentials and reports,
per system, whether the service publishes it as an RF2 archive, as FHIR
resources, or only as Ontoserver’s binary index; scripts/live/sync-e2e.sh
builds the binaries from the checkout, starts the server on an empty index
root, runs the sync once, and shows the run record and what the server serves
afterwards. Both take the FERROTERM_SYNC__NTS__* variables and print no secret.
The FerroEHR hop follows: point its quickstart overlay at the server the
second script started and commit a composition whose binding names a code the
run made available.
- Get the account, accept the terms, and confirm which systems your licences
unlock. Run
scripts/live/nts-feed.shto see the feed as your account sees it. - Put the client in the
[nts.credentials.oauth]keys as variables or mounted files, and keep them out of the configuration file you commit. - Subscribe by canonical identifier. The defaults are the SNOMED CT
Netherlands edition (
http://snomed.info/sct/11000146104), LOINC (http://loinc.org), UCUM (http://unitsofmeasure.org), and ICD-10 (http://hl7.org/fhir/sid/icd-10). The service’s own canonicals for the Dutch content are ICD-10-NL (http://hl7.org/fhir/sid/icd-10-nl), the Labcodeset (http://labterminologie.nl/cs/labconcepts, a LOINC supplement, with its maps underhttp://labterminologie.nl/cm/), NHG-Tabel 24 (http://hl7.org/fhir/sid/icpc-1-nl), the other NHG tables (https://referentiemodel.nhg.org/tabellen/nhg-tabel-NN-slug), and the zib value sets (http://decor.nictiz.nl/fhir/ValueSet/{oid}--{timestamp}). - Run once and read the run record before you activate anything. It lists every entry the feed offered, what was taken, and the reason for each entry left behind: a system you did not subscribe to, a release you already serve, or a system the service offers only as Ontoserver’s binary index, which is an internal package format and is reported as not syndicable.
- Check the corrections. The freely published NHG ICPC-1 to SNOMED CT map
file writes
experimentalas the string"true", and the add-on writes the boolean FHIR declares before the file is served. The service itself servesexperimentalas a boolean on every resource it lists , so the correction concerns files taken from elsewhere. Every correction is listed with the element it changed; a file that needs none lands byte-identical.