Skip to main content

Notification Persistence and Repositories

Summary

Persistence is EF Core over PostgreSQL in the notification schema. Callers use NotificationDbContext directly; there is no repository or unit-of-work abstraction. The context intentionally applies no global tenant query filter.

Entities and tables

EntityTablePurpose (verified)
NotificationTemplateNotificationTemplatesVersioned per-tenant/global subject+body templates
NotificationRecipientNotificationRecipientsDirectory of resolved recipients
NotificationMessageNotificationMessagesOne rendered message per channel+recipient
NotificationDeliveryAttemptNotificationDeliveryAttemptsAppend-only per-attempt record
NotificationPreferenceNotificationPreferencesPer-recipient channel opt-outs
NotificationAuditLogNotificationAuditLogAppend-only stage audit trail
ProcessedIntegrationEventProcessedIntegrationEventsIdempotency ledger, unique on EventId

Key constraints and indexes

The model configures a unique index on (TenantId, TemplateKey, Channel, Version) for templates, a unique index on (TenantId, RecipientType, ExternalRef) for recipients, a unique preference scope index, a unique EventId on the idempotency ledger, and supporting indexes on message recipient/status, event id, correlation and audit occurrence. Length limits and a text column type for bodies are declared explicitly.

Access pattern

NotificationDispatcher, TemplateEngine, PreferenceEvaluator and the endpoints obtain NotificationDbContext via DI and issue LINQ directly. Writes call SaveChangesAsync; reads use AsNoTracking. The dispatcher persists incrementally (recipient, then each message, then attempts and audit) rather than in one transaction.

Design-time factory

NotificationDbContextFactory provides a design-time connection for dotnet ef migrations, defaulting to a local connection when the environment variable is absent.

Verified absence

There are no IRepository, INotificationRepository, generic repository, specification objects or unit-of-work types. The DbContext is the persistence abstraction.

Requires Confirmation

Production database sizing, retention policy for append-only tables and index adequacy under load require confirmation.

Source References

  • microservices/src/notification-service/Infrastructure/NotificationDbContext.cs
  • microservices/src/notification-service/Domain/NotificationEntities.cs
  • microservices/src/notification-service/Infrastructure/Migrations/NotificationDbContextModelSnapshot.cs

See Also

Keywords

Repositories, persistence, DbContext, entities, indexes, verified absence.

Revision Information

  • Status: Draft
  • Last reviewed: 2026-07-21
  • Next review: 2026-10-21