Node.js › Email & Notifications

How would you design a multi-channel notification system in Node.js that can send the same logical notification via email, SMS, or push depending on user preference?

Advanced

Answer

A common approach defines a common Notification interface/abstraction and separate channel-specific adapters (EmailChannel, SmsChannel, PushChannel) each implementing a consistent send() method -- a central notification service looks up the user's preferred channel(s) and delegates to the appropriate adapter(s), letting new channels be added later without touching the calling code, and letting a single logical event (like 'order shipped') fan out to multiple channels if the user has enabled more than one.
class NotificationService {
  constructor(channels) { this.channels = channels; } // { email: EmailChannel, sms: SmsChannel }
  async notify(user, event) {
    const preferredChannels = user.notificationPreferences; // e.g., ['email', 'push']
    await Promise.allSettled(
      preferredChannels.map(ch => this.channels[ch].send(user, event))
    );
  }
}
Real-world example A logistics platform's notification service sends an 'order shipped' event through both email and SMS for customers who've opted into both channels, using Promise.allSettled so a failure in one channel (like an invalid phone number) doesn't prevent the email from still being sent.

Common follow-ups: How does this design apply the Strategy or Adapter pattern discussed earlier in Architecture & Design Patterns?;How would you track and avoid sending duplicate notifications for the same event across multiple channels?