ADR-004: Let Scheduler trigger Notification-owned maintenance batches
Scheduler publishes hourly maintenance requests while Notification selects and processes bounded outbox batches and owns resend and cleanup outcomes.
This architecture decision has been marked as superseded.
This ADR is Superseded. Hourly Notification resend and cleanup maintenance jobs have been retired in favor of native Kafka retries and dead-letter queues; see ADR-002: Keep business ownership outside the SchedulerDecision Recordv1.0.0ADR-002: Keep business ownership outside the SchedulerThe Scheduler System coordinates when work is attempted, while Catalog and Notification systems own validation, processi...Ownerplatform-engineering-teamOpen docs and ADR-001: Consume order notification commands through KafkaDecision Recordv1.0.0ADR-001: Consume order notification commands through KafkaNotification consumes Finance order commands through Wolverine and Kafka, keeping email processing outside the business ...Ownerplatform-engineering-teamOpen docs.
1. Context & Problem
Two routine maintenance tasks keep BookWorm’s notification system healthy: giving unsent emails another chance at delivery after transient provider problems, and cleaning up already-sent records so operational tables do not grow without limit. If the central job scheduler queried or deleted Notification’s database tables directly, the two systems would become tightly coupled around database structure, and operators might mistakenly treat a “job completed” signal as proof that emails were delivered or deleted.
2. Business Value
- Independent system evolution: The scheduler and the notification service can update their internal databases and schedules without breaking one another.
- Protected system resources: Processing maintenance work in fixed-size batches prevents large backlogs from overloading the database or mail provider in a single run.
- Clear operational ownership: The scheduler owns when maintenance is requested, while Notification owns which records qualify and how they are retried or removed.
3. How It Works
- Hourly maintenance triggers: Every hour, the scheduler publishes two lightweight maintenance requests—one to retry unsent emails and one to clean up sent records. These requests carry only timing and identity metadata, with no recipient data, batch sizes, or retention rules.
- Bounded retry batch: When Notification receives a resend request, it picks up to 100 unsent records in oldest-first order.
- Eligibility checks only whether the record is unsent (it does not require a prior recorded error).
- Notification attempts delivery for each item, logs individual send failures while continuing through the batch, and marks successful original records as sent.
- Bounded cleanup batch: When Notification receives a cleanup request, it picks up to 100 sent records in oldest-first order and deletes them.
- No return status to Scheduler: Scheduler never touches Notification’s tables and receives no maintenance completion event back.
4. Trade-offs & Lessons Learned
- A successful job run is not a delivery SLA: Because each run processes at most 100 records and individual email sends can fail while the batch continues, a completed hourly job does not guarantee the entire backlog was drained or every email succeeded. Operators must correlate job history with pending counts, oldest pending age, resend success/failure counts, and mail-provider health.
- Head-of-line delay for newer emails: Processing unsent records strictly oldest-first without a lifetime retry cap means repeatedly failing old records can occupy batch slots and delay newer unsent messages.
- Cleanup is operational deletion, not an audit archive: Sent records are deleted without a minimum age, retention window, or audit-hold check, so the outbox table cannot serve as a long-term delivery audit log.
- Row growth and duplicate risk: Resends reuse the shared sender flow (creating an additional row per attempt), and there are no Notification-side row locks or exactly-once guarantees across duplicate maintenance triggers or overlapping consumers.
- Alternatives rejected:
- Letting Scheduler query and delete Notification tables directly: Rejected because it couples Scheduler to Notification’s internal schema and data semantics.
- Processing the entire backlog in one run: Rejected because unbounded runs can exhaust memory, connections, or provider limits as backlogs grow.
- Treating Scheduler completion as delivery completion: Rejected because Scheduler owns only invocation timing, not downstream email processing.
5. Technical Reference
- Status & Context:
superseded(2026-11-01). Complements ADR-002: Keep business ownership outside the SchedulerDecision Recordv1.0.0ADR-002: Keep business ownership outside the SchedulerThe Scheduler System coordinates when work is attempted, while Catalog and Notification systems own validation, processi...Ownerplatform-engineering-teamOpen docs; does not add a terminal-failure policy or lifetime attempt cap. - Scheduler Triggers: Scheduler SystemSystemv1.0.0Scheduler SystemInternal Quartz-based platform system that persists schedules, coordinates
recurring jobs, and dispatches background wor...Ownerplatform-engineering-teamDiagramOpen docs uses Quartz jobs firing hourly (UTC) to publish
ResendErrorEmailIntegrationEventandCleanUpSentEmailIntegrationEventover Kafka with inherited identity and creation time only. - Notification Processing (Notification APIServicev1.0.0Notification APIInternal background worker that consumes order commands from Kafka, renders
MJML email templates, and submits mail over ...SubscribesPlaceOrderCommand, CancelOrderCommand +1APIsAsyncAPIOwnerplatform-engineering-teamDiagramRepositoryOpen docs / Notification PostgreSQL):
- Batch size is bounded to at most 100 records per request, ordered by
sequence_number. - Resend: Selects all unsent records with tracking enabled (does not require a recorded error despite the event name). Individual delivery failures are logged and the batch continues; successful originals are marked sent (while the shared
ISenderoutbox wrapper creates a new outbox row per attempt). Handler-token cancellation, selection failures, and final save failures propagate. - Cleanup: Selects sent records without a minimum age, retention duration, or audit-hold check, removes the batch, and saves; failures are logged and rethrown.
- Batch size is bounded to at most 100 records per request, ordered by
- Boundary Rules: Scheduler never accesses Notification tables directly, and Notification publishes no application-level maintenance result event.