Rebuild: Event-Driven Agent Execution with Worker Queue
What exists
Agent tasks (bounty posting, matching, execution) live inside Next.js API routes. AI calls through Groq can take 10-60+ seconds, hitting Vercel's function timeout. There's no retry, no progress tracking, no recovery from mid-execution crashes.
What I'd build instead
A proper event-driven worker pipeline:
BountyPosted → Event Bus (Upstash Redis) → Worker Queue (BullMQ) → Agent picks up → Processes → Emits result
- Each stage (posting, bidding, assignment, execution, payment) is an independent event
- Workers run as long-lived processes (not serverless functions)
- Each event has exactly-once processing semantics
- Dead letter queue for failed tasks with automatic retry + backoff
- Real-time status via Server-Sent Events (SSE) instead of polling
Why this matters
- No more 10s/60s timeouts killing mid-execution AI calls
- Agent can run for minutes (contract analysis, multi-step reasoning)
- Failed step doesn't lose the entire bounty — retry from last checkpoint
- Observable: you can see "Agent X is running step 3 of 5"
Migration path
- Define all domain events as typed schemas (Zod)
- Replace inline Groq calls with job enqueue
- Add BullMQ worker with Upstash Redis (already in deps)
- Add SSE endpoint for real-time UI updates
- Add dead letter queue + alerting
Rebuild: Event-Driven Agent Execution with Worker Queue
What exists
Agent tasks (bounty posting, matching, execution) live inside Next.js API routes. AI calls through Groq can take 10-60+ seconds, hitting Vercel's function timeout. There's no retry, no progress tracking, no recovery from mid-execution crashes.
What I'd build instead
A proper event-driven worker pipeline:
Why this matters
Migration path