Home/Case Studies/Building a Developer-First Email Platform on Cloudflare's Edge
Cloud SolutionsSaaS / Developer Tools

Building a Developer-First Email Platform on Cloudflare's Edge

Tired of wiring up the same email infrastructure for every project, we built PushMail — an API-first email platform on Cloudflare Workers that handles transactional, sequence, and campaign email through one REST API, one account, and pay-per-send pricing.

10+
Cloudflare Products
$0.003
Per-Email Cost
Zero
Cold Starts
None
Origin Servers

Overview

Every new project we built needed the same thing: transactional email for signups and password resets, drip sequences for onboarding, and campaign sends for announcements. Every time, we'd wire up SendGrid, build the same contact management logic, implement the same webhook handlers, and manage yet another account. When SendGrid eliminated their free tier, the cost of running email across a dozen side projects and client platforms became untenable. We didn't want separate ESP accounts for every project — we wanted one platform, one bill, and one API that worked everywhere.

So we built it. PushMail is an API-first email platform built entirely on Cloudflare's edge infrastructure. It handles transactional email, drip sequences, and marketing campaigns through a single REST API — with pay-per-email pricing, multi-site support from a single account, bring-your-own-key SendGrid integration, and AI-native tooling for modern development workflows.

The Challenges

Building an email platform that competes with established ESPs required solving several interconnected technical and product challenges simultaneously.

1

Reliable Email Delivery Without Vendor Lock-In

Email deliverability depends on IP reputation, domain authentication, and compliance with ISP throttling rules. Most platforms lock customers into their shared sending infrastructure, which means one bad actor can tank deliverability for everyone. The platform needed to support both a managed sending mode for simplicity and a bring-your-own-key mode for customers who want full control over their sending reputation — without duplicating the entire sending pipeline.

2

Unified Transactional and Marketing Email

Developers typically cobble together separate services for transactional email (password resets, receipts) and marketing email (newsletters, drip sequences). This creates fragmented contact data, inconsistent analytics, and double billing. The platform needed to handle all email types — single sends, multi-step sequences with delay scheduling, and bulk campaigns — through one API with one contact database and one billing model.

3

Edge-Native Architecture for Global Performance

Email API calls are latency-sensitive. A developer sending a transactional email during a user signup flow can't afford 500ms of API latency added to their response time. The platform needed to accept API requests at the edge, validate and enqueue them immediately, and process sends asynchronously — all without traditional server infrastructure that would inflate operating costs and create scaling bottlenecks.

4

Multi-Tenant Isolation at Scale

An email platform manages highly sensitive data: contact lists, email content, sending credentials, and engagement analytics. Multi-site support — where a single account manages email for multiple projects — demanded strict data isolation between sites, between organizations, and between API key scopes. A misconfigured query or leaked credential couldn't be allowed to cross tenant boundaries.

5

Sustainable Unit Economics

The pricing model needed to undercut per-subscriber billing (where ESPs charge for contacts that never receive email) while still covering infrastructure costs. Per-email pricing aligned incentives with customers but required precise cost tracking at the individual send level — including SendGrid API costs, validation overhead, template rendering, and storage for analytics data.

The Solution

We designed PushMail as a Cloudflare-native application from day one, leveraging Workers, D1, R2, KV, and Queues as integrated building blocks for a full email infrastructure platform.

1

Cloudflare Workers as the API and Application Layer

The entire platform runs on Cloudflare Workers via the OpenNext adapter, deploying a Next.js application to the edge without modification. The REST API, dashboard, documentation site, and marketing pages all run from the same Worker — no origin servers, no load balancers, no auto-scaling configuration. API requests are authenticated, validated, and routed at the nearest edge location, delivering consistent sub-50ms response times for API calls globally. The edge runtime also enforces rate limiting, CORS policies, and request validation before any business logic executes.

2

D1 for Relational Data with Drizzle ORM

All platform data lives in Cloudflare D1, a SQLite-based edge database. The 18-table schema — designed with Drizzle ORM for type-safe queries — covers organizations, users, API keys, sites, contacts, lists, tags, templates, sequences, campaigns, sends, and events. Because D1 is co-located with the Worker, database operations execute with sub-millisecond latency. Contact upserts, list membership changes, and event ingestion all happen at the edge without connection pooling overhead or VPC networking complexity.

3

Cloudflare Queues for Asynchronous Email Processing

Email sends are decoupled from API requests using Cloudflare Queues. When a developer calls the send endpoint, the API validates the request, confirms credit balance, and enqueues the send — returning a response in under 50ms. A separate queue consumer Worker picks up batches of up to 10 messages, renders email templates with variable substitution, calls the SendGrid API, stores the rendered HTML in R2 for later viewing, deducts credits, and updates send status in D1. A second queue handles CSV contact imports, processing uploads asynchronously with progress tracking. This architecture means API latency is independent of email rendering or delivery time.

4

Dual-Mode SendGrid Integration

The sending layer supports two modes through a single pipeline. In managed mode, PushMail routes email through its own SendGrid account — customers pay per-email pricing with sending costs baked in. In BYOK (bring-your-own-key) mode, customers provide their own SendGrid API key and manage their own IP reputation, domain authentication, and deliverability monitoring. Both modes share the same queue consumer, template engine, and event processing — the only difference is which credentials are used for the SendGrid API call. High-volume accounts (100k+ emails per month) automatically get dedicated SendGrid subusers provisioned with automated IP warmup schedules.

5

KV for Sessions, Caching, and Suppression

Cloudflare KV handles the platform's fast-access data layer. Session tokens are stored in KV with 7-day TTL for stateless authentication without database queries on every request. Global suppression lists (bounced addresses, complaint addresses) are cached in KV for instant lookup during send validation, preventing delivery to addresses that would harm sender reputation. Rate limit counters use KV's atomic operations to enforce per-organization and per-site sending limits without distributed locking.

6

R2 for Templates, Rendered Email, and Imports

Cloudflare R2 stores all binary and large-text data with a structured key hierarchy: templates, rendered email HTML (for "view in browser" links and audit trails), uploaded CSV files for contact imports, and email images. R2's S3-compatible API made integration straightforward, and zero-egress-fee pricing means serving rendered emails and template assets costs nothing beyond storage — critical for a platform where every sent email generates a stored copy.

7

Scheduled Workers for Sequence and Campaign Automation

A cron-triggered Worker runs every minute to advance the platform's automation engine. It evaluates drip sequence enrollments — checking delay conditions and triggering the next step for each enrolled contact. It processes scheduled campaigns by checking send windows and enqueuing bulk sends. It verifies domain authentication status (DKIM, SPF, DMARC) for newly configured domains. It calculates organization health metrics including bounce rates, complaint rates, and trust levels that determine sending limits. And it provisions SendGrid subusers for accounts that cross volume thresholds — all without any always-on infrastructure.

8

AI-Native Developer Experience with MCP Tools

PushMail ships with 15 Model Context Protocol (MCP) tools that integrate directly with AI development environments like Claude Code, GPT, and Cursor. Developers can manage contacts, create sequences, send campaigns, and monitor delivery — all through natural language in their IDE. This isn't a bolt-on integration; the MCP server uses the same REST API that powers the dashboard, ensuring feature parity between the visual interface and AI-assisted workflows.

The Results

The Cloudflare-native architecture delivered measurable advantages across performance, cost, and developer experience.

The

Zero Origin Servers, Zero Cold Starts

entire platform — API, dashboard, docs, marketing site, queue consumers, and cron jobs — runs without a single origin server. There are no EC2 instances to right-size, no Kubernetes clusters to manage, no database connections to pool. Workers execute in under 5ms cold start time, and D1 queries return in under 1ms. This means a developer in Tokyo gets the same API response time as a developer in Virginia.

Per-email

$0.003 Per Email at Launch Scale

pricing starts at $0.003 and decreases with volume — reaching $0.0005 per email above 1 million monthly sends. Because infrastructure costs are near-zero at low volume (Workers, D1, R2, and KV all have generous free tiers), the platform achieves positive unit economics from the first paid customer. There are no per-subscriber charges, no charges for bounced or unsubscribed contacts, and no minimum monthly commitments.

Developer

Five Steps to First Email

onboarding was reduced to five steps: sign up, create an API key, register a site, add a contact, and send an email. No sandbox environments, no IAM role configuration, no DNS propagation waits, no SDK installation. The API accepts plain JSON over REST — a single curl command sends an email. Combined with $5 in free credits on signup (no credit card required), developers can evaluate the platform end-to-end in under two minutes.

Transactional

Full Platform in a Single Codebase

email, drip sequences, marketing campaigns, contact management, template building, analytics, and billing all ship as one application deployed with a single command. This eliminated the integration complexity of stitching together separate services and reduced the operational surface area to one Worker deployment, one D1 database, one R2 bucket, two Queues, and one KV namespace. The entire infrastructure can be described in a single wrangler.toml file.

The

10+ Cloudflare Products in Production

platform leverages Workers, D1, R2, KV, Queues, Cron Triggers, Worker Static Assets, Custom Domains, and the OpenNext adapter — demonstrating that Cloudflare's developer platform can support complex, multi-service applications that would traditionally require a combination of AWS services. Each product handles a specific infrastructure concern, and all communicate through native bindings without network hops or serialization overhead.

Tags

Cloudflare WorkersD1R2KVQueuesEmail InfrastructureSaaSEdge ComputingSendGrid

Ready to Achieve Similar Results?

Let our team of experts help you solve your toughest challenges and achieve transformational results.