## Why Event-Driven AI?
Instead of synchronous request-response, event-driven architectures process AI tasks asynchronously — enabling better scaling, reliability, and user experience.
### Synchronous vs. Event-Driven
Synchronous: ``` User → API → Wait 30s for AI → Response ``` Problems: Timeouts, blocked UI, wasted resources
Event-Driven: ``` User → API → Queue → Response "Processing..." ↓ Worker → AI API → Store Result ↓ Notify User (webhook/poll) ```
### Common Triggers
- User actions: File upload, form submission, message sent
- Scheduled: Daily report generation, batch analysis
- Data changes: New database record, file modified
- External events: Email received, payment processed, API callback
### Architecture Components
- Event source: Where events originate (UI, API, schedule)
- Event bus/queue: Buffer and route events (Redis, SQS, Kafka)
- Workers: Process events and call AI APIs
- Storage: Store results (database, file storage)
- Notification: Inform clients of completion (webhooks, WebSocket, polling)
### Example: Content Moderation Pipeline
``` Image Upload → Queue → Moderation Worker → { if (safe) → Store & Display if (flagged) → Review Queue → Human Review if (rejected) → Notify User & Delete } ```