A reaction or comment is a domain event; a notification is a user-facing consequence of that event. Keeping those concepts separate makes it possible to change delivery without changing the social action itself. It also prevents a common bug: the action succeeds, but notification delivery fails and the request reports an error even though the user’s reaction was saved.
Persist first, deliver second
Validate the action and authorization, commit it, then enqueue a notification event. For systems that cannot atomically commit a database row and queue message, use an outbox table written in the same transaction as the action. A worker can publish pending outbox records and mark them delivered. Make the consumer idempotent using a stable event ID so retries do not create duplicate inbox rows.
A useful event records the actor, recipient, object, action, and creation time. Avoid storing a fully rendered sentence as the only source: names and titles can change, and localization belongs at presentation time. Do not notify someone about their own action unless the product has an explicit reason.
Respect user controls
Preferences should be checked at delivery or display time, depending on whether muted events should be retained in the inbox. Group repeated events when a burst would overwhelm the recipient. Keep email or push delivery separate from the in-app inbox so each channel can retry and record its own status.
Choose when the inbox becomes reliable
A comment, its notification row, and the real-time delivery signal have different failure modes. Persist the user-facing state first. When an inbox notice is part of the same business transition, commit the notice in the same database transaction or persist an outbox record that a worker can deliver later. Use the event identifier, recipient, and notification type to tell a retry apart from a genuinely new comment. PostgreSQL transactions
The article-review workflow in DevShareHub's repository illustrates that distinction. Submission records and inbox rows share a transaction, while the WebSocket signal follows the commit. The same pattern fits social actions when a user should still find a notice after reconnecting. A queue is useful for email, push, and longer retry schedules. NestJS documents BullMQ as a Redis-backed queue integration, so its durability and retry behavior depend on the queue and Redis configuration you actually run. NestJS queue documentation
Worked example
This service-level sketch assumes authenticated IDs and a queue helper. A reply to the article author produces one notification, and the actor is excluded. Persist the comment before optional notification delivery.
tsconst recipients = new Set([articleAuthorId, repliedToUserId]); recipients.delete(actorId); for (const recipientId of recipients) { if (recipientId) await enqueueNotification({ recipientId, commentId }); }




Community
Discussion
Loading comments…