Tuesday, February 4, 2025     Bojan Arsenovic     Web Development

Featured Photo

In today's digital world, an effective notification system is crucial for businesses and applications that need to engage users, provide updates, and maintain real-time communication. Whether it's transactional messages, promotional emails, or urgent security alerts, a robust notification system ensures timely delivery across different channels—Email, SMS, and Push Notifications.

Building such a system from scratch presents several challenges, such as handling multiple channels, ensuring reliability, managing failures, and integrating with third-party providers. This post explores:

  • What makes a notification system robust
  • How to integrate external services for Email (Gmail/SendGrid), SMS (EZ Texting), and Push (Firebase)
  • A high-level design in .NET 9 using Clean Architecture and SOLID principles

By the end, you'll understand how to build a scalable and maintainable notification system in C# and .NET 9.

What Makes a Robust Notification System?

A modern notification system must be scalable, reliable, and multi-channel. Here are the key elements:

1. Multi-Channel Support

  • Email (Gmail, SendGrid, AWS SES)
  • SMS (EZ Texting, Twilio, Nexmo)
  • Push Notifications (Firebase, OneSignal)

2. Reliability & Failure Handling

  • Implement retry mechanisms for failed messages.
  • Use message queues (e.g., RabbitMQ, Azure Service Bus) for async processing.

3. Prioritization & User Preferences

  • Users should choose preferred channels (Email, SMS, or Push).
  • Critical notifications (e.g., password reset) should be delivered immediately.

4. Logging & Monitoring

  • Track sent notifications for debugging and compliance.
  • Implement audit trails for troubleshooting failed messages.

5. Scalability

  • Handle thousands of notifications without performance degradation.
  • Use distributed architectures (e.g., microservices) for large-scale applications.

Integrating with External Providers

Instead of building an entire notification infrastructure, we can leverage industry-standard providers:

1. Email Notifications (Gmail/SendGrid)

  • Emails are commonly used for account verifications, newsletters, and transactional alerts.
  • We'll use Gmail SMTP for sending emails in .NET 9.

2. SMS Notifications (EZ Texting)

  • SMS provides instant communication, useful for alerts and authentication.
  • We'll integrate EZ Texting API to send SMS messages.

3. Push Notifications (Firebase)

  • Push notifications are cost-effective for mobile and web applications.
  • We'll use Firebase Cloud Messaging (FCM) to send push notifications.

High-Level Design of the Notification System

Architecture Overview

We'll follow Clean Architecture to structure the notification system. Here's a simplified layered architecture:


+----------------------+
|    Presentation     |  --> Controllers or Background Services
+----------------------+
|    Application      |  --> Use Cases (Send Notification)
+----------------------+
|       Domain       |  --> Entities (Notification, NotificationType)
+----------------------+
|   Infrastructure   |  --> External Integrations (Gmail, SMS, Firebase)
+----------------------+
	

Core Components

  1. Domain LayerNotification entity & NotificationType
  2. Application LayerSendNotificationUseCase
  3. Infrastructure Layer — Email, SMS, and Push integrations
  4. Presentation Layer — API controllers or background workers

Implementing a Notification System in .NET 9

Now, let's look at the code implementation in C# and .NET 9.

1. Define the Notification Entity (Domain Layer)


public enum NotificationType
{
    Email,
    SMS,
    Push
}

public class Notification
{
    public Guid Id { get; set; }
    public string Recipient { get; set; }
    public string Message { get; set; }
    public NotificationType Type { get; set; }
    public DateTime SentAt { get; set; }
}
	

2. Implementing Use Case (Application Layer)


public class SendNotificationUseCase
{
    private readonly IEmailService _emailService;
    private readonly ISmsService _smsService;
    private readonly IPushNotificationService _pushNotificationService;

    public SendNotificationUseCase(
        IEmailService emailService, 
        ISmsService smsService, 
        IPushNotificationService pushNotificationService)
    {
        _emailService = emailService;
        _smsService = smsService;
        _pushNotificationService = pushNotificationService;
    }

    public async Task SendNotificationAsync(Notification notification)
    {
        switch (notification.Type)
        {
            case NotificationType.Email:
                await _emailService.SendEmailAsync(notification.Recipient, notification.Message);
                break;
            case NotificationType.SMS:
                await _smsService.SendSmsAsync(notification.Recipient, notification.Message);
                break;
            case NotificationType.Push:
                await _pushNotificationService.SendPushNotificationAsync(notification.Recipient, notification.Message);
                break;
        }
    }
}
	

3. Implementing External Provider Integrations (Infrastructure Layer)

Email (Gmail SMTP Integration)

public class GmailEmailService : IEmailService
{
    private readonly SmtpClient _smtpClient;

    public GmailEmailService()
    {
        _smtpClient = new SmtpClient("smtp.gmail.com")
        {
            Port = 587,
            Credentials = new NetworkCredential("your-email@gmail.com", "your-password"),
            EnableSsl = true
        };
    }

    public async Task SendEmailAsync(string recipient, string message)
    {
        var mailMessage = new MailMessage("your-email@gmail.com", recipient)
        {
            Subject = "Notification",
            Body = message
        };
        await _smtpClient.SendMailAsync(mailMessage);
    }
}

	
SMS (EZ Texting API Integration)

public class EzTextingSmsService : ISmsService
{
    private readonly HttpClient _httpClient;

    public EzTextingSmsService(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    public async Task SendSmsAsync(string recipient, string message)
    {
        var payload = new { phoneNumber = recipient, message = message };
        await _httpClient.PostAsJsonAsync("https://app.eztexting.com/api/send", payload);
    }
}

	
Push Notifications (Firebase Cloud Messaging - FCM)

public class FirebasePushService : IPushNotificationService
{
    private readonly FirebaseMessaging _firebaseMessaging;

    public FirebasePushService(FirebaseMessaging firebaseMessaging)
    {
        _firebaseMessaging = firebaseMessaging;
    }

    public async Task SendPushNotificationAsync(string recipient, string message)
    {
        var notification = new Message
        {
            Token = recipient,
            Notification = new Notification
            {
                Title = "New Notification",
                Body = message
            }
        };

        await _firebaseMessaging.SendAsync(notification);
    }
}
	

Conclusion

A robust notification system is essential for user engagement, real-time alerts, and seamless communication. By using .NET 9 with Clean Architecture, you can:

  • Scale notifications across multiple channels (Email, SMS, Push)
  • Integrate with industry-leading providers (Gmail, EZ Texting, Firebase)
  • Ensure reliability, scalability, and extensibility

Need a Custom Notification System? Our team specializes in .NET 9, Clean Architecture, and scalable messaging solutions. Contact i2b Global today to discuss your project!


  Go Back



Google Rating

4.6      10 reviews


Photo of Sam Barb

Sam Barb
  February 08, 2025

Bob at i2b global has been fantastic to deal with. I've been using this firm since 1995 and they have never let me down. I believe they are to notch and always perform beyond our expectations. I would highly recommend Bob and his team to all my family and friends. GREAT WORK!!!

Photo of D R

D R
  July 20, 2023

We have been using I2B Global for over 5 years and for multiple business ventures, and we could not be more pleased with the service we have received. Bob and his team have been incredibly accommodating, supportive, and always share their wealth of experience. I could not recommend I2B Global more, Thanks for all your work.

Photo of Ramon P. Schuler

Ramon P. Schuler
  February 19, 2022

AMAZING COMPANY WITH FOLKS WHO CARE!! RPS

Photo of Ace Luxury

Ace Luxury
  August 22, 2021

To Bob, Bojan, and the I2B Global Team: Thank you so much for the outstanding work you have done for us so far. Your way of responding to our needs is truly a breath of fresh air in this fast paced era we live in. We continue to add more services your firm has to offer given how effective your site design and SEO has been. We look forward to continued growth along with you for years to come. Keep up the excellent work.

Photo of Grant McGuinty

Grant McGuinty
  March 19, 2021

As a neophyte in the software business I cannot express enough how happy I am to deal with Bob Gill at i2b Global Inc. The company is with me every step of the way. Kind, professional and very responsive are the best words to describe them. I look forward to grow with them in the future with my FinalDocx by Executor Choice distribution business.

View All Google Reviews


 Request a Quote