Skip to main content
Back to blog
Engineering

Inside the atomic sequence engine

·8 min read·NamasteSuite team

The sequence engine is a core part of NamasteSuite. This post walks through the controls used to claim due work once, record delivery intent, and recover safely when a provider or process fails.

The atomic claim

Every processor tick runs ns_claim_due_enrollments(), which selects active enrollments whose next_step_at <= now() using FOR UPDATE SKIP LOCKED. Concurrent runners therefore cannot hold the same row lock at the same time.

Log-before-send

We insert into ns_email_log with status='pending' before calling Resend. A unique index on (enrollment_id, step_id) prevents a retry from inserting a second log row for the same step.

Throttle, cap, window

  • Throttle: min 48h between emails to the same lead (configurable per sequence).
  • Daily cap: max 8 emails per lead per day.
  • Send window + day-of-week filters honor the workspace timezone.

Completion chaining

When an enrollment finishes the last step, the engine checks on_complete_sequence_id and auto-enrolls in the next sequence. Onboarding flows into nurture flows into long-haul newsletters without manual work.