Skip to main content
Reference vendor/dbos 2 min read

advanced-serialization


title: Use Portable Serialization for Cross-Language Interoperability impact: LOW impactDescription: Enables TypeScript workflows to exchange data with Python, Java, and Go applications tags: serialization, portable, cross-language, interoperability, json

Use Portable Serialization for Cross-Language Interoperability

By default, TypeScript DBOS uses SuperJSON serialization, which only TypeScript can read. Use "portable" serialization to write data as JSON that any DBOS SDK (Python, TypeScript, Java, Go) can read and write.

Incorrect (default SuperJSON — blocks cross-language access):

// A Python or Java client cannot read this workflow's
// inputs, outputs, events, or streams
async function processOrderFn(orderId: string) {
  await DBOS.setEvent("status", { progress: 50 });
  return { result: "done" };
}
const processOrder = DBOS.registerWorkflow(processOrderFn);

Correct (portable JSON — readable by any language):

import { DBOS } from "@dbos-inc/dbos-sdk";

async function processOrderFn(orderId: string) {
  await DBOS.setEvent("status", { progress: 50 });
  return { result: "done" };
}
const processOrder = DBOS.registerWorkflow(processOrderFn, {
  name: "processOrder",
  serialization: "portable",
});

Supported Portable Types

Portable JSON supports JSON primitives, arrays, and objects. Some TypeScript types are automatically converted:

TypeScript TypePortable Representation
DateRFC 3339 UTC string
BigIntNumeric string

Where to Set Serialization

On workflow registration (key: serialization) — affects inputs, outputs, events, and streams for that workflow:

const myWorkflow = DBOS.registerWorkflow(myWorkflowFn, {
  name: "myWorkflow",
  serialization: "portable",
});

Or with a decorator:

class Orders {
  @DBOS.workflow({ serialization: "portable" })
  static async processOrder(orderId: string) {
    await DBOS.setEvent("progress", 50);  // Portable by default
    return { done: true };                // Portable by default
  }
}

On individual operations (key: serializationType) — override per-operation when mixing strategies:

// Explicitly set portable on send (send is never affected by workflow default)
await DBOS.send(
  "workflow-123",
  { status: "complete" },
  "updates",
  undefined,  // idempotencyKey
  { serializationType: "portable" }
);

// Override on setEvent or writeStream
await DBOS.setEvent("key", value, { serializationType: "portable" });
await DBOS.writeStream("key", value, { serializationType: "portable" });

On enqueue from DBOSClient — for cross-language workflow submission:

import { DBOSClient } from "@dbos-inc/dbos-sdk";

const client = await DBOSClient.create({ systemDatabaseUrl: dbUrl });
const handle = await client.enqueue(
  {
    workflowName: "processOrder",
    queueName: "orders",
    serializationType: "portable",
  },
  "order-123",
);

Serialization Strategy Options

// On workflow registration or @DBOS.workflow decorator
serialization: undefined   // Uses config serializer (SuperJSON by default)
serialization: "portable"  // Portable JSON for cross-language use
serialization: "native"    // Explicitly uses native TypeScript serializer

// On per-call operations (send, setEvent, writeStream, client.enqueue)
options.serializationType: "portable" | "native"

The keys differ by API: workflow/registration config uses serialization, while per-call options on send / setEvent / writeStream / client.enqueue use serializationType.

Portable Errors

When a portable workflow fails, the error is serialized in a standard JSON structure all languages can read:

import { PortableWorkflowError } from "@dbos-inc/dbos-sdk";

throw new PortableWorkflowError(
  "Order not found",
  "NotFoundError",
  404,
  { orderId: "order-123" },
);

Non-portable exceptions raised in a portable workflow are automatically converted to this format on a best-effort basis.

Key Rules

  • send is never affected by the workflow’s serialization strategy — always set serializationType explicitly on send for cross-language messages
  • Step outputs always use the native serializer regardless of workflow strategy (steps are internal)
  • DBOSClient.serializer must match the app’s serializer for default-format data, but portable data is always readable

Reference: Cross-Language Interaction