Notification & Utility Microservices

Five small services (Email, SMS, Gift Card, Auth, Weather) that pulled shared work out of the food delivery monolith at Sepand. ASP.NET 5, ServiceStack, Hangfire, gRPC and PostgreSQL.

Full Stack Developer · 2020 - 2023 · Food Delivery

Tech: ASP.NET 5, ServiceStack, EF Core 5, OrmLite, Hangfire, gRPC, PostgreSQL, CI/CD, Unit Testing, Integration Testing, REST API

The problem

Email, SMS and gift card logic was duplicated across teams and tied to the main application, which made it hard to scale and risky to change. The new services had to deploy on their own, and a slow SMS provider could not be allowed to block order processing.

The approach

Each service is ASP.NET 5 with ServiceStack and OrmLite on PostgreSQL. REST faces callers, gRPC is used between services, and Hangfire sends email and SMS in the background with retries. Every service has its own CI/CD pipeline with unit and integration tests.

Outcomes

  • Five services that deploy and scale independently
  • 90%+ code coverage from unit and integration tests
  • Automated CI/CD per service, so release schedules are no longer tied together

What it is

Five services (Email, SMS, Gift Card, Auth and Weather) that provide shared functions to the wider food delivery platform at Sepand. Each one deploys on its own. The point was to take cross-cutting work out of the monolith and put it into small services that can scale separately.

Why we split them out

As the platform grew, things like sending email and SMS or issuing gift cards were being duplicated across teams and were tightly coupled to the main application. That made the system hard to scale and risky to change. The new services had to be:

  • deployable and scalable on their own
  • resilient, so a slow SMS provider can't block order processing
  • well tested, with high coverage and automated delivery

Architecture

flowchart TB
  GW[API Gateway / Edge]
  subgraph Services[ASP.NET 5 + ServiceStack]
    AUTH[Auth Service]
    EMAIL[Email Service]
    SMS[SMS Service]
    GIFT[Gift Card Service]
    WEA[Weather Service]
  end
  HF[Hangfire Workers]
  DB[(PostgreSQL)]
  EXT[External Providers<br/>SMTP / SMS / Weather API]

  GW -->|REST| AUTH
  GW -->|REST| EMAIL
  GW -->|REST| SMS
  GW -->|REST| GIFT
  GW -->|REST| WEA
  AUTH <-->|gRPC| EMAIL
  AUTH <-->|gRPC| SMS
  EMAIL --> HF
  SMS --> HF
  HF --> EXT
  EMAIL --> DB
  SMS --> DB
  GIFT --> DB
  AUTH --> DB

How they're built

  • Framework: ASP.NET 5 with ServiceStack for typed service contracts, and OrmLite as a light data-access layer on PostgreSQL.
  • Sync and async: REST for external and synchronous calls, gRPC for fast service-to-service calls, and Hangfire for background delivery of email and SMS with automatic retries.
  • Resilience: outbound messages are queued as Hangfire jobs, so a slow provider only delays delivery. The caller doesn't fail.
  • Quality: unit and integration tests aiming for 90%+ coverage, all run in a CI/CD pipeline that builds, tests and deploys each service separately.

Sending a notification

The caller gets a 202 straight away. Delivery and retries happen in Hangfire.

sequenceDiagram
  participant Caller as Platform Service
  participant Email as Email Service
  participant HF as Hangfire
  participant SMTP as SMTP Provider

  Caller->>Email: POST /send (gRPC/REST)
  Email->>HF: Enqueue send job
  Email-->>Caller: 202 Accepted (queued)
  HF->>SMTP: Deliver email
  alt provider fails
    SMTP-->>HF: error
    HF->>HF: Retry with backoff
  else success
    SMTP-->>HF: 250 OK
  end

CI/CD pipeline

flowchart LR
  G[Git push] --> B[Build]
  B --> U[Unit tests]
  U --> I[Integration tests]
  I --> P[Package]
  P --> D[Deploy service]

Problems and fixes

  • Flaky providers. Every third-party call runs inside a Hangfire job with exponential backoff, so transient failures recover on their own.
  • Contracts drifting between services. Typed ServiceStack DTOs and gRPC contracts keep producers and consumers in sync at compile time.

Result

  • Five services that deploy and scale independently.
  • 90%+ code coverage, enforced by unit and integration tests.
  • Automated CI/CD per service, so teams can release on their own schedule.