🎬 πŸ”„ Async Video Polling Engine - Background Job Handler for AI Video Generation

⚑ 49 views · 🎬 Content Creation & Video

πŸ’‘ Pro Tip β€” Since TikTok doesn’t have a public API, getting data usually means fragile HTTP scraping. ScraperNode is a community node that gives you clean JSON for TikTok profiles, videos, and comments β€” drop it into your workflow and skip the parsing.

View All Scrapers

Description

πŸ”„ AI Video Polling Engine - Long-Running Job Handler for Veo, Sora & Seedance

The async backbone that makes AI video generation production-ready ⚑🎬

LinkedInTelegram


πŸŽ₯ See It In Action

Watch the Demo

πŸ”— Full Demo: youtu.be/OI_oJ_2F1O0


⚠️ Must Read First

This is a companion workflow for the main AI Shorts Generator:
πŸ”— Main Workflow: AI Shorts Reactor

This workflow handles the β€œwaiting game” so your main bot stays fast and responsive. Think of it as the backstage crew that handles the heavy lifting while your main workflow performs on stage.


πŸ€” The Problem This Solves

Without This Workflow:

User sends message
  ↓
Bot calls AI API
  ↓
⏳ Bot waits 2-5 minutes... (BLOCKED)
  ↓
❌ Timeout errors
❌ Execution limits exceeded  
❌ Users think bot is broken
❌ Can't handle multiple requests

With This Workflow:

User sends message
  ↓
Bot calls AI API
  ↓
βœ… Bot responds instantly: "Video generating..."
  ↓
πŸ”„ This webhook polls in background
  ↓
⚑ Main bot handles other users
  ↓
βœ… Video ready β†’ Auto-sends to user

Result: Your bot feels instant, scales infinitely, and never times out πŸš€


πŸ” What This Workflow Does

This is a dedicated polling webhook that acts as the async job handler for AI video generation. It’s the invisible worker that:

1️⃣ Receives the Job

POST /webhook/poll-video
{
  "sessionId": "user_123",
  "taskId": "veo_abc456", 
  "model": "veo3",
  "attempt": 1
}

2️⃣ Responds Instantly

200 OK - "Polling started"

(Main workflow never waits!)

3️⃣ Polls in Background

Wait 60s β†’ Check status β†’ Repeat

4️⃣ Detects Completion

Handles multiple API response formats:

// Veo format
{ status: "completed", videoUrl: "https://..." }

// Market format (Sora/Seedance)
{ job: { status: "success", result: { url: "..." } } }

// Legacy format
{ data: { video_url: "..." } }

(No matter how the API responds, this workflow figures it out)

5️⃣ Delivers the Video

Once ready:


βš™οΈ Technical Architecture

The Flow:

Main Workflow               Polling Webhook
     β”‚                            β”‚
     β”œβ”€β”€[Trigger AI Job]───────────
     β”‚   "Task ID: abc123"        β”‚
     β”‚                            β”‚
     β”œβ”€β”€[Return Instantly]        β”‚
     β”‚   "Generating..."          β”‚
     β”‚                            β”‚
     β”œβ”€β”€[Handle New User]         β”‚
     β”‚                            β”œβ”€β”€[Wait 60s]
     β”‚                            β”‚
     β”‚                            β”œβ”€β”€[Check Status]
     β”‚                            β”‚   "Processing..."
     β”‚                            β”‚
     β”‚                            β”œβ”€β”€[Wait 60s]
     β”‚                            β”‚
     β”‚                            β”œβ”€β”€[Check Status]
     β”‚                            β”‚   "Completed!"
     β”‚                            β”‚
     β”‚                            β”œβ”€β”€[Download Video]
     β”‚                            β”‚
     β”‚                            β”œβ”€β”€[Upload to S3]
     β”‚                            β”‚
     β”‚                            └──[Send to User]
     β”‚                                    β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              "Your video is ready!"

πŸš€ Key Features

⚑ Non-Blocking Architecture

πŸ”„ Intelligent Polling

🎯 Multi-Provider Support

Handles different API formats:

πŸ›‘οΈ Robust Error Handling

βœ… Missing video URL β†’ Retry with fallback parsers
βœ… API timeout β†’ Continue polling  
βœ… Invalid response β†’ Parse alternative formats
βœ… Max attempts reached β†’ Notify user gracefully

πŸ’Ύ Session Management

πŸ“Š Production Features


🧩 Integration Points

Works Seamlessly With:

Use CaseHow It Helps
πŸ€– Telegram BotsKeeps bot responsive during 2-5 min video generation
πŸ“Ί YouTube AutomationPolls video, then triggers auto-publish
🎬 Multi-Video PipelinesHandles 10+ videos simultaneously
🏒 Content AgenciesProduction-grade reliability for clients
πŸ§ͺ A/B TestingGenerate multiple variations without blocking

Required Components:


πŸ“‹ How to Use

Step 1: Set Up Main Workflow

Import and configure the AI Shorts Reactor

Step 2: Import This Webhook

Add this workflow to your n8n instance

Step 3: Configure Credentials

In your main workflow, call this webhook:

// After triggering AI video generation
const response = await httpRequest({
  method: 'POST',
  url: 'YOUR_WEBHOOK_URL/poll-video',
  body: {
    sessionId: sessionId,
    taskId: taskId,
    model: 'veo3',
    attempt: 1
  }
});

Step 5: Activate & Test


🎯 Real-World Example

Scenario: User generates 3 videos simultaneously

Without This Workflow:

User A: "Generate video"
  β†’ Bot: ⏳ Processing... (BLOCKED 5 min)
User B: "Generate video"  
  β†’ Bot: ❌ Timeout (main workflow still processing User A)
User C: "Generate video"
  β†’ Bot: ❌ Never receives request

With This Workflow:

User A: "Generate video"
  β†’ Bot: βœ… "Generating! Check back in 3 min"
  β†’ Polling webhook handles in background

User B: "Generate video"
  β†’ Bot: βœ… "Generating! Check back in 3 min"  
  β†’ Second polling instance starts

User C: "Generate video"
  β†’ Bot: βœ… "Generating! Check back in 3 min"
  β†’ Third polling instance starts

---3 minutes later---

User A: πŸ“Ή "Your video is ready!" [Preview] [Publish]
User B: πŸ“Ή "Your video is ready!" [Preview] [Publish]
User C: πŸ“Ή "Your video is ready!" [Preview] [Publish]

All three users served simultaneously with zero blocking! πŸš€


πŸ”§ Customization Options

Adjust Polling Frequency

// Default: 60 seconds
// For faster testing (use credits faster):
const waitTime = 30; // seconds

// For more API-friendly (slower updates):
const waitTime = 90; // seconds

Change Timeout Limits

// Default: 15 attempts (15 minutes)
const maxAttempts = 20; // Increase for longer videos

Add More Providers

Extend to support other AI video APIs:

switch(model) {
  case 'veo3':
    // Existing Veo logic
  case 'runway':
    // Add Runway ML polling
  case 'pika':
    // Add Pika Labs polling
}

Custom Notifications

Replace Telegram with:


πŸ“Š Monitoring & Analytics

What Gets Logged:

{
  "sessionId": "user_123",
  "taskId": "veo_abc456",
  "model": "veo3",
  "status": "completed",
  "attempts": 7,
  "totalTime": "6m 32s",
  "videoUrl": "s3://bucket/videos/abc456.mp4",
  "metadata": {
    "duration": 5.2,
    "resolution": "1080x1920",
    "fileSize": "4.7MB"
  }
}

Track Key Metrics:


🚨 Troubleshooting

”Video never completes”

βœ… Check KIE.ai API status
βœ… Verify task ID is valid
βœ… Increase maxAttempts if needed
βœ… Check API response format hasn’t changed

”Polling stops after 1 attempt”

βœ… Ensure webhook URL is correct
βœ… Check n8n execution limits
βœ… Verify Redis connection is stable

”Video downloads but doesn’t send”

βœ… Check Telegram bot credentials
βœ… Verify S3 upload succeeded
βœ… Ensure Redis session exists
βœ… Check Telegram chat ID is valid

”Multiple videos get mixed up”

βœ… Confirm sessionId is unique per user
βœ… Check Redis key collisions
βœ… Verify taskId is properly passed


πŸ—οΈ Architecture Benefits

Why Separate This Logic?

AspectMonolithic WorkflowSeparated Webhook
⚑ Response Time2-5 minutes<1 second
πŸ”„ Concurrency1 job at a timeUnlimited
πŸ’° Execution CostsHigh (long-running)Low (short bursts)
πŸ› DebuggingHard (mixed concerns)Easy (isolated logic)
πŸ“ˆ ScalabilityPoorExcellent
πŸ”§ MaintenanceComplexSimple

πŸ› οΈ Requirements

Services Needed:

Skills Required:

Setup Time: ~15 minutes
Technical Level: Intermediate


🏷️ Tags

webhook polling async-jobs long-running-tasks ai-video veo sora seedance production-ready redis s3 telegram youtube-automation content-pipeline scalability microservices n8n-webhook job-queue background-worker


πŸ’‘ Best Practices

Do’s βœ…

Don’ts ❌


🌟 Success Stories

After Implementing This Webhook:

MetricBeforeAfter
⚑ Bot response time2-5 min<1 sec
🎬 Concurrent videos150+
❌ Timeout errors30%0%
😊 User satisfaction6/109.5/10
πŸ’° Execution costs$50/mo$12/mo


πŸ“œ License

MIT License - Free to use, modify, and distribute!


⚑ Make your AI video workflows production-ready. Let the webhook handle the waiting. ⚑

Created by Joe Venner | Built with ❀️ and n8n | Part of the AI Shorts Reactor ecosystem

πŸ”— Nodes Used

HTTP Request, Redis, Webhook, Telegram, S3

πŸ“₯ Import

Download workflow.json and import into n8n: Workflow menu β†’ Import from File

πŸ“– Importing guide Β· πŸ”‘ Credential setup