Multi-tenancy · Platform
A multi-tenant notification platform
A shared service for SMS, email, WhatsApp and push, where tenant isolation is enforced by PostgreSQL itself and new providers plug in without touching the core.
01 Problem
Messaging was spread across services, each with its own provider integration. Adding a channel or switching a provider meant changing several codebases, and there was no single place to enforce tenant boundaries, preferences or delivery tracking.
02 Constraints
- Multiple tenants share one database; a bug must not leak one tenant's messages to another.
- Providers differ by market and change over time.
- Message volume grows unbounded, so storage has to be partitioned from day one.
03 Architecture
- 01Kafka / APIProducts publish a notification request.
- 02PreferencesChannel selection driven by recipient preferences.
- 03Provider SPIAdapter chosen per tenant, channel and market.
- 04AdaptersAfrica's Talking, Mailgun, Twilio, WhatsApp, FCM, Infobip.
- 05PostgreSQL + RLSForced row-level security; partitioned delivery records.
04 Decisions
Row-level security, forced
- Chose
- PostgreSQL RLS policies with FORCE enabled, keyed on the tenant.
- Instead of
- Tenant filtering in application queries.
- Why
- The database refuses cross-tenant reads even if application code forgets a filter.
Provider SPI
- Chose
- A Provider / ProviderFactory interface with self-contained adapters.
- Instead of
- Provider-specific branches inside the delivery service.
- Why
- Adding or swapping a provider becomes a new adapter, not a change to core logic.
Partitioning up front
- Chose
- Partition delivery tables from the first migration.
- Instead of
- Add partitioning later when tables are large.
- Why
- Retrofitting partitions onto a hot, large table is far riskier than starting with them.
05 Implementation
- Wrote the requirements and technical specification and ADRs before implementation.
- Implemented six channel adapters behind the SPI.
- Verified RLS policies and partitioning against real PostgreSQL with Testcontainers.
06 Outcomes
- Tenant isolation is guaranteed by the database and verified by integration tests.
- New channels and providers are added as adapters without changes to the core engine.
Outcomes are limited to what I can verify and share. Internal names, partners, infrastructure details and production data are deliberately omitted.