Scry Protocol
Event protocol for Scry SQL proxy - FlexBuffers serialization for query events.
Overview
This crate provides the event types and serialization/deserialization for query events captured by the Scry proxy. It's designed to be used both by the proxy itself and by downstream analytics services that consume events.
Features
- Event Types:
QueryEventandQueryEventBuilderfor constructing events - FlexBuffers Serialization: Efficient, schema-less binary serialization
- FlexBuffers Deserialization: Deserialize event batches from binary format
- Batch Support: Serialize and deserialize multiple events in a single batch
- Schema Documentation: Canonical FlatBuffers schema in
schema/query_event.fbs
Wire Format
Events are serialized using FlexBuffers, a schema-less binary format from the FlatBuffers project. This provides:
- Compact binary representation: Smaller than JSON, efficient over the network
- Backward/forward compatibility: Schema evolution without breaking consumers
- Zero-copy capabilities: Efficient deserialization when needed
- Works seamlessly with serde: No code generation required
Event Schema
See schema/query_event.fbs for the canonical schema definition.
QueryEvent
Represents a captured SQL query event from the proxy:
event_id: Unique identifier (UUID v4)timestamp: When the query was received (SystemTime)query: The SQL query text (raw or anonymized)normalized_query: Normalized query with placeholders (optional, if anonymization enabled)value_fingerprints: Fingerprints of literal values (optional, for hot data detection)duration: Query execution durationrows: Number of rows affected/returned (optional)success: Whether the query succeedederror: Error message if query failed (optional)database: Database nameconnection_id: Client connection identifier
QueryEventBatch
A batch of query events sent together:
events: Array of QueryEventproxy_id: Unique proxy instance identifierbatch_seq: Batch sequence number (for ordering/deduplication)
Usage
Creating Events
use ;
let event = new
.connection_id
.database
.duration
.rows
.build;
Serializing Batches
use FlatBuffersSerializer;
let events = vec!;
let bytes = serialize_batch;
// Send bytes over the network...
Deserializing Batches
use FlexBuffersDeserializer;
// Receive bytes from the network...
let batch = deserialize_batch?;
println!;
println!;
for event in batch.events
Examples
See the examples/ directory for complete examples:
serialize.rs- Creating and serializing eventsdeserialize.rs- Deserializing and reading events
Run examples with:
Version Compatibility
This crate follows semantic versioning:
- Major version: Breaking changes to the event schema or API
- Minor version: New fields added (backward compatible)
- Patch version: Bug fixes, internal improvements
FlexBuffers provides forward/backward compatibility:
- Forward compatible: Old readers can read new data (unknown fields ignored)
- Backward compatible: New readers can read old data (missing fields use defaults)
Performance
- Serialization: ~1-2 microseconds per event
- Deserialization: ~2-3 microseconds per event
- Batch overhead: Minimal, amortized across events
- Binary size: ~200-400 bytes per event (varies with query length)
Testing
Run tests with:
The test suite includes:
- Unit tests for serialization/deserialization
- Roundtrip tests (serialize → deserialize → verify)
- Edge cases (empty batches, large batches, special characters)
- Timestamp precision tests
License
Licensed under MIT OR Apache-2.0