gRPC Protocol Reference
High-throughput typed RPCs, cancellation, catalog reflection, and native OTLP gRPC ingestion over HTTP/2.
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:
{
"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_bindoff loopback (for example0.0.0.0:9090) requires TLS (tlsconfigured). The server negotiates ALPNh2at startup and refuses plaintext non-loopback configuration before opening sockets. - Authentication metadata: Every RPC except
Healthrequiresauthorization: Bearer <token>in gRPC metadata. Tokens resolve to the sameSession, 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 (
CancelRPC 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 (
10stimeout) and gracefulDRAIN_GRACE(30s) during server shutdown.
2. Service Definition (spyddb.v1.Spyddb)#
| RPC Method | Request | Response | Auth Required | Behavior |
|---|---|---|---|---|
Execute | ExecuteRequest | ExecuteResponse | Bearer Token | Executes SpydQL or SQL (sql), positional parameters, optional query_id, and returns full columns, rows, affected, and execution status. |
Query | QueryRequest | QueryResponse | Bearer Token | Returns query rows bounded by grpc_max_rows. |
Catalog | CatalogRequest | CatalogResponse | Bearer Token | Returns the serialized catalog document (collections, fields, indexes, constraints, roles) scoped by caller visibility. |
Cancel | CancelRequest | CancelResponse | Bearer Token | Cancels an in-flight query_id belonging to the caller's tenant/user. |
Health | HealthRequest | HealthResponse | None | Unauthenticated liveness and readiness probe for Kubernetes and load balancers. |
SubscribeEvents | SubscribeRequest | stream ChangeEvent | Bearer Token | Server-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, andLogsServicecollectors on portgrpc_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:
| Category | Wire Variant Examples | Fidelity Guarantee |
|---|---|---|
| Null & Booleans | null_value, bool_value | Explicit SQL NULL distinct from empty strings or zero |
| Exact Signed/Unsigned Integers | i8/i16/i32/i64, u8/u16/u32/u64 | Full 64-bit integer range (safe for snowflake IDs & counters) |
| Floating Point & Decimal | f32, f64, decimal_value { mantissa, scale } | Exact fixed-point financial precision up to 38 digits |
| Text, Binary & Temporal | string_value, bytes_value, date, timestamp, uuid | Microsecond UTC instants and raw binary payloads |
| Structured & Semi-Structured | json_value, array_value, composite_value (name, CompositeField[]) | Preserves nested record schemas & typed element arrays |
| Spatial & AI Vectors | vector_value (repeated float), geo_point, geo_polygon | Direct 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):
# 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/CatalogHandling Deadlines & Cooperative Cancellation#
- Client gRPC deadlines: When a client cancels its gRPC call or its HTTP/2 stream deadline expires,
spyd-servertriggers the underlyingCancellationTokenon the blocking query worker immediately so CPU and memory budgets are released. - Explicit
CancelRPC: Pass a unique non-zeroquery_idonExecuteRequest/QueryRequest, and invokeSpyddb/Cancelwith{ "queryId": <id> }from another task or admin session to abort long-running scans deterministically.