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
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.
Write business logic in Rust or TypeScript that runs inside the database via WASM/V8 sandboxing. Zero network hops between compute and data.
Subscribe to any SQL query. DBSP-based incremental view maintenance pushes only the deltas that changed. Microsecond-level latency.
Optimistic concurrency control with serializable isolation. Every reducer call is an atomic transaction. Commits or rolls back cleanly.
Binary BSATN wire format over WebSocket. Connect from any language. TypeScript SDK included with auto-reconnection and local caching.
Declarative SQL WHERE-clause injection for per-identity access control. No manual permission checks needed in your reducers.
Update business logic without downtime. In-flight requests drain, then the new module swaps in atomically. Zero-downtime deployments.
Automatic BSATN serialization with #[derive(BsatnSerialize, BsatnDeserialize)]. Eliminates 200+ lines of boilerplate per module.
Type-safe database queries with find_by_pk, find_all, exists. No more manual table scanning and byte parsing.
Hook into module lifecycle with #[reducer(init)], #[reducer(client_connected)]. Perfect for presence tracking and initialization.
Derive macros eliminate serialization boilerplate. The Query API provides type-safe database operations. Focus on your logic, not the plumbing.
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()))); }
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!' } );
Use the #[table] macro to declare your schema with types, indexes, and constraints in Rust structs.
Business logic as plain functions. Each call is an atomic transaction with full access to the datastore.
→Compile to WASM and deploy with the CLI. Hot-reload is supported with zero downtime.
→Clients subscribe to SQL queries over WebSocket. Deltas stream in real-time as data changes.
Cosmictron is open source, MIT/Apache-2.0 licensed, and free forever.