| Pick this approach | Integration effort | Evidence it should expose |
|---|---|---|
| Send inside the contact-form handler | Few initial components; request handling owns delivery errors | Intake decision and each send attempt |
| Persist intake and dispatch work together | Requires a transactional store and a dispatcher | Committed route, pending work, and attempt history |
| Route through an existing event pipeline | Fits a team that already operates consumers and replay | Original event, routing revision, and consumer outcomes |
Build a notification center backend that can explain a routing decision after the request ends. For a B2B SaaS contact form, that means keeping the selected support queue and pending notification work in the same transaction, with an audit log feeding delivery history. Email and SMS are consequences of that decision; neither channel should become the only record that a customer asked for help.
TL;DR: Build the notification center around an append-only audit log and a separate view of delivery history. Give the polling API a stable cursor. Record why the contact reached a queue, then distinguish a dispatch attempt from an observed delivery outcome. This field guide uses investigation effort as the deciding test: can support explain one submission without searching three unrelated logs?
How should a notification center backend expose email and SMS delivery history?
Start with the form, not the transport. Consider a deliberately illustrative submission: contact contact-42, account account-7, category billing. A routing rule selects billing-support. The useful question is whether that choice happened, which rule revision made it, and what notification work followed. A message identifier alone cannot answer those questions in this design.
Diagram in words: contact submission → committed routing decision and pending work → dispatcher → email or SMS adapter → observed status → delivery-history projection → authenticated polling response. The audit record sits beside this path and retains the sequence of observations.
Keep those boundaries visible.
The distinction matters during a support investigation. A worker might record an attempted dispatch without having evidence of receipt. A queue assignment might be correct even while the notification remains pending. Design the interface to show both facts together, with separate labels, so a successful routing decision never silently becomes a claim that somebody read a message.
Pick direct sending for a bounded prototype
Use a request-bound send when the exercise is small enough that the team explicitly accepts coupling contact submission to transport handling. Its attraction is integration effort: one handler can validate input, select a queue, and call an adapter. Still create the contact record before treating a send result as the whole outcome.
The trap is an ambiguous retry.
If a response is lost after the adapter accepted a message, repeating the form submission can create another contact or another notification. Give intake a stable deduplication key and define its scope. Treat this as a design requirement, not a promise that an external transport can deduplicate your request.
Pick transactional dispatch when support needs an explanation
For the support-intake example, choose a transaction that commits the contact, selected queue, routing revision, audit entry, and pending dispatch work together. A dispatcher then claims committed work. This is a proposed implementation contract: a successful form response means intake was committed, while channel delivery remains a separate operation.
That choice adds a worker and a recovery path. In exchange, the support team gets something precise to investigate even before a message leaves the system. Integration effort moves from wiring a transport into a handler toward defining ownership, persistence, and transitions. That is a useful trade-off when the actual job is routing customers to the right people.
Here is a small TypeScript model for the history projection and polling boundary. The data is synthetic. The pure functions can run in a Node.js service, but they deliberately leave storage and authentication to the surrounding application. The caller must supply tenant-scoped records from a consistent read; the example isn't a durable queue implementation.
type Channel = "email" | "sms";
type Kind =
| "route_selected"
| "dispatch_requested"
| "adapter_accepted"
| "delivery_confirmed"
| "delivery_failed";
type Entry = Readonly<{
sequence: number;
tenantId: string;
contactId: string;
notificationId: string;
kind: Kind;
channel?: Channel;
attemptId?: string;
queue?: string;
routingRevision?: string;
}>;
function pollHistory(
tenantEntries: readonly Entry[],
after: number,
limit = 50,
): { items: Entry[]; nextCursor: number; hasMore: boolean } {
if (!Number.isSafeInteger(after) || after < 0) {
throw new RangeError("Invalid cursor");
}
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) {
throw new RangeError("Invalid page size");
}
const candidates = tenantEntries
.filter((entry) => entry.sequence > after)
.sort((a, b) => a.sequence - b.sequence);
const items = candidates.slice(0, limit);
return {
items,
nextCursor: items.length ? items[items.length - 1].sequence : after,
hasMore: candidates.length > limit,
};
}
function summarizeAttempt(entries: readonly Entry[]): string {
const observed = new Set(entries.map((entry) => entry.kind));
if (observed.has("delivery_confirmed") &&
observed.has("delivery_failed")) return "conflicting_evidence";
if (observed.has("delivery_confirmed")) return "confirmed";
if (observed.has("delivery_failed")) return "failed";
if (observed.has("adapter_accepted")) return "accepted";
if (observed.has("dispatch_requested")) return "pending";
return "unknown";
}
const sample: readonly Entry[] = [{
sequence: 1,
tenantId: "tenant-demo",
contactId: "contact-42",
notificationId: "notification-42",
kind: "route_selected",
queue: "billing-support",
routingRevision: "billing-rules-3",
}];
const firstPage = pollHistory(sample, 0);
const emptyPage = pollHistory(sample, firstPage.nextCursor);
if (firstPage.items.length !== 1 || emptyPage.items.length !== 0) {
throw new Error("Polling contract failed");
}
The cursor starts at 0. The default page holds 50 entries, with a maximum of 100; those are example API choices, not measured capacity recommendations. An empty response preserves the cursor. Each stored sequence must be a positive safe integer, unique within its cursor scope, and visible in commit order. Enforce those invariants in storage. Otherwise, a transaction that commits late with a lower sequence could fall behind a cursor the client has already advanced.
That last detail is easy to miss.
Expose a tenant-scoped read endpoint such as GET /notification-history?after=0&limit=50. Treat that path as an application-defined example. Resolve the tenant from authenticated context, authorize access to the relevant contact, and fetch only authorized records before pagination. Don't trust a tenant identifier supplied in query parameters. Advance the client cursor only after applying the page successfully.
Keep polling order separate from transport timestamps. Store when an external observation occurred and when your service recorded it, but paginate by the committed sequence. Deduplicate repeated observations using the adapter's documented event identity where available; otherwise specify a conservative application rule and retain enough evidence to investigate collisions. Never silently assume every adapter has the same callback contract.
The summary function expects entries for exactly one notification, channel, and attempt. Group by those identifiers before calling it. It reports conflicting evidence instead of choosing whichever callback happened to arrive last. Keep the original observations so an operator can inspect the disagreement. A production projection needs an explicit reconciliation policy for its actual transport contracts. For example, suppose attempt attempt-1 receives an acceptance observation and then loses its worker response. A later retry must get its own attempt identifier while remaining attached to notification-42. Otherwise, a failure recorded for the retry could overwrite evidence about the earlier attempt. Store both histories, and make the notification-level view acknowledge any unresolved attempt rather than treating the most recent record as a complete explanation.
Now connect the records to observability. Put contact, notification, and attempt identifiers in structured logs. Measure pending-work age, attempts by outcome, and the lag between an observed status and its appearance in the polling view. Keep contact identifiers out of metric labels; reserve them for logs and authorized history queries. Choose alert thresholds from the service's response commitments rather than copying arbitrary numbers into an alert rule. An acceptance count is useful, but it doesn't replace a delivery measurement.
Test the boundaries that can mislead the support team: replay the same submission, repeat an observation, interrupt a worker after dispatch, read two consecutive pages, and poll while new entries commit. Also test that another tenant cannot retrieve contact-42. During deployment, keep readers compatible with older event shapes while workers roll forward, and retain the routing revision on historical records rather than recomputing old decisions with new rules.
Pick an existing event pipeline when its operational contract already fits
If a team already operates an event pipeline, publish the committed routing decision into that workflow and let channel consumers create attempt records. Reuse is attractive only if the existing contract covers authorization, replay, ordering scope, and ownership of failed work. A pipeline doesn't decide those policies for the notification center.
Before integrating, trace the illustrative billing contact through a replay. Decide whether replay rebuilds a history projection or authorizes a new send.
Keep those actions separate.
A read-model rebuild should not accidentally notify the support queue again.
Limits: delivery evidence has a scope
This design records routing decisions and delivery observations. It doesn't establish that a human read a message, prove that a queue assignment was appropriate, or supply a retention policy. Keep message bodies and contact details out of routine operational logs; design retention and access rules for the actual support workflow.
Message purpose also matters. The FTC's CAN-SPAM guidance distinguishes commercial email from transactional or relationship messages, and mixed content requires care about the message's primary purpose. Don't infer an exemption merely because a message originated from a contact form. If a future workflow introduces password-reset codes, OWASP's guidance calls for protections including secure generation, expiration, single use, and controls against excessive requests. Keep those secrets out of the audit trail.
The next engineering decision is small and concrete: define what each status proves, then walk one contact through intake, routing, dispatch, and polling. Any unexplained transition is work to finish before the notification center becomes support's source of truth.
References
- FTC, CAN-SPAM Act: A Compliance Guide for Business: https://www.ftc.gov/business-guidance/resources/can-spam-act-compliance-guide-business
- OWASP, Forgot Password Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Forgot_Password_Cheat_Sheet.html
Top comments (0)