Skip to main content
This guide covers best practices for building AdCP orchestrators that handle asynchronous operations, pending states, and human-in-the-loop workflows.

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
DON’T:
  • 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:

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:
  1. Asynchronous design throughout
  2. Proper state management with persistence
  3. Graceful handling of pending states
  4. User communication for long-running operations
  5. Monitoring and observability
Remember: Pending states are not errors - they’re a normal part of the advertising workflow.

Next Steps

  • Task Lifecycle: See Task Lifecycle for status handling
  • Webhooks: See Webhooks for push notifications
  • Security: See Security for multi-tenant security