Runtime Configuration and Backends
7. Getting Started & Execution Guide
Follow these steps to build, configure, and execute the application with various database engines across different WASI-compliant WebAssembly runtimes.⚙️ Prerequisites
Ensure you have the following installed on your developer machine:- Rust Toolchain: Stable release (Rust 1.93.0+ or similar)
- WASM Target:
rustup target add wasm32-wasip2 - Fermyon Spin CLI (for Spin runtime):
brew install fermyon/tap/spin - Wasmtime CLI (for bare WASM runtime):
brew install wasmtime - cargo-leptos:
cargo install --locked cargo-leptos
🔑 Environment Setup (.env)
Before running the application, configure your databases. We provide a complete template. Copy the example file to initialize your config:
examples/counter-app/.env and inspect the configuration variables. The .env.example template is tracked by version control as a reference, enabling seamless collaboration and automated testing across local and cloud environments:
🔀 Advanced Enterprise Multi-Backend Architecture
Our Leptos application implements a state-of-the-art Multi-Backend Persistence Engine insidesrc/store.rs.
Because our CQRS and Event Sourcing infrastructure depends strictly on framework traits (EventStore, CheckpointStore, Projection), we designed dynamic, runtime-routed wrappers—MultiBackendEventStore<A>, MultiBackendCheckpointStore, and MultiBackendCounterProjection—which inspect the environment at boot-time and execute the correct database operations without modifying a single line of business or component-rendering code.
Supported Database Backends Matrix
Backend Key (db) | Connection Model | Network Protocol | Target Runtime Compatibility | Use Cases | Realtime Support |
|---|---|---|---|---|---|
sqlite | Local Host-Call or JSON files | Spin SQLite host calls; Wasmtime /data mount | Fermyon Spin & Wasmtime | Low-latency local dev, edge microservices, zero-dependency local testing | Yes (SSE polling or Redis wake) |
postgres | Direct Socket Pool | TCP Socket stream | Fermyon Spin & Wasmtime | Classic high-throughput self-hosted PG | Yes (SSE polling or Redis wake) |
neon | Stateless HTTP SQL | JSON over HTTP (WASIp3) | Wasmtime & Fermyon Spin | Serverless cloud databases with cold-start mitigation | Yes (SSE polling or Redis wake) |
supabase | Stateless REST | JSON REST over HTTP (WASIp3) | Wasmtime & Fermyon Spin | Rapid prototyping, managed Supabase database integration | Yes (SSE polling or Redis wake) |
turso | Hrana Protocol | Pipeline HTTP (WASIp3) | Wasmtime & Fermyon Spin | Globally distributed SQL, SQLite-at-the-edge (Turso) | Yes (SSE polling or Redis wake) |
redis | Async Redis commands | RESP TCP under Wasmtime, Spin Redis outbound and optional Redis Trigger under Spin | Wasmtime & Fermyon Spin | Experimental event persistence, checkpoints, and realtime notifications | Yes (via PubSub / SSE) |
mysql | Direct Socket | TCP stream on Wasmtime; Spin SDK MySQL host API on Spin; native driver on non-WASI targets | Wasmtime, Fermyon Spin, and native targets | High-throughput self-hosted or cloud MySQL | Yes (SSE polling or Redis wake) |
⚡ Overcoming WASM Sandbox Limits: Stateless Outbound HTTP
When compiling applications to WebAssembly targets, traditional blocking socket connection pools (such as those used bytokio-postgres or standard native SQLite engines written in C) are strictly incompatible with the isolated, single-threaded sandboxed environment of a WASM component.
To solve this compilation and runtime block, our Multi-Backend Engine employs a stateless, highly optimized Outbound HTTP Bridge powered by the WASIp3 HTTP Component Model standards.
When a database request is sent to Neon, Supabase, or Turso, the store adapter converts the SQL query and its parameterized arguments into a payload format (e.g., the JSON-based Hrana pipeline protocol for Turso/LibSQL or the HTTP SQL Endpoint format for Neon), dispatches it via a single non-blocking HTTP POST, collects the response, and translates the rows back into DDD event envelopes.
Sequence Flow: Outbound HTTP Database Query
Here is a simplified look at how theMultiBackendEventStore leverages WASIp3 Outbound HTTP helpers to communicate with external SQL APIs: