---
title: Scheduled work and email notifications
summary: A practical guide to Platform schedules, target-system ownership, and the durable email workflow.
version: 1.0.0
type: guides
order: 1
badges:
  - content: Guide
    backgroundColor: teal
    textColor: teal
---

**Audience & Outcome:** This guide is for platform engineers and operators working with [[service|scheduler-service]] and [[service|notification-api]]. You will learn how recurring jobs trigger catalog indexing and how stateless transactional email delivery guarantees reliability without a notification database.

BookWorm's Platform subdomain separates recurring time-based orchestration from transactional email dispatch into two independent services: [[service|scheduler-service]] runs recurring Quartz.NET jobs backed by [[container|scheduler-database]], while [[service|notification-api]] operates as a stateless Kafka and SMTP worker with no database.

## Context and motivation

Two distinct operational needs exist across BookWorm's business domains:

- **Periodic batch triggers:** Catalog books change continuously, and generating embeddings plus updating [[container|catalog-vector]] is more efficient in scheduled batches than inside synchronous HTTP book writes.
- **Decoupled customer emails:** Order creation, completion, and cancellation should never block on external SMTP server latency or fail when an email provider is temporarily unreachable.

Separating these capabilities into dedicated Platform services keeps domain services focused on business invariants while avoiding cross-domain database coupling.

## How it works

The visual below illustrates the two independent Platform pipelines—[[service|scheduler-service]] triggering [[service|catalog-ingestion]] on a UTC cadence, and [[service|notification-api]] delivering order emails over SMTP.

<MermaidFileLoader file="mermaids/scheduled-work-and-email-notifications-diagram-1.mmd" />

### Recurring work in Scheduler

[[service|scheduler-service]] persists Quartz state, 30-day execution history, and its transactional outbox in [[container|scheduler-database]]. **Quartz Dashboard** (exposed at `/quartz` behind Microsoft Entra ID `admin` role) provides operational visibility.

| Job                     | Cron (UTC)       | Cadence          | Behavior                                                                                                               |
| :---------------------- | :--------------- | :--------------- | :--------------------------------------------------------------------------------------------------------------------- |
| `ProcessVectorBatchJob` | `0 0/5 * * * ?`  | Every 5 minutes  | Non-concurrent; publishes [[event\|ProcessVectorBatchIntegrationEvent]] to [[channel\|scheduler.process-vector-batch]] |
| `HeartbeatJob`          | `0/30 * * * * ?` | Every 30 seconds | Emits structured heartbeat logs and OpenTelemetry telemetry                                                            |

Both jobs use `FireOnceNow` misfire handling so a missed run triggers one immediate catch-up execution rather than replaying every missed interval. When `ProcessVectorBatchJob` succeeds, [[service|scheduler-service]] guarantees only that the Kafka event was published. [[service|catalog-ingestion]] independently consumes [[channel|scheduler.process-vector-batch]] to update [[container|catalog-vector]].

### Stateless email delivery in Notification

[[service|notification-api]] consumes Finance's Kafka order commands (<ResourceLink id="bookworm.{env}.finance.place-order" type="channel">`bookworm.{env}.finance.place-order`</ResourceLink>, <ResourceLink id="bookworm.{env}.finance.complete-order" type="channel">`bookworm.{env}.finance.complete-order`</ResourceLink>, and <ResourceLink id="bookworm.{env}.finance.cancel-order" type="channel">`bookworm.{env}.finance.cancel-order`</ResourceLink>), partitioned by `OrderId`:

<Steps>
<Step title="Idempotency and blank-email check">

Each handler checks a 24-hour Redis idempotency guard keyed by message ID and handler name, skipping duplicate deliveries. Messages with blank or whitespace recipient emails return cleanly without error.

</Step>
<Step title="Template rendering and resilient SMTP handoff">

The worker renders the MJML order email template into HTML and delivers it over SMTP (Mailpit locally, [[service|sendgrid-api]] in Azure) through a resilience pipeline with circuit breaking, exponential retry with jitter, and a 30-second timeout.

</Step>
<Step title="Dead-letter queue fallback">

If transient SMTP failures exhaust both resilience and broker retries, failed messages route to <ResourceLink id="bookworm.{env}.notification.dead-letter-queue" type="channel">`bookworm.{env}.notification.dead-letter-queue`</ResourceLink> for operator investigation and replay.

:::note
SMTP acceptance proves only that the relay server accepted the message; it never proves inbox delivery or commercial order status.
:::

</Step>
</Steps>

<AccordionGroup>
<Accordion title="Design trade-offs and alternatives considered">

| Decision                                                       | Benefits                                                                                | Costs and limits                                                                                      |
| :------------------------------------------------------------- | :-------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------- |
| **Stateless Notification worker (Kafka + Redis + DLQ)**        | Removes a database, migrations, and hourly resend jobs; uses native Kafka durability    | Replaying failed emails requires Kafka DLQ tooling rather than SQL queries                            |
| **At-least-once Kafka delivery with message ID deduplication** | Prevents lost order emails during transient network or SMTP outages                     | Ambiguous SMTP timeouts or reissued commands can still produce duplicate emails                       |
| **Kafka event trigger from Scheduler to Catalog Ingestion**    | Eliminates synchronous HTTP coupling and token management between Scheduler and Catalog | Operators must inspect both Scheduler history and [[container\|catalog-database]] to confirm indexing |
| **`FireOnceNow` misfire instruction**                          | Prevents catch-up storms after Scheduler downtime                                       | Intermediate missed windows are skipped                                                               |

**Rejected alternatives:**

- **PostgreSQL email outbox with hourly Quartz resend jobs:** Retired because maintaining a dedicated database and sweeping jobs duplicated Kafka's native durable log, retry, and dead-letter queue capabilities.
- **Direct HTTP calls from Scheduler to Catalog:** Coupled ingestion availability directly to Scheduler execution.

</Accordion>
</AccordionGroup>

## Related documentation

- [[flow|notification-delivery]] — End-to-end notification delivery flow.
- [[flow|product-ingestion]] — End-to-end scheduled vector ingestion flow.
- [[service|scheduler-service]] — Detailed Scheduler service reference.
- [[service|notification-api]] — Detailed Notification service reference.
