Nathaniel Redmon
Work

Pioneer Direct Mail API

Turning individual API submissions into organized mailing batches that a warehouse can process.

Started April 2025 · Developer

Pioneer's public API documentation showing the send-record endpoint, authentication, idempotency header, and example JSON request
The public integration documentation, with an example request and the requirements for safe retries.

Connecting software to physical fulfillment

A mailing system needs more than an endpoint that accepts a name and address. Integrations send records at different speeds, retry requests, and need to know which batch their data belongs to. The warehouse needs a consistent file and a clear record of what has been handed off.

I built an Express API with separate intake and processing paths. A request is authenticated, checked for a previous submission, and assigned to a batch. Background workers turn completed batches into CSV files, upload them to S3, and record the output in MongoDB. Clients can query processed upload summaries by batch instead of treating an accepted request as a completed mailing.

Technical details

API
Node.js and Express 5; JSON record intake and batch-status endpoints
Fast storage
Redis through ioredis for short batches, request deduplication, and authentication caching
Persistence
MongoDB and Mongoose for scheduled batches, records, and processed uploads
Workers
Separate batch processor and API-key synchronization worker
Delivery
Papa Parse CSV generation, AWS S3 storage, signed download URLs, and Amazon SES notifications
Integration
OpenAPI specification and public Redocly documentation

Two ways to close a batch

Short batches collect related records in Redis. Each incoming record renews the activity window, so a burst of submissions can become one export after the integration goes quiet. This supports integrations that send records one at a time without requiring a separate request to close the batch.

Longer batches persist their records and scheduled processing time in MongoDB. The worker checks for due batches and claims work before processing it. The current scheduling policy limits how much work runs at once and holds overdue batches outside the automatic age window for review, rather than releasing a backlog of stale mail after a restart.

Handling retries and authentication

The send endpoint requires an idempotency key scoped to the authenticated user. Redis atomically reserves that key while the request is running. A concurrent duplicate receives a conflict response; a completed retry can receive the stored result. That gives integrations a defined retry path when a connection drops after a submission.

API-key verification uses bcrypt, with cached results to avoid repeating the expensive comparison on every request. Cached authorization still checks the current active-key set, so caching does not keep a revoked key usable. If the dependency needed to verify access or request identity is unavailable, the API returns an error rather than accepting an unchecked record.

Making the handoff traceable

The export path flattens nested record fields, collects a consistent set of CSV columns, and stores the file in S3. A corresponding upload record keeps the batch identifier, owner, record count, file location, and processing status together. Signed download links and email notifications support the operational handoff.

The important boundary is between accepting data and producing a usable batch. The API contract, worker state, and upload records make those stages explicit.