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.

Clients

Your app
Any language, any framework
Postgres tools
Drivers · ORMs · IDEs
Browser
Dashboards · live agents

Protocols

HTTP API
REST + JSON
PG Wire
Postgres compatible
WebRTC
Realtime streams

Gateway

Gateway
Auth · RBAC · routing

Engines

Query Engine
SQL · vectors · docs · graph
Storage & Backups
Durable · point-in-time restore
Payments & Credits
Merchant rail · KYC
Edge Cache
CDN · automatic invalidation

The diagram above is the same interactive view rendered on the landing page. Clients reach the platform through one of three protocol surfaces (HTTP API, PG wire, WebRTC). All requests land on zserver which performs authentication, RBAC, and request routing before dispatching to the engines — query, storage, payments, and the edge cache.

For accessibility, an ASCII diagram of the same flow:

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

At the core of Zatabase is a query engine that provides fast similarity search, exact matching, and SQL compatibility. The engine is a separate 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 the engine
  • 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 query 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 query engine. The platform storage layer (zplatform-storage) provides a key-value API on top of the engine for metadata and configuration:

Application Code
zplatform-storage (KV API)
put_json / get_json / scan_prefix_json / delete
Query Engine
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 ships an on-chain payment rail and merchant verification system as first-class platform primitives. Merchants accept ZATA-denominated payments through a permissioned EVM chain operated by the Zatabase fabric — no external payment processor required for the on-chain settlement path.

The rail supports two settlement modes per merchant, configurable in the merchant dashboard:

  • Instant payout — funds transfer to the merchant wallet on every payment. Best for high-ticket, low-volume merchants.
  • Accumulate + withdraw — funds credit to an in-contract balance the merchant withdraws on demand. Batches transaction friction for small payments and saves per-payment overhead.

Fees follow a dual-mode pattern that the merchant can also override per order:

  • Absorb — the platform fee is taken from the merchant’s posted price.
  • Pass on — the platform fee is added on top of the merchant’s price at checkout. The customer sees the marked-up total.

The platform fee is 2% of every on-chain transaction, accumulated to a treasury balance and swept periodically. Refunds in accumulate mode are atomic balance swaps; refunds in instant mode pull from the merchant’s allowance.

Merchant verification is a separate, opt-in layer built on the identity tier. Verified merchants earn a higher monthly payment cap and a public verification badge in the merchant directory. Verification is performed off chain by the Zatabase identity service and bridged to the chain as a tamper-evident attestation that the payment rail can read. No personal information is written on chain — only the verified-or-not status, the verification level, and the cap tier.

The full verification flow is exposed in both the web console and the mobile shell.

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