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-and-transports

Server and transports

The standalone server opens one HelixDB database and presents native queries, Cypher, and SQL through HTTP and gRPC. Both transport surfaces use the same query service and database state, so clients can use either interface without changing query behavior. The server also reports health, index readiness, and read-only setup diagnostics so an operator can tell when the process can serve traffic and what may limit it.

Runtime lifecycle

The server lifecycle starts with environment-based configuration and ends only after both transport tasks stop and the database closes. The database is opened before the listeners start, which gives every request path one shared storage identity and one controlled shutdown boundary.

flowchart LR
    A[Process start] --> B[Load server configuration]
    B --> C[Select storage and cache]
    C --> D[Claim cache and prepare process limits]
    D --> E[Open and prepare database]
    E --> F[Build shared server state]
    F --> G[Start HTTP listener]
    F --> H[Start gRPC listener]
    G --> I[Serve queries and management checks]
    H --> I
    I --> J[Shutdown signal or transport stop]
    J --> K[Stop both transports]
    K --> L[Stop metrics and close database]
    L --> M[Release cache ownership]

On startup, configuration selects memory, local disk, or S3-compatible storage and applies the index queue, write-ahead log flush, and SST compression policy. Durable storage can use a bounded local hybrid cache. The server claims that cache before it opens the database and checks the process resources needed by the cache. Database startup prepares the writer and index runtime before shared state is built. The server then creates shared state and launches both listeners. A shutdown signal or failure in either listener stops its peer before metrics, the database, and cache ownership close. crates/…/config.rs• L60-80, crates/…/config.rs• L245-266, crates/…/lib.rs• L65-94, crates/…/lib.rs• L263-313

Shared server state

ServerState is the common service context for HTTP and gRPC. It holds the opened database handle, the request-level query service, the database mode, storage description, and index runtime readiness. This arrangement keeps transport code focused on adapting requests and responses while the query service owns query execution.

The state also carries shared diagnostic facts and can attach server query metrics to the query service. A tenant header can identify telemetry for a request, but it does not select a storage namespace. The database mode still controls whether a write can run, and a request can ask the server to wait for a durable writer flush before it returns success.

References: crates/…/state.rs• L10-47 crates/…/state.rs• L50-98 crates/…/lib.rs• L271-280

Transport surfaces

The two public surfaces expose the same high-level capabilities: native query execution, Cypher and SQL execution, plan inspection, and health reporting. HTTP also exposes read-only setup diagnostics. Each query surface validates the request before it sends it to the shared query service and enforces the same maximum query body size. Cypher and SQL use the same compiled execution path, so SQL is an alternate query form rather than a separate storage path.

HTTP surface

The HTTP surface uses JSON over a small set of routes. POST /v2/query accepts a native query request and returns its JSON result. POST /v2/cypher and POST /v2/sql execute graph and relational query forms. Their /explain routes return plans without changing database state. SQL is translated and handled through the same query path as Cypher. GET /healthz reports process health, GET /readyz reports whether the index runtime is ready, and GET /v2/diagnostics reports read-only checks of storage, cache, resources, indexes, and recent query shapes.

Request headers can select warm reads, require writer mode, wait for durable writes, and provide a telemetry tenant identity. HTTP errors use JSON with a stable error code and a human-readable message. Query errors can also include compile or runtime details, while service errors use the shared failure class and may state whether a retry is safe. Invalid JSON, an oversized body, an option that does not match the query type, and database failures remain distinct.

References: crates/…/http.rs• L40-84 crates/…/http.rs• L86-239 crates/…/http.rs• L241-335 crates/…/http.rs• L337-443

gRPC surface

The gRPC surface defines the HelixDbServer service with native query, Cypher and SQL query, plan inspection, and health methods. Query requests carry JSON as bytes plus fields for warm reads, writer routing, and durable write acknowledgment. SQL and Cypher use the same execution and explain rules, including the rule that explaining a write plans it without running it. Health responses carry the same readiness, mode, and index runtime values as the HTTP health responses.

gRPC maps query failures to status classes and places the stable Helix error code in response metadata. Cypher and SQL diagnostics also carry a structured error body in status details. The generated protocol boundary keeps the wire contract explicit while the service delegates query work to the same shared state used by HTTP.

References: crates/…/grpc.rs• L15-57 crates/…/grpc.rs• L59-234 crates/…/grpc.rs• L256-351

Transport contract alignment

The transport contract is the shared behavior expected from embedded queries, the query service, HTTP, and gRPC. The contract keeps response shapes, query results, error classes, and option rules stable when a client changes access paths.

The shared test corpus checks that these paths produce the same observations. Additional checks cover nested values, folded rows, edge paths, readiness, writer routing, deadlines, malformed requests, body limits, and restart behavior. Cypher and SQL checks also confirm that HTTP and gRPC share values, errors, atomic writes, explain behavior, and durable-write rules. Failure classification is checked as a cross-surface rule: HTTP exposes an error envelope and status, while gRPC exposes the matching status class and Helix error code.

References: crates/…/transport_contracts.rs• L44-213 crates/…/transport_contracts.rs• L541-579 crates/…/transport_contracts.rs• L718-961 crates/…/transport_contracts.rs• L1037-1415 crates/…/cypher_tests.rs• L12-96 crates/…/cypher_tests.rs• L595-937 crates/…/cypher_tests.rs• L973-1044

Operational diagnostics

The diagnostics report is a read-only view of the server setup. It helps an operator find data-loss risks, slow storage paths, cache pressure, memory pressure, delayed index publication, missing indexes, and unbounded scans without changing data or configuration.

The report runs only checks that apply to the selected storage. It groups stable check IDs into storage, cache, resource, index, and query categories. Each check returns pass, warn, fail, or skip; warnings and failures include a suggested fix. I/O-heavy facts are reused for a short time, so concurrent or repeated polls do not repeat the same filesystem and network probes.

The S3 checks compare the bucket and server regions when AWS metadata is available and measure a small set of bounded round trips. Local checks inspect the data and cache backing, available space, memory limit, and cache warm policy. Query checks use recent planner insights without exposing query values. The JSON shape is the contract rendered by helix doctor.

References: crates/…/mod.rs• L1-32 crates/…/mod.rs• L115-212 crates/…/mod.rs• L215-309 crates/…/aws.rs• L1-24 crates/…/backing.rs• L1-18

Health signals

Health and readiness answer different operational questions. Liveness confirms that the server can answer a health request. Readiness also checks the database index runtime and returns unavailable when that runtime is not ready.

Both transport surfaces report four values:

SignalMeaning
readyWhether the index runtime is ready for service.
modeWhether the opened database handle is a writer or read-only handle.
index_runtimeA stable machine-readable readiness code.
blocked_index_entity_countThe number of index entities that currently block publication.

The standalone server opens a writer database through the server-specific database entry point. The shared state still exposes the mode because the transport contract must make writer requirements visible and must reject writes when a read-only handle is used by an embedding or test. The blocked count is safe for unauthenticated health checks because it does not identify tenants or entities. Direct storage without a separate text-index runtime still reports ready when its index runtime is ready. crates/…/http.rs• L56-79, crates/…/grpc.rs• L223-234, crates/…/state.rs• L75-93, crates/…/tests.rs• L1229-1285

Query execution

Each transport turns its wire request into a native QueryRequest, a Cypher request, or a SQL request. It applies transport options and sends the request to HelixQueryService. SQL is translated before it enters the shared Cypher execution path. The service performs the shared validation and execution path, then returns a query result or a plan that the transport serializes in its native response form. Explain requests use the read contract because they inspect a plan without executing the statement, even when the planned statement would write data.

The main cross-surface rules are:

  • Warm mode applies only to reads.
  • Durable acknowledgment applies only to writes and requires a writer flush before success. An absent durable flag keeps the normal wait; only an explicit false trades crash durability for latency.
  • Writer-required requests fail when the server runs with a read-only database handle.
  • Query bodies are bounded before execution.
  • Transaction conflicts and invalid client input are reported as client-visible failures. Other database failures remain server failures, with retry guidance where the failure class supports it.

This shared model is checked across native queries, Cypher, and SQL over HTTP and gRPC. The purpose is to keep a change in one transport from changing query results or the meaning of errors in another.

References: crates/…/http.rs• L86-269 crates/…/http.rs• L337-395 crates/…/grpc.rs• L59-220 crates/…/grpc.rs• L236-331 crates/…/transport_contracts.rs• L718-961 crates/…/cypher_tests.rs• L759-937

Benchmark role

The optional async-index benchmark entry point runs the normal transports as either a writer or a reader and emits cumulative JSON samples. It exists to compare index queue, publication, merge, connector, and storage behavior without changing the product server's default queue layout or query metrics ownership.

Readers require shared disk or object storage because an in-memory database cannot share the writer's state. Each sample is cumulative, so a measurement window is the difference between two samples. This mode is operational tooling for performance work rather than a separate query contract. crates/…/Cargo.toml• L6-8, crates/…/benchmark.rs• L1-31, crates/…/benchmark.rs• L96-177

For wire-level request, response, and error rules, read HTTP and gRPC server contracts. For bootstrap inputs, cache ownership, shared state, diagnostics, and shutdown concerns, read Server configuration and state.

Change checklist

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

  • Keep HTTP and gRPC health fields aligned when readiness, database mode, or blocked index reporting changes.
  • Keep native, Cypher, and SQL query option rules aligned across HTTP headers and gRPC request fields.
  • Keep explain requests read-only in both transports, including durable-write validation.
  • Keep SQL routes and RPCs aligned with their Cypher execution and explain paths.
  • Preserve the shared query-service boundary so transport changes do not create different query semantics.
  • Recheck shutdown ordering when changing listener startup, transport supervision, metrics shutdown, database close behavior, or cache lock release.
  • Keep diagnostic check IDs, categories, status meanings, and helix doctor expectations aligned when setup checks change.
  • Keep storage selection, cache ownership, cache warm behavior, open-file limits, index queue policy, WAL flush policy, and database startup requirements aligned when environment settings change.
  • Update the protobuf contract and its generated boundary together when changing gRPC fields.
  • Keep the shared transport corpus and failure-class mappings aligned when a response shape or error classification changes.

Important failure modes

TriggerConsequenceGuard
Invalid listener addressStartup fails before the server can accept traffic.Parse listener addresses during configuration loading.
Both local data storage and S3 storage are configuredServer configuration is rejected as ambiguous.Select one storage source before opening the database.
A cache setting is used with memory storage, or without its required cache directoryConfiguration fails before storage opens.Validate cache settings against the selected storage source.
The default cache budget does not fit its filesystemStartup fails instead of allowing the cache to fill the filesystem.Set an explicit fitting budget or mount a larger cache volume.
Another server holds the hybrid cache lockThe second server cannot open the configured storage.Give each running server a separate cache directory.
Cache open-file needs exceed the hard process limitStartup fails before cache use can produce EMFILE errors.Raise the hard limit or reduce the cache requirement.
HTTP or gRPC listener stops unexpectedlyThe peer transport is stopped and the database is closed.Supervise both tasks and join both before close.
Write sent to a read-only handleThe request fails instead of changing storage.Enforce database mode and return the transport-specific unavailable status.
Query body exceeds the limitThe request is rejected before query execution.Apply the shared body limit at each public surface.
Explain request asks for durable write acknowledgmentThe request is rejected because explain does not execute or commit a write.Apply read-only option validation to explain requests.
Service failure has an unknown commit outcomeThe client cannot know whether the write took effect.Return an explicit non-retryable outcome over HTTP and an unavailable gRPC status.
Diagnostics cannot inspect a filesystem, metadata service, or S3 pathThe affected check is skipped or reported with a warning; query service remains available.Bound probes and expose the reason in the diagnostic result.
HTTP and gRPC classify the same service error differentlyClients receive different retry and recovery behavior for the same database result.Use the shared failure class and verify both transport mappings.

Key files

FileWhy to read it
crates/…/lib.rsShows process startup, database ownership, cache preparation, transport supervision, metrics setup, and shutdown order.
crates/…/config.rsShows how listener addresses, storage sources, cache policy, index queue limits, WAL flush timing, and SST compression reach database startup.
crates/…/state.rsDefines the state shared by both transport surfaces and the diagnostic view.
crates/…/http.rsShows the HTTP query, Cypher, SQL, explain, health, and diagnostics capabilities.
crates/…/grpc.rsShows the gRPC service boundary and status mapping.
crates/…/cypher_tests.rsShows cross-surface Cypher and SQL behavior for shared state, explain plans, errors, telemetry, and durable writes.
crates/…/transport_contracts.rsShows that embedded, service, HTTP, and gRPC paths follow the same query, result, and error behavior.
crates/…/tests.rsVerifies transport supervision, shutdown order, readiness, body limits, writer routing, and cross-surface failure behavior.
crates/…/mod.rsDefines the read-only operational report and its stable check contract.
crates/…/helixdb.protoDefines the public gRPC methods and message fields.
crates/…/query_service.rsDefines the common query boundary used by transports.
crates/…/benchmark.rsShows the optional writer and reader benchmark lifecycle and sample contract.