Prompt
How do I build event-driven integrations without constantly polling third-party APIs?
Latest observation
To avoid constant polling, aim for push-based or event-driven integration patterns. The right approach depends on whether the third-party system supports webhooks, event streams, or only pull APIs.
Best options
1) Use webhooks when available
If the provider can send you HTTP callbacks:
- Register a webhook URL
- Verify signatures / secrets
- Process events asynchronously
- Make handlers idempotent
- Queue work instead of doing heavy processing inline
Good for: SaaS tools, payments, CRMs, e-commerce platforms.
Example flow:
- Vendor sends
invoice.paid - Your webhook endpoint receives it
- You validate + enqueue a job
- Worker updates your system
2) Subscribe to event streams
Some platforms support:
- Kafka topics
- Pub/Sub
- SNS/SQS
- CloudEvents
- Server-Sent Events (less common)
You consume events from the stream instead of repeatedly querying the API.
Good for: High-volume or low-latency integrations.
3) Use change data capture or database events
If the “third party” is actually another system you control:
- Emit domain events from the source system
- Use CDC tools or outbox patterns
- Publish events to a broker
This avoids external polling and makes integrations more reliable.
4) If only polling exists, make it smarter
Sometimes you can’t eliminate polling, but you can reduce it:
- Poll only incremental changes using
updated_since/ cursors - Use ETags /
If-Modified-Since - Increase intervals dynamically when idle
- Poll per tenant/resource rather than globally
- Store checkpoints to avoid re-reading data
- Use backoff and jitter
A solid architecture
A common pattern is:
- Webhook/API ingress
- Validation and deduplication
- Message queue
- Async workers
- Retry + dead-letter queue
- State store for idempotency and checkpoints
This keeps your integration resilient even if the third party retries deliveries or sends events out of order.
Key design practices
Idempotency
Assume the same event may arrive multiple times.
Use event IDs or natural keys to prevent duplicate processing.
Ordering
Events may arrive out of order.
If ordering matters, reconcile using timestamps or version numbers.
Retry handling
Expect timeouts and transient failures.
Use exponential backoff and dead-letter queues.
Security
Protect webhook endpoints with:
- HMAC signatures
- Shared secrets
- IP allowlists if appropriate
- Replay protection
Reconciliation
Even with events, run occasional audits to detect missed events or drift.
If the API has no webhooks
Your options are:
- Ask the vendor for webhook/event support
- Use their notification/email/export feeds if available
- Build a lightweight polling-to-events adapter
- Use browser automation or scraping only as a last resort
Rule of thumb
If you find yourself polling frequently for “something changed,” you probably want:
- a webhook,
- an event stream,
- or an outbox/CDC pattern.
If you want, I can sketch a reference architecture for a specific stack like AWS, Node.js, Python, or Kafka.