clockworklabs / clockworklabs/SpacetimeDB

Async Inter-database Communication (Async IDC)

Open
#5,198 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

I would like to be able to send messages from one database to another via an outbox table.

Sender side (inventory module)

  1. Declare the outbox table. It needs a #[primary_key] #[auto_inc] u64 msg_id, a #[target] typed identity, and payload columns matched by name to the receiver reducer's parameters.
  use game_world as gw;

  #[spacetimedb::table(name = out_receive_item, outbox(gw::receive_item))]
  pub struct OutReceiveItem {
      #[primary_key]
      #[auto_inc]
      msg_id: u64,            // runtime-assigned sequence number

      #[target]
      target: gw::Identity,   // which database to deliver to

      // Payload columns — names must match gw::receive_item's parameters.
      item_id: u64,
      qty: u32,
  }

Defaults are the strong guarantees: ordered = true, reliable = true → ordered, exactly-once delivery per (sender, receiver).

  1. Send by inserting a row. Leave msg_id at 0; the runtime assigns it on commit. If the transaction rolls back, nothing is sent.
  #[spacetimedb::reducer]
  fn transfer_item(ctx: &ReducerContext, to: gw::Identity, item_id: u64, qty: u32) {
      ctx.db.out_receive_item().insert(OutReceiveItem {
          msg_id: 0,
          target: to,
          item_id,
          qty,
      });
  }
  1. (Optional) Observe the outcome. Attach an on_result reactive reducer naming the outbox table. It fires once per terminated delivery, post-commit, on the sender. Ok(()) means the
    receiver returned Ok; Err(s) carries the receiver's error or a terminal transport/schema failure.
  #[spacetimedb::reducer(on_result(out_receive_item))]
  fn on_transfer_result(
      ctx: &ReducerContext,
      row: OutReceiveItem,
      result: Result<(), String>,
  ) {
      if let Err(err) = result {
          log::warn!("transfer of item {} to {:?} failed: {}", row.item_id, row.target, err);
      }
  }

Requested by @cloutiertyler via the SpacetimeDB site.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Rust table and reducer entry points shown in the issue, including outbox and on_result annotations, then identify the transaction and inter-database delivery paths they would require. Done means supporting insertion-based sending with commit and rollback semantics, ordered reliable delivery, receiver results, and post-commit on_result callbacks as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.