gRPC Protocol Reference

High-throughput typed RPCs, cancellation, catalog reflection, and native OTLP gRPC ingestion over HTTP/2.

4 min read Protocols & HTTP API

SpydDB exposes a typed, schema-aware HTTP/2 gRPC service (spyddb.v1.Spyddb) alongside OpenTelemetry OTLP gRPC ingestion (opentelemetry.proto.collector.{trace,metrics,logs}.v1) on a single multiplexed TLS/HTTP/2 listener.

Unlike untyped JSON endpoints, gRPC preserves exact 25-variant datum fidelity (u64 vs i64, fixed-scale decimal, nanosecond/microsecond timestamp, uuid, raw bytes, vector, geo_point, geo_polygon, array, and nested composite records) end to end.


1. Enabling & Securing the gRPC Listener#

Configure grpc_bind and optional payload/row bounds in server.json:

json
{
  "grpc_bind": "0.0.0.0:9090",
  "grpc_max_request_bytes": 16777216,
  "grpc_max_response_bytes": 67108864,
  "grpc_max_rows": 100000,
  "grpc_request_timeout_millis": 30000,
  "tls": {
    "certificate": "/etc/spyd/tls/tls.crt",
    "private_key": "/etc/spyd/tls/tls.key"
  }
}

Transport & Security Behavior#

  • Loopback vs. network bind: Binding grpc_bind off loopback (for example 0.0.0.0:9090) requires TLS (tls configured). The server negotiates ALPN h2 at startup and refuses plaintext non-loopback configuration before opening sockets.
  • Authentication metadata: Every RPC except Health requires authorization: Bearer <token> in gRPC metadata. Tokens resolve to the same Session, RBAC roles, row policies, tenant isolation, and per-peer auth failure rate limiter as SpydWire and HTTP.
  • Admission & quotas: Queries execute under configured tenant/workload active-query budgets and share cooperative server cancellation tokens (Cancel RPC and client deadline disconnect both terminate running query workers cleanly).
  • Keepalives & multiplexing: Each HTTP/2 connection supports up to 256 concurrent streams with 30s HTTP/2/TCP keepalive probes (10s timeout) and graceful DRAIN_GRACE (30s) during server shutdown.

2. Service Definition (spyddb.v1.Spyddb)#

RPC MethodRequestResponseAuth RequiredBehavior
ExecuteExecuteRequestExecuteResponseBearer TokenExecutes SpydQL or SQL (sql), positional parameters, optional query_id, and returns full columns, rows, affected, and execution status.
QueryQueryRequestQueryResponseBearer TokenReturns query rows bounded by grpc_max_rows.
CatalogCatalogRequestCatalogResponseBearer TokenReturns the serialized catalog document (collections, fields, indexes, constraints, roles) scoped by caller visibility.
CancelCancelRequestCancelResponseBearer TokenCancels an in-flight query_id belonging to the caller's tenant/user.
HealthHealthRequestHealthResponseNoneUnauthenticated liveness and readiness probe for Kubernetes and load balancers.
SubscribeEventsSubscribeRequeststream ChangeEventBearer TokenServer-streaming durable realtime change events backed by the commit journal with resumable cursors and RBAC/tenant/record-grant enforcement.

Tip: The same HTTP/2 gRPC listener also mounts standard OpenTelemetry TraceService, MetricsService, and LogsService collectors on port grpc_bind, allowing OpenTelemetry SDKs and Collectors to export over gRPC directly alongside HTTP OTLP.


3. Typed Value Wire Model#

Each field cell uses spyddb.v1.Value carrying a strongly typed protobuf oneof kind variant so clients never suffer IEEE-754 integer precision loss on 64-bit IDs or decimal rounding drift:

CategoryWire Variant ExamplesFidelity Guarantee
Null & Booleansnull_value, bool_valueExplicit SQL NULL distinct from empty strings or zero
Exact Signed/Unsigned Integersi8/i16/i32/i64, u8/u16/u32/u64Full 64-bit integer range (safe for snowflake IDs & counters)
Floating Point & Decimalf32, f64, decimal_value { mantissa, scale }Exact fixed-point financial precision up to 38 digits
Text, Binary & Temporalstring_value, bytes_value, date, timestamp, uuidMicrosecond UTC instants and raw binary payloads
Structured & Semi-Structuredjson_value, array_value, composite_value (name, CompositeField[])Preserves nested record schemas & typed element arrays
Spatial & AI Vectorsvector_value (repeated float), geo_point, geo_polygonDirect binary floats for HNSW/similarity queries without text parsing

Maximum statement length matches HTTP/SpydWire (1 MiB, 1,048,576 bytes). Client-supplied query_id values must be unique among currently active queries on that node (duplicate active IDs return ALREADY_EXISTS).


4. Generating Clients (grpcurl / Protobuf Tooling)#

Use standard protobuf tooling against spyddb/v1/spyddb.proto in Go, Rust (tonic), Java, Python (grpcio), C#, or TypeScript (@grpc/grpc-js):

bash
# Unauthenticated readiness check
grpcurl -cacert tls/ca.crt \
  -import-path ./proto -proto spyddb/v1/spyddb.proto \
  localhost:9090 spyddb.v1.Spyddb/Health

# Authenticated parameterized SpydQL query
grpcurl -cacert tls/ca.crt \
  -H "authorization: Bearer $SPYD_TOKEN" \
  -import-path ./proto -proto spyddb/v1/spyddb.proto \
  -d '{"sql": "orders | where status == $1 | take 10", "parameters": [{"stringValue": "paid"}]}' \
  localhost:9090 spyddb.v1.Spyddb/Execute

# Fetch live catalog snapshot
grpcurl -cacert tls/ca.crt \
  -H "authorization: Bearer $SPYD_TOKEN" \
  -import-path ./proto -proto spyddb/v1/spyddb.proto \
  -d '{}' \
  localhost:9090 spyddb.v1.Spyddb/Catalog

Handling Deadlines & Cooperative Cancellation#

  1. Client gRPC deadlines: When a client cancels its gRPC call or its HTTP/2 stream deadline expires, spyd-server triggers the underlying CancellationToken on the blocking query worker immediately so CPU and memory budgets are released.
  2. Explicit Cancel RPC: Pass a unique non-zero query_id on ExecuteRequest / QueryRequest, and invoke Spyddb/Cancel with { "queryId": <id> } from another task or admin session to abort long-running scans deterministically.