In-memory vs remote cookbook

When to use this

You want the same Graft code to run locally in-process during development and against a remote Gateway in production — or switch after Quick Start tutorial #6.

Core idea: execution location is not a programming concern. The same Graft, methods, types, and error handling apply whether Hypertube runs in-memory, across local runtimes in one process, or on a remote node — only GraftConfig changes.

ModeWhen to use
In-memoryDev, modular monoliths, zero network overhead
Local polyglotMultiple runtimes (.NET + Python) in one process
RemoteProduction microservices, separate GG hosts

In-memory, polyglot in-memory, and remote execution modes

Prerequisites


In-memory (default)

Do not set host. Hypertube executes calls in the same process.

import { OrderService } from "@graft/nuget-Orders";
// GraftConfig.host unset → in-memory
const orders = new OrderService();
await orders.createOrder({ id: "1" });

Ensure the receiver runtime/module is loaded in the same process (typically same GG or embedded Hypertube host).


Remote via code

import { GraftConfig, OrderService } from "@graft/nuget-Orders";

GraftConfig.host = "tcp://order-service:8990";
const orders = new OrderService();
await orders.createOrder({ id: "1" });
GraftConfig.host = "ws://order-service:8888/ws";
var orders = new OrderService();
orders.CreateOrder(new { Id = "1" });

Remote via config file (no code change)

graftcode-config.json next to your app:

{
  "host": "tcp://order-service:8990"
}

Or per-Graft file @graft-nuget-Orders-config.json:

{
  "host": "tcp://order-service:8990"
}

Remote via environment variable

Set a global or runtime-specific env var (exact name depends on generated Graft; check generated GraftConfig or use graftcode-config pattern). Config files and env vars override code.


Dev vs prod pattern

EnvironmentConfiguration
Local devNo host — in-memory
Staginggraftcode-config.json with staging GG URL
ProductionEnv var or secrets-mounted config with prod GG URL

Same binary artifact in all environments.


Verify it works

  1. In-memory: stop remote GG — calls still work if module is local
  2. Remote: stop GG — calls fail with connection error; restart GG — calls succeed

Use GG_DEBUG=1 on Gateway for wire-level traces — Debugging runbook.


Common mistakes

MistakeFix
host set but wrong portMatch GG --tcpPort / --port; see Transport guide
Expecting remote without GG runningStart GG on target host
Config file ignoredCheck precedence — env may override file

See also

Practiced in Quick Start tutorial #6