github clockworklabs/SpacetimeDB v2.4.0
Release v2.4.0

7 hours ago

2.4.0 brings a headline new capability for Rust modules HTTP handlers alongside meaningful improvements to runtime performance, durability correctness, and server-side observability. The changelog is focused but every entry is production-relevant.

Features

HTTP handlers in Rust modules

This is currently an unstable feature and will need to be enabled to have be available.

  • Rust users can enable unstable features in their Cargo.toml:
[dependencies]
spacetimedb = { version = "1.*", features = ["unstable"] }
  • C# users can enable unstable features by adding #pragma warning disable STDB_UNSTABLE at the top of your file.
  • C++ users can enable unstable features by adding #define SPACETIMEDB_UNSTABLE_FEATURES before including the SpacetimeDB header.

Rust modules can now define custom HTTP routes and serve arbitrary HTTP requests directly from module code (#4636). Annotate a function with #[spacetimedb::http::handler] to create a handler, then wire it into your module's routing table with #[spacetimedb::http::router].

#[spacetimedb::http::handler]
fn insert(ctx: &mut HandlerContext, request: Request) -> Response {
    let body: Vec<u8> = request.into_body().into_bytes().into();
    let id = ctx.with_tx(|tx| tx.db.data().insert(Data { id: 0, body }).id);
    Response::new(Body::from_bytes(format!("{id}")))
}

#[spacetimedb::http::router]
fn router() -> Router {
    Router::new().post("/insert", insert).get("/retrieve", retrieve)
}

All user-defined routes are exposed under /v1/database/:name_or_identity/route/{*path}. Handlers have access to a HandlerContext that can open a database transaction, giving you full read/write access to your tables.

This opens the door to webhook integrations, REST-style APIs for non-realtime clients, and any other HTTP-driven interaction you want to build on top of your SpacetimeDB module.

Faster WASM reducer execution

Reducers now run on a dedicated synchronous WASM runtime backed by a single OS thread, instead of sharing the async runtime that procedures use (#5095). Because reducers never yield, the old async scaffolding was pure overhead. The synchronous path removes that cost from the hot path for every reducer invocation.

Bug Fixes

  • Durability: silent data loss on resume fixed. The commitlog could silently corrupt a segment on restart if trailing bytes shorter than a commit header were left behind. A subsequent append would render the segment corrupt, and anything written after those trailing bytes would become unreachable after the next restart. The segment is now truncated to its validated size before writes resume (#5116).
  • V8 heap metrics now cover procedure workers. Previously V8HeapMetrics were tracked only for reducer workers, leaving memory usage by JavaScript procedure workers invisible. Procedure worker heap usage is now aggregated and reported alongside the reducer worker metrics (#5122).
  • Commitlog decode errors include context. Errors encountered while decoding commits now carry additional context, making it substantially easier to diagnose corrupted or truncated log segments in production (#5129).
  • Reverted energy/execution-time conversion in V8 host. A regression introduced in v2.3.0 in how execution time was converted to energy units for JavaScript modules was reverted (#4927).

Don't miss a new SpacetimeDB release

NewReleases is sending notifications on new releases.