Polling vs Webhooks
Choose the right approach for receiving task results
Polling vs Webhooks
APIXO offers two ways to receive task results: polling (async mode) and webhooks (callback mode). This guide helps you choose the right approach and implement it effectively.
Quick Comparison
| Aspect | Polling (Async) | Webhooks (Callback) |
|---|---|---|
| Setup | Simple | Requires public endpoint |
| Real-time | Near real-time | Instant |
| API Calls | Multiple per task | One per task |
| Best For | Development, client apps | Production servers |
| Infrastructure | None | HTTPS endpoint |
When to Use Polling
Choose polling when:
- Building client-side applications
- Prototyping or testing
- You don't have a public server
- Processing low volume of tasks
Basic Polling Implementation
Exponential Backoff
For better efficiency, use exponential backoff:
Recommended Intervals by Model Type
| Model Type | Initial Wait | Poll Interval | Max Wait |
|---|---|---|---|
| Image (fast) | 5s | 3s | 2 min |
| Image (quality) | 10s | 5s | 3 min |
| Video | 60s | 15s | 10 min |
| Audio | 30s | 10s | 5 min |
When to Use Webhooks
Choose webhooks when:
- Running a production server
- Processing high volume of tasks
- Need real-time notifications
- Want to minimize API calls
Webhook Setup
1. Create an endpoint:
2. Submit task with callback:
Webhook Requirements
- Must be publicly accessible via HTTPS
- Must respond with HTTP 200 within 30 seconds
- Should handle duplicate deliveries (use
taskIdfor idempotency)
Retry Policy
If your webhook fails:
| Attempt | Delay |
|---|---|
| 1st retry | 30 seconds |
| 2nd retry | 2 minutes |
| 3rd retry | 10 minutes |
After 3 failed attempts, the webhook is abandoned. You can still query via the status endpoint.
Hybrid Approach
For maximum reliability, combine both approaches:
Local Development with ngrok
For testing webhooks locally:
Summary
| Scenario | Recommendation |
|---|---|
| Development / Testing | Polling |
| Client-side app | Polling |
| Production backend | Webhooks |
| High volume | Webhooks |
| Maximum reliability | Hybrid (webhooks + polling fallback) |
Start with polling for simplicity, then migrate to webhooks as your application scales.