Skip to main content
NetScriptdocs Search docs ⌘K v0.0.9
Browse documentation
View as Markdown

Compare backend workflows

These cases fit an application that already needs several durable runtimes. NetScript supplies shared definitions and generated resource wiring; you still own the business effects, deployment and persistence policy. The code shows the relevant boundary, not a complete application.

Choose a scenario

An order backend with delayed payment and shipping events

Keep an order’s state across restarts and reject forged shipment notifications.

Definition excerpts for a workspace with sagas, triggers, workers and streams installed. Register the saga, webhook and record-shipment job, then run netscript generate. Implement the named job entrypoint to store each shipment once. Payment workers publish PaymentReceived or PaymentFailed with the same order correlation key. The state transition below does not charge or refund a card. T1 persistence needs a durable configured store. The HMAC sender uses the default x-netscript-signature header.

NetScript

orders.ts TypeScript
orders.tsorders.tsTypeScript
import { defineSaga, sagaCompensate } from '@netscript/plugin-sagas-core';
import type { SagaMessage, SagaState } from '@netscript/plugin-sagas-core/domain';

interface OrderState extends SagaState {
  orderId: string;
  status: 'pending' | 'paid' | 'cancelled';
}
const initial: OrderState = { orderId: '', status: 'pending' };

export const order = defineSaga('order')
  .durability('t1')
  .state(initial)
  .correlate<SagaMessage>((message) => message.correlationKey)
  .on<'PaymentReceived', { orderId: string }>('PaymentReceived', (saga, event) => {
    saga.state.orderId = event.payload.orderId;
    saga.state.status = 'paid';
    return [];
  })
  .on<'PaymentFailed', { reason: string }>('PaymentFailed', (_saga, event) => [
    sagaCompensate(event, event.payload.reason),
  ])
  .compensate('PaymentFailed', (saga) => {
    saga.state.status = 'cancelled';
    return [];
  })
  .build();

webhook.tswebhook.tsTypeScript
import { defineWebhook, enqueueJob } from '@netscript/plugin-triggers-core';
import { defineJob } from '@netscript/plugin-workers-core';
import { z } from 'zod';

const Shipment = z.object({ deliveryId: z.string(), orderId: z.string() });
const recordShipment = defineJob('record-shipment')
  .payload(Shipment)
  .entrypoint('./workers/jobs/record-shipment.ts')
  .build();

export default defineWebhook((event) => {
  const payload = Shipment.parse(event.payload.body);
  return Promise.resolve([
    enqueueJob(recordShipment, {
      payload,
      idempotencyKey: `shipment:${payload.deliveryId}`,
    }),
  ]);
}, {
  id: 'shipment-received',
  path: '/webhooks/shipment',
  verifier: 'hmac-sha256',
  secretEnv: 'SHIPMENT_WEBHOOK_SECRET',
});

Typical alternative

Nest provides durable workflows as well as queue integrations. An existing Nest app can keep its workflow and queue providers; its webhook controller still needs signature verification and an explicit handoff to the work. Hono can serve the ingress while a chosen queue or workflow engine owns durability.

Sources: Nest durable workflows · Nest queues

Why it matters: For a Deno workspace already running these plugins, persisted state, verified ingress and named job dispatch use generated registries and resource wiring. You avoid designing those joins for each integration. Retries still require idempotent business effects, and cancellation is not a payment refund.

Build it step by step

A scheduled ERP sync with a Python normalization step

Run an existing Python transform every night and retain the job’s outcome.

Definition excerpt: register the sync job and scheduled trigger in a workers/triggers workspace. Provide workers/scripts/normalize.py; it reads the input argument and prints a JSON object as its last stdout line. Relative paths resolve from the worker’s working directory. Python must be installed and allowed by the host. It inherits the worker’s OS access; Deno permission flags do not sandbox it. Production imports must handle retries without duplicating writes.

NetScript

sync.ts TypeScript
sync.tssync.tsTypeScript
import {
  createFailureResult,
  createSuccessResult,
  defineJob,
} from '@netscript/plugin-workers-core';
import { defineTask } from '@netscript/plugin-workers-core/builders';
import { createDefaultTaskExecutor } from '@netscript/plugin-workers-core/executor';
import { defineScheduledTrigger, enqueueJob } from '@netscript/plugin-triggers-core';

const normalize = defineTask('normalize-erp')
  .runtime('python')
  .entrypoint('./workers/scripts/normalize.py')
  .args('--input', '.data/incoming/export.csv')
  .timeout(60_000)
  .build();
const executor = createDefaultTaskExecutor();

export const sync = defineJob('sync-erp')
  .handler(async () => {
    const result = await executor.execute(normalize);
    return result.success
      ? createSuccessResult(result.result)
      : createFailureResult(result.error ?? 'Normalization failed');
  })
  .retry(2)
  .build();

export const schedule = defineScheduledTrigger(
  () => Promise.resolve([enqueueJob(sync)]),
  { id: 'nightly-erp', cron: '0 2 * * *', timezone: 'UTC' },
);

Typical alternative

A Nest schedule can enqueue a queue job, and that processor can spawn Python. The team owns the subprocess adapter, exit/result protocol and connection to the queue’s execution record. A managed batch scheduler is also a sound choice when the transform is already deployed there.

Sources: Nest scheduling · Nest queues

Why it matters: NetScript supplies the task runtime adapter and result protocol alongside the scheduled trigger and job result. Keeping an existing transform in its own language is cheaper than rewriting it solely to fit a TypeScript handler. You still operate the interpreter, data files and retry-safe import.

Build it step by step

An agent investigating a failing multi-service app

Find the live service and operation schema before inspecting a failed request.

Run netscript agent init in the workspace and connect its MCP server. These are tool-call recipes, executed in order rather than as a JSON-RPC batch. Replace each placeholder with the exact name or operation id returned by the preceding discovery call. Start unfamiliar API work with find_guidance and search_docs. After inspection, use the generated typed SDK client for application calls; these discovery tools do not invoke a business operation.

NetScript

mcp.json JSON
mcp.jsonmcp.jsonJSON
[
  {
    "name": "list_api_services",
    "arguments": {}
  },
  {
    "name": "list_service_operations",
    "arguments": {
      "service": "<service name returned above>",
      "limit": 10
    }
  },
  {
    "name": "get_operation_schema",
    "arguments": {
      "service": "<service name returned above>",
      "operation": "<operation id returned above>"
    }
  },
  {
    "name": "get_recent_errors",
    "arguments": {
      "service": "<service name returned above>",
      "limit": 5
    }
  }
]

Typical alternative

Encore has a local MCP server, Next has a development MCP endpoint, and Nest Observe exposes observability through MCP. If your application already uses one of those stacks, use its native tools. Tool coverage and the resources represented differ; MCP itself is not unique to NetScript.

Sources: Encore local MCP · Next MCP · Nest observability MCP

Why it matters: In a NetScript workspace, one server can connect service discovery, operation schemas, runtime health and correlated telemetry to the same app vocabulary. The agent can inspect the declared service instead of guessing a port or endpoint. Diagnostics still depend on the running resources and available telemetry.

Build it step by step

When another backend is a better fit

Keep Nest when its Node ecosystem, dependency injection and existing workflow integrations meet the need. Use Hono for a small HTTP service that does not need a coordinated worker estate. Choose Encore when its infrastructure model and platform workflow suit how you want to operate. Adding NetScript solely for one webhook or cron task adds a workspace and orchestration cost.

See the capability table and trade-offs.

Search all documentation

Type a term to search the documentation.