Core Design Principles
1. Asynchronous First
The AdCP protocol is inherently asynchronous. Operations may take seconds, hours, or even days to complete. DO:- Design all operations as async/await
- Store operation state persistently
- Handle orchestrator restarts gracefully
- Implement proper timeout handling
- Assume immediate completion
- Use synchronous blocking calls
- Store state only in memory
- Retry indefinitely without backoff
2. Status-Driven Logic
Operations progress through standardized status values:3. State Machine Design
Implement proper state machines aligned with AdCP task statuses:Operation Tracking
Persistent Storage
Store all operations with comprehensive tracking:State Reconciliation
Sync local state with server on startup:Async Operation Handler
Response Routing
Handle responses based on status:Submitted Operations
Handle long-running operations:Polling with Backoff
Implement efficient polling:Webhook Support
Reliable Webhook Handler
Implement webhooks with reliability patterns:Webhook + Polling Backup
Never rely solely on webhooks:Example Orchestrator
Complete orchestrator implementation:Governance in the Campaign Lifecycle
Plan creation (sync_plans) happens during the planning phase — before any campaigns exist. Governance checks happen during campaign execution. These are separate concerns.
Planning phase (once per media plan):
See the media buy governance workflow for the complete sequence with code examples, and the seller integration guide for the seller’s execution check obligations.
Best Practices
1. Persistent Storage
Always use persistent storage for operation state:- Database (PostgreSQL, MongoDB)
- Message queue (Redis, RabbitMQ)
- Distributed cache (Redis Cluster)
2. Idempotency
Make all operations idempotent:3. Timeout Handling
Implement reasonable timeouts:4. Error Recovery
Implement retry logic with circuit breakers:5. Monitoring and Alerting
Track key metrics:- Pending operation count by type
- Average approval time
- Rejection rate
- Task timeout rate
- API error rate
User Communication
Keep users informed about pending operations:Summary
Building a robust AdCP orchestrator requires:- Asynchronous design throughout
- Proper state management with persistence
- Graceful handling of pending states
- User communication for long-running operations
- Monitoring and observability
Next Steps
- Task Lifecycle: See Task Lifecycle for status handling
- Webhooks: See Webhooks for push notifications
- Security: See Security for multi-tenant security