Skip to content

Transacciones Saga

Documentación en español de Transacciones Saga, alineada con el monorepo y la guía inglesa.

Entrada rápida

SagaBuilder.define()

  ├─ Step 1: Create resource   → Compensation: Delete resource
  ├─ Step 2: Update resource   → Compensation: Revert update
  ├─ Step 3: Send notification → Compensation: Void notification

  └─ Coordinator.execute(saga)

       ├─ Step 1 → success
       ├─ Step 2 → success
       ├─ Step 3 → FAILURE

       └─ Compensate
            ├─ Undo Step 2 (revert update)
            └─ Undo Step 1 (delete resource)
typescript
const saga = new SagaBuilder('deploy-service')
  .step('create-dir', async (ctx) => {
    await fs.mkdir(ctx.path);
  }, {
    compensate: async (ctx) => {
      await fs.rmdir(ctx.path);
    },
  })
  .step('write-config', async (ctx) => {
    await fs.writeFile(ctx.path, ctx.config);
  }, {
    compensate: async (ctx) => {
      await fs.unlink(ctx.path);
    },
  })
  .step('restart-service', async (ctx) => {
    await service.restart();
  }, {
    compensate: async (ctx) => {
      await service.restore(ctx.prevVersion);
    },
  })
  .build();
typescript
const pool = new WorkerPool({ maxConcurrency: 5 });
pool.execute(steps);  // Independent steps run in parallel
PolicyBehavior
No retryFail immediately, begin compensation
Fixed retriesRetry N times with fixed delay
Exponential backoffRetry with doubling delay, up to max
Circuit breakerUse shared circuit breaker state

Notas

  • CLI monorepo: cliEntry.ts · tras build: commander
  • Métricas: 25 proveedores · 5 topologías · 18 tools · 6700+ tests
  • Firmas API exactas: monorepo / API overview

Relacionado

MIT — Hecho para orquestación multi-agente.