Prompt
building a backend that needs delivery logs and event tracking
Latest observation
Nov 12, 2026
OpenAI APIWeb search: off
Got it — if you're building a backend that needs delivery logs and event tracking, you’ll want to design for a few core concerns:
1. Define the events you care about
At minimum, delivery systems usually track events like:
queuedsentdeliveredopenedclickedfailedbounceddroppedunsubscribed
If this is for internal service-to-service delivery, you may also want:
attemptedretry_scheduledretry_exhaustedacknowledged
2. Use an event-driven model
A good pattern is:
- Delivery record = current state of the message/job
- Event log = append-only history of everything that happened
This gives you:
- auditability
- easier debugging
- replay capability
- analytics later
3. Suggested data model
deliveries
Stores the canonical state of a delivery.
{
"id": "deliv_123",
"recipient": "user@example.com",
"channel": "email",
"status": "sent",
"created_at": "2026-11-12T10:00:00Z",
"updated_at": "2026-11-12T10:01:15Z",
"provider_message_id": "abc-xyz-987",
"metadata": {
"template_id": "welcome_email",
"campaign_id": "cmp_42"
}
}
delivery_events
Append-only event table.
{
"id": "evt_001",
"delivery_id": "deliv_123",
"event_type": "delivered",
"timestamp": "2026-11-12T10:01:10Z",
"source": "provider_webhook",
"payload": {
"provider_status": "ok",
"latency_ms": 220
}
}
4. Recommended backend flow
When sending:
- Create delivery record with status
queued - Attempt send
- Write event
sent - Update delivery status
When provider webhook arrives:
- Verify signature
- Match provider ID to delivery
- Insert event row
- Update latest delivery status if needed
5. Important design choices
Idempotency
Webhooks and retries often duplicate events.
Store a unique key like:
provider_event_id- or
(delivery_id, event_type, timestamp_bucket)if needed
Ordering
Events may arrive out of order.
Do not rely only on arrival order; track:
occurred_atreceived_at
Retention
Event logs can grow quickly. Consider:
- archiving old events
- partitioning by date
- TTL for noisy debug logs
Searchability
Index:
delivery_idprovider_message_idevent_typetimestamprecipient
6. Tech stack options
Simple setup
- PostgreSQL
- REST API
- background worker
- webhook endpoint
Scalable setup
- PostgreSQL for source of truth
- Kafka/SQS/RabbitMQ for event ingestion
- object storage for raw webhook payloads
- analytics sink for reporting
7. Minimal API endpoints
POST /deliveries— create/send deliveryGET /deliveries/:id— fetch delivery stateGET /deliveries/:id/events— fetch event historyPOST /webhooks/provider— receive provider events
8. Questions to narrow the design
If you want, I can help you design this more specifically. For example:
- Is this for email, SMS, push, or internal jobs?
- Do you need real-time tracking or just logs for auditing?
- Are you using SQL or NoSQL?
- Do you need high scale or just a straightforward backend?
If you answer those, I can propose a concrete schema and architecture.