Architecture Overview
1. Distributed Storage & Checkpoint OCC
A. PostgreSQL Schema Setup
When running multi-pod Kubernetes or ECS workloads, you must enable Optimistic Concurrency Control (OCC) to prevent Last-Write-Wins (LWW) state clobbering across concurrent worker nodes. Run the following DDL migration (or useadapter.ensureTables()):
B. Handling OptimisticLockException
If two worker nodes execute concurrent step completions or resumptions for the same stackId, the second update raises OptimisticLockException. Wrap workflow execution in an exponential backoff retry loop:
2. Durable Timers & Worker Schedulers (@siglo/scheduler)
A. Deploying the Background Poller Daemon
To resume sleeping workflows (wait('24h') or waitForEvent('APPROVAL', { timeout: '7d' })) even after container restarts:
B. Serverless & Cloud-Native Webhook Dispatchers
For serverless architectures (AWS Lambda, Google Cloud Run) where persistent background polling is prohibited, usecreateSchedulerWebhookHandler connected to AWS EventBridge Scheduler or Google Cloud Tasks:
- Target URL:
https://api.yourdomain.com/scheduler/resume - Headers:
Authorization: Bearer <SCHEDULER_SECRET_TOKEN> - Body:
{"stackId": "stack-12345", "payload": {"event": {"type": "timer:expired"}}}
3. Idempotency & Thundering Herd Defense
A. Wait-and-Settle Configuration
In high-volume webhook endpoints (e.g., Stripe, Shopify) or distributed messaging consumers (Kafka, SQS), concurrent duplicates can hit workers within milliseconds. Instead of rejecting duplicates immediately with 409 Conflict, enable Wait-and-Settle:B. Two-Tier Error Classification
When handling errors in idempotent steps, differentiate between permanent business declines and transient infrastructure faults:- Permanent Business Errors (e.g.
CardDeclined,AccountNotFound): CallidempotencyStore.complete(key, { error: 'CardDeclined' })so retried requests return the cached decline without charging the card again. - Transient Infrastructure Errors (e.g.
ETIMEDOUT,503 Service Unavailable): Let Siglo callidempotencyStore.fail(key), releasing the claim so subsequent retry attempts re-execute against the gateway.
4. Zero-Trust Network Perimeter & SSRF Hardening
A. Pre-Flight DNS Resolution & IP Pinning
Siglo enforces declarative network egress boundaries when using.networkPolicy() on flows or .allowNetwork() on steps.
B. Unix Domain Socket Hardening
By default when network policy is active, Unix domain sockets are disallowed unless explicitly listed inallowUnixSockets:
5. Sagas, Named Compensations & Dead-Letter Queues (DLQ)
A. Named Compensation Registry
Never rely on in-memory closures for long-running workflows across service deployments. Register named compensation handlers:B. Best-Effort Compensations & Persistent DLQ Sink
Provide adeadLetterQueue sink with a send method through CompensationRunOptions to capture compensation failures:
C. Stale Stack Reconciliation Sweep
Deploy a scheduled Kubernetes CronJob running the reconciler every 10 minutes to recover from unhandled pod crashes or OOM events:6. DevTools & Control Plane Hardening (@siglo/monitor)
A. Production Monitor Configuration
Never expose the DevTools monitor without authentication and telemetry redaction:7. Concurrency & Resource Tuning
Production Readiness Checklist
Before tagging your service for production release, verify the following:- OCC Versioning Active:
siglo_checkpointstable includesversion BIGINT DEFAULT 1. - Row-Level Poller Running:
@siglo/schedulerinstance started with gracefulSIGTERMhandler. - Wait-and-Settle Configured: Critical financial / billing steps configure bounded
settleTimeoutMs. - Named Compensations Registered: All durable sagas use
registerCompensationHandlerrather than local closures. - Compensation DLQ Connected: A
deadLetterQueuesink ({ send: async (entry) => ... }) forwards failed rollbacks to SQS or Kafka. - Cron Reconciler Scheduled:
npm exec --package=@siglo/cli -- siglo reconcilescheduled to sweep stale stacks past heartbeat windows. - Network Policies Enforced: Zero-trust egress rules block RFC 1918 private IPs and container Unix sockets.
- Monitor Security Hardened: DevTools server configured with authentication tokens, field redaction, and
allowRemoteResume: false. - OpenTelemetry Active: Traceparent headers injected via
@siglo/opentelemetryfor distributed tracing.
