Now in public alpha

Your database
should think

Cosmictron embeds your business logic directly inside the database. Write Rust or TypeScript, get real-time subscriptions, transactions, and a WebSocket API. Replace your entire backend stack with a single binary.

$ cargo install cosmictron

Your backend
is too complex

The traditional stack forces you to maintain an app server, a database, a pub/sub system, and an ORM layer. Network hops between tiers destroy latency. Cosmictron collapses all of it into one.

Traditional Stack
Client SDK
↓ HTTP / REST
App Server (Express, Rails...)
↓ ORM / SQL
Database (Postgres, MySQL...)
↓ triggers / polling
Pub/Sub (Redis, Kafka...)
↓ websocket
Real-time Server (Socket.io...)
Cosmictron
Client SDK
↓ WebSocket (binary)
Cosmictron
Database + Compute + Real-time

Everything you need.
Nothing you don't.

Embedded Logic

Write business logic in Rust or TypeScript that runs inside the database via WASM/V8 sandboxing. Zero network hops between compute and data.

Real-Time Subscriptions

Subscribe to any SQL query. DBSP-based incremental view maintenance pushes only the deltas that changed. Microsecond-level latency.

🔒

MVCC Transactions

Optimistic concurrency control with serializable isolation. Every reducer call is an atomic transaction. Commits or rolls back cleanly.

🌐

WebSocket Protocol

Binary BSATN wire format over WebSocket. Connect from any language. TypeScript SDK included with auto-reconnection and local caching.

🛡

Row-Level Security

Declarative SQL WHERE-clause injection for per-identity access control. No manual permission checks needed in your reducers.

🔄

Hot-Reload Modules

Update business logic without downtime. In-flight requests drain, then the new module swaps in atomically. Zero-downtime deployments.

Derive Macros

Automatic BSATN serialization with #[derive(BsatnSerialize, BsatnDeserialize)]. Eliminates 200+ lines of boilerplate per module.

🔍

Typed Query API

Type-safe database queries with find_by_pk, find_all, exists. No more manual table scanning and byte parsing.

💡

Lifecycle Reducers

Hook into module lifecycle with #[reducer(init)], #[reducer(client_connected)]. Perfect for presence tracking and initialization.

Zero Boilerplate.
Maximum Velocity.

Derive macros eliminate serialization boilerplate. The Query API provides type-safe database operations. Focus on your logic, not the plumbing.

chat/src/lib.rs Rust
use cosmictron_sdk::*;

#[derive(BsatnSerialize, BsatnDeserialize)]
#[table(name = "messages")]
pub struct Message {
    #[primary_key] #[auto_inc]
    pub id: u64,
    #[index]
    pub channel_id: u64,
    pub content: String,
}

#[reducer]
pub fn send_message(
    channel_id: u64,
    content: String,
) {
    let msg = Message {
        id: 0,  // auto-assigned
        channel_id,
        content,
    };
    datastore::insert(&msg);
}

#[reducer(client_connected)]
pub fn on_connect() {
    info(&format!("User {} connected", 
        identity_abbr(&caller_identity())));
}
app.ts TypeScript
import { CosmictronClient } from '@cosmictron/client';

const client = new CosmictronClient(
  'ws://localhost:8080'
);

// Connect and authenticate
await client.connect();

// Subscribe to messages in real-time
await client.subscribe(
  'SELECT * FROM messages WHERE channel_id = 1',
  (update) => {
    update.inserts.forEach(msg =>
      console.log(`New: ${msg.content}`)
    );
  }
);

// Send a message
await client.callReducer(
  'chat',
  'send_message',
  { channel_id: 1, content: 'Hello!' }
);
0
Lines Saved per Module
0
Less Boilerplate
0
Manual Serialization
0
New SDK Features

From code to real-time
in four steps

01

Define Tables

Use the #[table] macro to declare your schema with types, indexes, and constraints in Rust structs.

02

Write Reducers

Business logic as plain functions. Each call is an atomic transaction with full access to the datastore.

03

Deploy

Compile to WASM and deploy with the CLI. Hot-reload is supported with zero downtime.

04

Subscribe

Clients subscribe to SQL queries over WebSocket. Deltas stream in real-time as data changes.

Ready to launch?

Cosmictron is open source, MIT/Apache-2.0 licensed, and free forever.