Skip to content

Cross-language interoperability

Cross-language RPC lets a caller and a service use different programming languages while sharing a service interface. You might keep a Python service close to a model or data pipeline and call it from a Node application.

This walkthrough calls the Python greeting service from JavaScript using the TypeScript SDK package. The client reads the producer’s published contract and uses a dynamic proxy, so it needs no local copy of the Python classes. The payload still travels as typed binary XLANG data.

Complete the Python producer in the first-service tutorial, and keep it running. It must expose HelloService.say_hello with the explicit hello/HelloRequest and hello/HelloResponse wire names shown there. Copy its current address.

In a separate Node project, install the TypeScript SDK using the same tutorial’s TypeScript installation instructions. This example uses an .mjs file directly; it requires neither TypeScript compilation nor generated client metadata. A statically typed TypeScript client has a different build workflow, covered in TypeScript build setup.

This pair was executed on Apple Silicon macOS with the public Python package and Node SDK. It tests one string request and response over a real peer connection. It does not qualify other payload shapes, streaming patterns, or language pairs. The producer uses permissive development admission.

Save cross-language.mjs in the Node project:

import { AsterClientWrapper } from '@aster-rpc/aster';
const address = process.env.ASTER_ENDPOINT_ADDR;
if (!address) throw new Error('Set ASTER_ENDPOINT_ADDR to the Python producer address.');
const client = new AsterClientWrapper({ address });
try {
await client.connect();
const hello = await client.proxy('HelloService');
const response = await hello.say_hello({ name: 'JavaScript' });
if (response.message !== 'Hello, JavaScript!') {
throw new Error(`Unexpected response: ${JSON.stringify(response)}`);
}
console.log(response.message);
} finally {
await client.close();
}

Run it with the complete address printed by the Python producer:

Terminal window
ASTER_ENDPOINT_ADDR="<producer address>" node cross-language.mjs

Expected output:

Hello, JavaScript!

The consumer closes its resources in finally, including when a call fails. The Python producer remains running; stop it with Ctrl+C when finished.

The method name stays say_hello: a dynamic client uses the producer’s wire method names, even when they differ from the caller language’s conventions. The TypeScript producer in the first-service tutorial instead defines sayHello, so it is not a substitute for the Python producer in this step.

Piece What both sides need to agree on
Service and method The published name and call pattern, such as HelloService.say_hello with one request and one response.
Wire type name A stable payload identity, such as hello/HelloRequest.
Payload schema Matching field names and compatible wire types; a familiar local type name alone is insufficient.
Serialization mode XLANG for interoperable typed binary calls.
Contract settings The complete interface descriptor used to derive the contract ID.

A wire type name identifies a payload type. A contract ID identifies the service’s canonical interface, including its methods, payload descriptions, and contract settings. Matching type names alone do not establish matching contracts. See contract identity for what changes the ID and what matching IDs establish.

The proxy fetches the published contract and constructs types the local codec can encode. Your call looks like a JavaScript object call, but the proxy does not send arbitrary JSON as the RPC payload. The serialization guide explains that distinction.

For a statically typed client, define equivalent request and response types with explicit wire names, and register or generate metadata as required by that binding. Keep service names, method names, call patterns, and contract settings aligned. Use the language guides for the actual registration workflow.

Take particular care with binary data, integer widths, collections, optional fields, and nested types. A language’s default integer or byte-array mapping may differ from the wire type intended by another language. For example, Go binary payloads need the appropriate fory:"type=bytes" field tag. Give nested application types their own stable wire names.

Use the default XLANG mode for these calls. Python’s NATIVE and ROW codecs have language-specific constraints and are not substitutes for a cross-language payload contract.

Start with one representative request and assert every decoded response field. Then cover the cases your application uses: empty and large collections, boundary numeric values, nested/optional fields, errors, deadlines, and stream completion or cancellation. Test each intended producer/consumer direction.

Compare contract IDs using the supported contract tools, but keep execution checks too: matching interface descriptors do not prove matching application behavior or support for every value. Byte-for-byte equality is not a general requirement for ordinary XLANG payload interoperability; compare the decoded values and call behavior.

If the call fails before dispatch, check connectivity and admission first. For an unknown method, check the exact published name. For codec failures, check wire names, fields, and registration. A document-sync warning is not an RPC result; use the returned response or error to assess the call.