Introducing a new way to review your PRs.

Read the announcement

helixdb / helix-db

HelixDB is an OLTP graph database with native vector and full-text search built in Rust on Object Storage.

View on GitHub

27 documents · Updated Nov 23, 2026

docs / server-configuration-and-state

Server configuration and state

The server runtime turns process configuration into one opened database and two transport services. It owns the shared state that lets HTTP and gRPC use the same query path, database mode, index readiness view, and shutdown boundary. This page covers the runtime side of server and transports; protocol behavior is described in HTTP and gRPC server.

Server bootstrap

The server starts by loading environment settings, deriving storage and runtime policies, opening the selected database, and creating both public transports around one shared state object. The small binary entry point delegates all lifecycle work to the reusable server runtime in crates/…/lib.rs.

When startup succeeds, the runtime has one database identity and two listeners. A failure while parsing configuration, validating cache resources, or opening storage stops startup before either transport is launched.

The bootstrap flow moves through these stages:

  1. Initialize tracing from RUST_LOG or the server default filter.
  2. Read and validate server settings.
  3. Convert storage settings into a database source and runtime policy.
  4. Claim cache resources and open a writer database for the server.
  5. Build shared state and start HTTP and gRPC tasks.
  6. Wait for an external shutdown signal or the first transport to finish.

This diagram shows how process startup creates the transport boundary and how the same boundary later closes the database.

flowchart TD
    A[Process entry point] --> B[Load environment configuration]
    B --> C[Build database source and runtime policy]
    C --> D[Claim cache and open HelixDB]
    D --> E[Create shared ServerState]
    E --> F[Start HTTP transport]
    E --> G[Start gRPC transport]
    F --> H[Supervise shutdown]
    G --> H
    H --> I[Join both transports]
    I --> J[Close metrics and database]

References: crates/…/main.rs• L1-4 crates/…/lib.rs• L46-80 crates/…/lib.rs• L226-314

Server configuration

ServerConfig defines the listener addresses, logical database path, storage source, cache policy, and search queue limits used by the standalone server. It keeps process settings separate from the database runtime, then maps them into the database source and runtime configuration at the bootstrap boundary.

The environment contract is intentionally small:

ConcernEnvironment settingDefault or rule
HTTP listenerHELIX_HTTP_ADDR or HTTP_ADDR0.0.0.0:8080
gRPC listenerHELIX_GRPC_ADDR or GRPC_ADDR0.0.0.0:8081
Logical database pathDB_PATHdb/
Local durable storageHELIX_DATA_DIRSelects disk storage when set
S3-compatible storageS3_BUCKETSelects object storage when set
S3 regionS3_REGION, then AWS region settingsus-east-1 when absent
S3 endpointAWS_ENDPOINT or AWS_ENDPOINT_URL_S3No custom endpoint when absent
Plain HTTP for S3 endpointAWS_ALLOW_HTTPDisabled unless true or 1
Disk cache rootHELIX_DISK_CACHE_DIROptional for local storage; /var/cache/helix for S3
Disk cache sizeHELIX_DISK_CACHE_BYTESBounded default when absent
Cache memory sizeHELIX_DISK_CACHE_MEMORY_BYTESDatabase cache default when absent
Cache startup warmHELIX_DISK_CACHE_WARMon unless set to off
Strong vector search boundHELIX_STRONG_VECTOR_SEARCH_MAX_PENDING_BYTESDatabase queue default
Strong text search boundHELIX_STRONG_TEXT_SEARCH_MAX_ANALYSIS_BYTESDatabase queue default

The server uses memory storage when neither a local data directory nor an S3 bucket is configured. Local and S3 storage are mutually exclusive. Invalid socket addresses, cache settings, search queue limits, and required cache resources are rejected as configuration errors before storage opens.

The logical database path identifies the database inside the chosen store. For disk storage it is rooted below HELIX_DATA_DIR; for S3 it identifies the database within the bucket. This separation lets the server keep one configuration shape while changing the storage system below it.

References: crates/…/config.rs• L57-72 crates/…/config.rs• L74-128 crates/…/config.rs• L130-154 crates/…/config.rs• L253-341 crates/…/lib.rs• L73-101

Cache policy

The cache policy adds a local read tier in front of durable storage when the selected backend can benefit from it. Local disk storage may use memory-only caching or an explicit hybrid cache. S3 storage always uses a hybrid cache so repeated reads do not depend only on remote object fetches.

The cache has three broad behaviors:

  • It divides one disk budget between database objects, database blocks, and full-text data.
  • It can warm useful database data in the background after storage opens.
  • It claims its root with an exclusive lock so two standalone servers do not share one cache directory.

Startup warm does not delay server readiness. With warm disabled, the tiers fill as queries read data. An unset default disk budget must fit the cache file system. An explicit budget is accepted with a warning when the available space is smaller.

The server keeps the cache lock until the shared database closes. On Unix, it also checks the required open-file limit before storage opens and raises the soft limit when the operating system allows it. This makes cache resource failures occur at startup instead of during request handling.

ServerConfig::db_config combines the selected storage, cache behavior, and index queue limits into the database runtime configuration. It avoids copying locally durable files into a local cache while allowing S3 storage to cache data written by the server.

References: crates/…/config.rs• L156-224 crates/…/config.rs• L344-370 crates/…/config.rs• L373-407 crates/…/config.rs• L445-568 crates/…/config.rs• L625-655 crates/…/config.rs• L704-750 crates/…/lib.rs• L64-101 crates/…/lib.rs• L104-149

Shared server state

ServerState is the transport-facing ownership object. It holds a shared Arc<HelixDB>, one HelixQueryService, the database mode captured at open time, the index runtime readiness value, the storage identity used for diagnostics, shared diagnostic facts, and the server start time.

Both transports receive clones of this state. The clones do not create separate databases. They point to the same database runtime and therefore share writes, reads, query behavior, readiness information, diagnostics, and lifecycle authority.

The state exposes the connections that transports and server diagnostics need:

State valueRole at the transport boundary
Shared database handleOwns storage and runtime resources
Query serviceProvides the common request execution path
Database modeDistinguishes writer and read-only behavior
Index readinessSupplies liveness and readiness status
Opened storage identitySupports storage-aware diagnostics
Diagnostic factsShares I/O-backed diagnostic results across state clones
UptimeMeasures time since the database opened
Blocked index entity countReports writer index work that cannot currently publish
Writer flush operationSupports explicit durable write acknowledgement

The server starts query metrics once for the server process. ServerState passes the recorder into the query service when it is available. A metrics setup error disables server query metrics without preventing query service startup.

References: crates/…/state.rs• L10-47 crates/…/state.rs• L50-83 crates/…/state.rs• L85-99 crates/…/lib.rs• L271-300 crates/…/lib.rs• L401-418 crates/…/query_service.rs• L27-49

Transport and database connections

The HTTP and gRPC handlers are thin protocol layers over the shared query service. Each accepts its protocol request, checks transport options against the request type and database mode, invokes the query service, and maps the common result or error into its protocol format.

Neither transport selects a different database or query engine. Both use the default unscoped data area through the query service entry point. A tenant ID carried for metrics identifies telemetry only; it does not select a storage namespace.

The request path is:

  1. The transport receives a query body and transport options.
  2. The transport decodes the query request.
  3. The transport rejects options that do not match the request or database mode.
  4. HelixQueryService validates the request and selects execute or warm mode.
  5. The database prepares a planner view and executes the query.
  6. A write may flush the writer when the caller requests durable acknowledgement.
  7. The transport returns the shared response shape or a protocol-specific error.

This diagram shows the common database connection used by both public transports.

flowchart LR
    H[HTTP request] --> HS[HTTP handler]
    R[gRPC request] --> GS[gRPC handler]
    HS --> QS[HelixQueryService]
    GS --> QS
    QS --> DB[Shared HelixDB]
    DB --> OUT[Query result or service error]
    OUT --> HS
    OUT --> GS

HTTP exposes /healthz, /readyz, and /v2/query. gRPC exposes the matching health and query methods through the generated server contract. The two protocols use different error envelopes, but they preserve the same service error meaning and stable error code.

References: crates/…/http.rs• L21-46 crates/…/http.rs• L48-117 crates/…/grpc.rs• L22-39 crates/…/grpc.rs• L59-125 crates/…/query_service.rs• L74-134 crates/…/query_service.rs• L175-200

Database runtime ownership

HelixDB is the database runtime owned by the server. It groups the storage handle with caches, runtime index catalogs, index workers, migration workers, query metrics, and close state so that all clones observe one database identity.

The server opens a writer handle through open_for_server. This path uses the configured object store and leaves server-level query metrics under server ownership. Database open also performs the startup work needed to make storage and runtime metadata usable before requests are accepted.

The database can run in writer or read-only mode. The standalone server opens as a writer, while the database API also supports reader handles for other hosting paths. The query service checks the mode before a write, and a request that requires a writer fails when the handle is read-only.

References: crates/…/lib.rs• L634-703 crates/…/lib.rs• L782-829 crates/…/lib.rs• L1224-1253 crates/…/query_service.rs• L283-321

Startup migration boundary

Writer startup prepares durable storage before the database runtime becomes public. The startup pipeline checks and bootstraps storage metadata, runs required blocking migrations, reconciles index operation records, loads the runtime catalog, and then finishes migrations that need the complete runtime.

This ordering matters because transport requests must see a coherent storage format and catalog. A malformed or incomplete bootstrap state causes database open to fail instead of starting transports over partial state.

References: crates/…/pipeline.rs• L1-29 crates/…/bootstrap.rs• L23-37 crates/…/bootstrap.rs• L40-109 crates/…/lib.rs• L888-954

Background runtime workers

The writer runtime may own background index and migration workers. These workers process durable lifecycle work while the server handles requests, and their supervisors remain attached to the database handle.

The ownership rule is one-way: workers use database storage, but the database close path stops and joins the workers before it closes storage or caches. This prevents a worker or request task from using resources after their owner has closed them.

References: crates/…/lib.rs• L679-703 crates/…/lib.rs• L1175-1221 crates/…/worker.rs• L41-71 crates/…/lib.rs• L1720-1794

Lifecycle and shutdown

The server uses one watch channel to broadcast shutdown to both transports. A process signal, an injected shutdown future, or the first transport task to finish starts the same shutdown sequence.

The supervisor always joins both transport tasks before it polls the database close operation. This rule applies when a listener fails as well as during a normal signal-driven stop. It keeps request work from outliving the shared database and its index workers.

The shutdown sequence is:

  1. Broadcast the stop signal to HTTP and gRPC.
  2. Join the HTTP task.
  3. Join the gRPC task.
  4. Stop server query metrics.
  5. Close the exact database handle shared by both transports.
  6. Release the cache lock after database close.
  7. Return the first transport or close error to the caller.

run_with_shutdown provides a deterministic boundary for service managers and tests. run_until_ctrl_c provides the same boundary for callers that want the server to own Ctrl-C handling. run_from_env adds environment loading and platform signal handling. On Unix, both SIGINT and SIGTERM request graceful shutdown.

References: crates/…/lib.rs• L53-62 crates/…/lib.rs• L196-232 crates/…/lib.rs• L259-314 crates/…/lib.rs• L316-399

Change checklist

When these files or sections are changed, remember to consider these:

  • If ServerConfig changes a storage, cache, listener, or queue setting, update the database source and runtime mapping and the deployment settings that provide those names.
  • If cache ownership, warming, or open-file requirements change, check the cache lock lifetime, process limits, and database close path.
  • If ServerState changes its query service, readiness inputs, storage identity, or diagnostic facts, check both HTTP and gRPC health and query handlers because they consume the same state contract.
  • If a transport adds a request option, keep its validation aligned with query type, writer mode, and durable flush behavior in the other transport.
  • If the database open mode changes, review writer-only request behavior and the health mode reported by both transports.

Important failure modes

TriggerConsequenceGuard
HELIX_DATA_DIR and S3_BUCKET are both setServer startup returns a storage configuration errorConfiguration rejects mutually exclusive backends
A cache setting is used with memory storage or without a required cache directoryConfiguration fails before storage opensCache settings are valid only for a selected durable backend and root
Two standalone servers use one cache directoryThe second server does not start with that cacheThe cache root uses an exclusive lock
The process file limit is below the cache requirementServer startup fails before storage opensThe runtime validates and raises the soft limit when possible
The unset default cache budget does not fit its file systemServer startup fails rather than silently filling the file systemThe default budget is checked before storage opens
Listener address or positive byte setting cannot be parsedThe server does not start either transportConfiguration validates addresses and queue limits first
Writer bootstrap metadata is incomplete or unsupportedDatabase open fails rather than serving partial stateStartup preflight validates the bootstrap tuple
A write runs on a read-only database handleThe query fails with a writer-mode errorQuery service and transport options check database mode
A transport task exits or fails firstThe peer transport is asked to stop, then the database closesSupervisor broadcasts shutdown and joins both tasks
A caller requests durable acknowledgement and writer flush failsThe query is not acknowledged as durableHTTP and gRPC flush before returning success

Key files

FileWhy to read it
crates/…/lib.rsShows the complete server bootstrap, cache resource checks, supervision, metrics, and shutdown flow
crates/…/config.rsDefines environment settings, storage selection, cache policy, and database runtime policy
crates/…/state.rsDefines the shared transport state and its database-facing operations
crates/…/http.rsShows the HTTP connection to shared state and query service
crates/…/grpc.rsShows the gRPC connection to shared state and query service
crates/…/query_service.rsDefines the common request execution boundary used by both transports
crates/…/lib.rsDefines database identity, open modes, runtime resources, and close ownership
crates/…/pipeline.rsDefines the ordered writer startup migration boundary
crates/…/runtime_dependencies.rsDefines index readiness and process-local in-memory database identity