Runnable path · Node.js caller → Python handler

Keep one target across two languages

A Node.js checkout asks billing.quote. A Python process owns that handler and returns the result through CoAkka Runtime. The two packages share the same Core generation and wire contract; neither application imports the other's language.

Beginner · 01

Polyglot means one product contract, not one language API

Node.js checkout
  ask target=billing.quote payload="3"
             ↓ direct CoAkka Runtime peer
Python billing
  handler target=billing.quote → "$36.00"
Application
Owns target meaning, payload format, handler logic and what to do with the result.
Connector
Projects lifecycle and values idiomatically into Node.js or Python.
Core
Owns accepted configuration, transport, routing, correlation, bounds and terminal outcome.
Infrastructure
This first run uses direct localhost peers. The same model works with reachable DNS/IP on LAN, VM, edge or Kubernetes.

Beginner · 02

Install each connector from its official channel

Python service

Terminal 1
mkdir python-service
cd python-service
python -m venv .venv
. .venv/bin/activate
python -m pip install --only-binary=:all: coakka-runtime-python==3.3.2

Node.js caller

Terminal 2
mkdir node-caller
cd node-caller
npm init -y
npm install [email protected]

Copy the two source files below into those folders. Do not copy a native library between them; each official connector owns its exact package layout and Core pin.

Beginner · 03

Start the Python billing handler first

python-service/polyglot_service.py
import signal
import threading

from coakka_v2_connector import (
    ConnectorStartSpec,
    RuntimeHost,
    RuntimeNetworkConfig,
    local_route,
)


target = "billing.quote"
stop_requested = threading.Event()


def quote(payload: bytes) -> bytes:
    quantity = int(payload.decode("utf-8"))
    unit_price_dollars = 12
    return f"${quantity * unit_price_dollars}.00".encode("utf-8")


def request_stop(_signum: int, _frame: object) -> None:
    stop_requested.set()


start_spec = ConnectorStartSpec(
    system_name="polyglot-billing",
    node_id="python-billing-1",
    routes=[local_route(target)],
    network=RuntimeNetworkConfig.network_node(
        bind_host="127.0.0.1",
        bind_port=19_326,
        advertise_host="127.0.0.1",
        advertise_port=19_326,
    ),
)

signal.signal(signal.SIGINT, request_stop)
signal.signal(signal.SIGTERM, request_stop)

with RuntimeHost.start(start_spec=start_spec) as runtime:
    runtime.register_payload_handler(target, quote)
    print("Python billing ready on 127.0.0.1:19326", flush=True)
    stop_requested.wait()
Terminal 1
python polyglot_service.py

Ready output

Python billing ready on 127.0.0.1:19326
network_node
Opens a listener. Here bind and advertise are localhost because both processes run on one machine.
local_route(target)
The handler lives in this Python process.
register_payload_handler
Accepts bytes and returns bytes. JSON, Protobuf or another schema is application-owned.

Beginner · 04

Run the Node.js checkout

node-caller/polyglot-caller.mjs
import { Buffer } from "node:buffer";

import {
  RouteStrategy,
  RuntimeHost,
  outboundOnlyNetwork,
} from "coakka-runtime-node";

const target = "billing.quote";
const runtime = RuntimeHost.start({
  systemName: "polyglot-checkout",
  nodeId: "node-checkout-1",
  network: outboundOnlyNetwork(),
  routes: [
    {
      target,
      strategy: RouteStrategy.SINGLE_OWNER,
      endpoints: [{ host: "127.0.0.1", port: 19326, weight: 1, flags: 0 }],
    },
  ],
});

try {
  const reply = await runtime.askPayload(
    "checkout",
    target,
    Buffer.from("3"),
    2000,
  );
  console.log("Python replied:", Buffer.from(reply).toString("utf8"));
} finally {
  await runtime.close();
}
Terminal 2
node polyglot-caller.mjs
outboundOnlyNetwork()
The caller needs no listener.
SINGLE_OWNER
Exactly one billing endpoint owns this route in the first run.
askPayload
Node.js awaits a correlated reply with a bounded 2000 ms caller budget.
finally
The Node.js app owns the RuntimeHost and closes it even when the call fails.

Beginner · 05

The reply crosses the language boundary, not the product boundary

Python quotes 3 items at the sample price of $12.00 each.

Node.js output

Python replied: $36.00