Skip to content

Architecture

Zatabase is a hybrid data and compute platform built in Rust. It combines relational SQL, NoSQL document storage, vector similarity search, and a job orchestrator in a single binary. This page describes the internal architecture and how the major components fit together.

Zatabase Architecture

┌─────────────┐
│ Clients │
└──────┬──────┘
┌────────────┼────────────┐
│ │ │
┌─────▼─────┐ ┌───▼────┐ ┌─────▼─────┐
│ HTTP API │ │PG Wire │ │ WebRTC │
│ (Axum) │ │Protocol│ │ Real-time │
│ Port 8686 │ │Port 5432│ │ │
└─────┬──────┘ └───┬────┘ └─────┬─────┘
│ │ │
└────────────┼────────────┘
┌──────▼──────┐
│ zserver │
│ (Router) │
└──────┬──────┘
┌─────────────────┼─────────────────┐
│ │ │
┌────▼─────┐ ┌─────▼──────┐ ┌──────▼──────┐
│ zauth │ │ ZQL │ │ zpayments │
│ (Auth) │ │ (Engine) │ │ (Credits) │
└────┬─────┘ └─────┬──────┘ └─────────────┘
│ │
┌────▼─────┐ ┌─────▼──────┐
│zpermis- │ │ ZQL │
│ sions │ │ Patent- │
│ (RBAC) │ │ Pending │
└──────────┘ └─────┬──────┘
┌─────▼──────┐
│ Storage │
└────────────┘

At the core of Zatabase is ZQL (Z Query Language), a patent-pending database engine that provides fast similarity search, exact matching, and SQL compatibility. ZQL is a separate, private codebase that Zatabase embeds as a library.

  • O(1) exact match: The = operator provides instant exact matching
  • Prefix scans: The STARTS_WITH operator efficiently finds records by text prefix
  • Similarity search: The ~ operator with a threshold parameter finds semantically related records
  • SQL compatibility: Standard SQL is auto-detected and executed through ZQL
  • Dense f32 vectors: Standard floating-point vectors (any dimension) for ML embeddings, with L2, cosine, and inner product distance metrics

Zatabase is organized as a Rust workspace with feature-gated crates:

CratePurpose
zplatform-storageKV API backed by the ZQL engine
zcore-catalogTable and column metadata management
zauthJWT authentication, OAuth, session management
zpermissionsRole-based access control (RBAC)
zpaymentsZATA ledger, escrow, and billing primitives
zserverAxum HTTP server, routes, streaming ingest
zpg-protocolPostgreSQL wire protocol implementation
zobservabilityMetrics, health checks, tracing
zcommonShared types and utilities
CrateFeature FlagPurpose
zeventseventsEvent system with webhooks and triggers
zorganizationsorganizationsMulti-tenant organization management
zteamsorganizationsTeam collaboration and membership
zfunctionsfunctionsServerless function execution
zdomainsdomainsCustom domain management
zprojectsprojectsProject lifecycle management
znotificationsnotificationsAlert and notification delivery
zsdk-generatorsdk-generatorClient SDK code generation
zmesh-networkmeshPeer-to-peer mesh networking
zconsensusconsensusRaft consensus for replication
ztransactiontransactionsDistributed transactions and sagas
zcloud-deploycloudCloud deployment automation
zcloud-hetznercloudHetzner Cloud provider integration
zcloud-cloudflarecloudCloudflare integration
zidentityidentityVerifiable credentials and DID

All data in Zatabase flows through the ZQL engine. The platform storage layer (zplatform-storage) provides a key-value API on top of ZQL for metadata and configuration:

Application Code
zplatform-storage (KV API)
put_json / get_json / scan_prefix_json / delete
ZQL Engine (patent-pending)
query / insert / exact_lookup / prefix_scan / execute_sql
Disk (data_dir/<org_id>/<store_name>/)

Each organization gets isolated storage directories. Within an organization, data is partitioned by store (table) name.

Zatabase uses a layered authentication system:

  1. JWT tokens: Short-lived access tokens (15 min default) + long-lived refresh tokens (7 days)
  2. SCRAM-SHA-256: For PostgreSQL wire protocol connections
  3. Dev tokens: HMAC-signed tokens for development (blocked in production)
  4. OAuth: Delegated authentication via Google, GitHub, Discord, Apple

Permissions are enforced at API boundaries using org-scoped role-based access control:

  • Principals: Users, Roles, Groups, Labels
  • Resources: Collections, Tables, Indexes, Jobs, Files, Permissions
  • Actions: Create, Read, Update, Delete
  • Built-in roles: admin (full access), operator (read/write data), reader (read-only)

Permission checks are applied by every handler before executing operations:

fn ensure_permission(
org_id: u64,
principals: &[Principal],
resource: ResourceKind,
action: Crud,
) -> Result<(), PermissionError>
  • Every request is scoped to an organization via the JWT token
  • Storage is physically isolated per org (separate directories)
  • Permissions are evaluated per-org
  • Environment isolation (live/sandbox) provides logical separation within an org

Zatabase supports WebSocket connections for real-time event streaming:

  • Topic-based pub/sub (subscribe to job updates, data changes)
  • Bounded message queues with backpressure (256 message capacity)
  • Concurrent connection handling with graceful cleanup

For low-latency data channel communication:

  • Room-based signaling with ICE trickle support
  • Query execution over data channels (SQL and QueryBuilder)
  • Real-time metrics, logs, and event forwarding
  • Database trigger notifications

When the consensus feature is enabled, Zatabase uses Raft consensus to replicate write operations across cluster nodes:

  • Write operations are proposed to the Raft leader
  • The leader replicates to a majority before committing
  • Read operations go directly to the local engine
  • A CompositeStateMachine routes operations to the appropriate subsystem

Zatabase includes a built-in job orchestrator (zbrain + zworker) for compute tasks:

  • Submit job specifications via REST API
  • Jobs execute as native processes (local mode) or containers (Docker mode)
  • Real-time log streaming via WebSocket
  • Artifact management with content-addressed filesystem storage
  • Cancellation support with configurable timeouts

Zatabase uses feature flags to control which subsystems are compiled:

Terminal window
# Core only (minimal binary)
cargo build -p zserver --no-default-features --features core
# V1 build (production release)
cargo build -p zserver --features v1
# Full build (all features including post-V1)
cargo build -p zserver --features full

v1 (production release): core, websocket, webrtc, events, organizations, consensus, tls, security-hardening, cypher, pg-tunnel, mesh, cloud, functions, projects.

full (all features): Everything in v1 plus identity, transactions, domains, notifications, sdk-generator, integrations.

FlagDescription
coreDatabase essentials (always included)
websocketWebSocket real-time event streaming
webrtcWebRTC data channels for low-latency queries
eventsEvent system with webhooks and triggers
organizationsMulti-tenant org and team management
consensusRaft consensus for replication
tlsTLS termination for HTTP API
security-hardeningArgon2id key management, X.509 cert gen, compliance
cypherCypher graph query language support
pg-tunnelPostgreSQL wire protocol with TLS tunnel
meshPeer-to-peer mesh networking
cloudCloud deployment (Hetzner, Cloudflare)
functionsServerless function execution
projectsProject lifecycle management
identityVerifiable credentials and DID (post-V1)
transactionsDistributed transactions and sagas (post-V1)
domainsCustom domain management (post-V1)
notificationsAlert and notification delivery (post-V1)
sdk-generatorClient SDK code generation (post-V1)
integrationsCross-service routing (post-V1)
s3-storageS3-compatible file storage backend