Agora

You're viewing the docs for Crypto 0.x. The latest is 1.x (rc). Go to the 1.x (rc) docs

Transports

How a tenant reaches the control plane — HTTP by default, Redis, BullMQ, the Adonis queue or a durable workflow, and what every driver guarantees.

A tenant talks to the control plane over a transport. HTTP is the default: an app that configures nothing behaves exactly as before. A broker driver changes only that server-to-server hop — same calls, same capabilities, same audit.

// config/crypto.ts (an app)
import { defineConfig, transports } from '@adonis-agora/crypto'

export default defineConfig({
  topology: 'tenant',
  tenant: {
    url: env.get('CRYPTO_URL'),
    partition: 'streaming',
    token,
    // default: transports.http({ url })
    transport: transports.redis({ connection: redis.connection('main') }),
  },
})
// config/crypto.ts (the control plane) — the same driver, consumed here
export default defineConfig({
  topology: 'control-plane',
  verifyTenant,
  transport: transports.redis({ connection: redis.connection('main') }),
})

The browser always uses HTTP

The transport is only for tenant ↔ control-plane traffic between servers. Anything a browser calls — the console, @adonis-agora/crypto-react, the app's own endpoints — talks HTTP, and the control plane keeps its HTTP API (/_crypto/v1/...) mounted whatever tenant transport is configured. A fleet can mix tenants: some on HTTP, some on a broker, the same control plane serving both (there is a test for exactly that).

That also means the broker never replaces the API: it is an extra consumer next to it.

Drivers

DriverCall channelPeer
transports.http({ url, fetch?, timeoutMs? }) (default)request/response over POST /_crypto/v1/transportnone (global fetch; fetch lets you add mTLS, a proxy or the crypto envelope)
transports.redis({ connection, prefix?, timeoutMs? })request on <prefix>:requests, reply on <prefix>:reply:<id>@adonisjs/redis (or any ioredis-shaped connection)
transports.bullmq({ connection, queueName?, prefix?, timeoutMs? })native reply: job.waitUntilFinished(queueEvents) returns the worker's resultbullmq (loaded lazily)
transports.queue({ connection, dispatch, consume, prefix?, timeoutMs? })request via @adonisjs/queue, reply on Redis (<prefix>:reply:<id>) — the queue has no await-result@adonisjs/queue
transports.durable({ engine | gateway, workflow?, timeoutMs? })native reply: start('crypto.call', …) resolves with the run result@adonis-agora/durable (injected)

Both carry the same envelope (v, id, operation, input, token, issuedAt), so switching drivers is a config change, not a code change.

Reply per driver

  • BullMQ has a reply built in: Queue.add() + job.waitUntilFinished(queueEvents) resolves with the worker's return value, so the reply is the job result and a failed job is the dead-letter (removeOnFail). transports.bullmq uses that: no extra reply key.
  • @adonisjs/queue (@boringnode/queue) does not: Job.dispatch() resolves { jobId } and there is no "wait for the result". So transports.queue carries the request on the queue and the reply on the queue adapter's Redis (<prefix>:reply:<id>, the same contract as the Redis driver). The app supplies its job's dispatch and its worker's consumer (consume), so the job is just a carrier for the envelope.
  • durable also has a reply built in, at the run level: start() resolves with the run's result. transports.durable passes the envelope as the workflow's input and takes run.output as the reply, so the answer comes back on the same line — no reply queue, no polling. A run that fails surfaces as TransportError('unavailable'); a run that never settles is a timeout.

Durable as the call channel

When the tenant already runs @adonis-agora/durable, the crypto call can ride it. The tenant starts a workflow; the control plane runs it; the tenant gets the result back from the same start() call.

config/crypto.ts (the tenant)
// The role-agnostic durable gateway: store-backed on a standalone/control-plane pod, a round-trip
// proxy on a store-less `role: 'tenant'` pod. Both resolve `start()` with the run result.
import { runGateway } from '@adonis-agora/durable/services/main'
import { defineConfig, transports } from '@adonis-agora/crypto'

export default defineConfig({
  topology: 'tenant',
  tenant: {
    url: env.get('CRYPTO_URL'),
    partition: 'streaming',
    token,
    transport: transports.durable({
      gateway: () => runGateway,
      timeoutMs: 15_000,
    }),
  },
})

A pod that owns a store can pass the engine instead — engine: () => engine from the same module (default export); both forms take (workflow, input, runId) and resolve with the run result.

On the control plane there is nothing to configure beyond the workflow itself: the engine runs it, and the body is handleTransportCall — the same verify → dedupe → run path as POST /_crypto/v1/transport and serveBroker.

app/workflows/crypto_call_workflow.ts (the control plane)
import { BaseWorkflow, type WorkflowCtx } from '@adonis-agora/durable'
import { handleTransportCall } from '@adonis-agora/crypto'

export default class CryptoCallWorkflow extends BaseWorkflow {
  static workflow = { name: 'crypto.call', version: '1' }

  async run(ctx: WorkflowCtx, input: unknown) {
    // `localStep` is what makes it replay-safe: the operation runs once per run and a replay returns
    // the checkpointed reply instead of re-running it. The envelope id is the second guard (dedupe).
    return ctx.localStep('crypto.call', () => handleTransportCall(input))
  }
}

handleTransportCall needs verifyTenant — configure it on the control plane like any other server. It refuses to run on a tenant (topology: 'tenant' has no service and no verifier).

The workflow is registered by name (crypto.call), so the server does not need transport in its config for this driver: no broker is consumed, the engine is the consumer.

What every driver guarantees

  • The token travels on every message, and the control plane runs verifyTenant on each one. A shared broker is not a trust boundary.
  • Partition and capabilities come from the verified token only — never from the payload, the queue name or a header.
  • Dedupe by <partition>:<id>: a broker delivers at-least-once, and the same id never runs an operation twice. The in-process store is 10 minutes / 10k ids; a multi-replica control plane should pass a shared one.
  • Bounded: 512 KiB per message, and a message older than 5 minutes is refused.
  • Timeouts: the caller's timeoutMs (default 10s); a broker that loses the reply surfaces TransportError('timeout'), never a silent hang.
  • Dead-letter: a malformed or oversized message is not retried forever — it goes to the driver's dead-letter (<prefix>:dead for Redis) with the reason.
  • Audit: the operation goes through the same service, so the crypto audit records the key, version, actor (the token's clientId) and result as with HTTP.

Latency

A brokered call is a queue hop: expect single-digit milliseconds on a local Redis and tens of milliseconds when the broker is remote, on top of the operation. A crypto operation waits for that on every request, so keep HTTP for latency-sensitive paths and use a broker when the crypto server must not expose a public endpoint (or the call must survive a restart of the caller). Batch where the API allows it (encryptBatch) to amortise the hop.

Durable is the slowest of the four: a call is a workflow turn (dispatch, execute, checkpoint, reply), so budget hundreds of milliseconds to seconds and give it its own timeoutMs (default 15s). It pays off when the operation must be durable — retried by a worker, auditable as a run, survivable across a restart of both sides — not when it is on a request's hot path.

On this page

Partner

Your product as the official integration for Crypto, right here.

Become a partner →