gitlabEdit

โšกAsync Flow

Learn how to implement asynchronous dispatch workflows with webhooks for scalable, production-ready integrations.

Overview

Async mode enables:

  1. Immediate response - API returns instantly with dispatch ID

  2. Background processing - Request processed asynchronously

  3. Webhook notification - Results sent to your callback URL

  4. Better scalability - Handle high volumes without blocking

  5. Fault tolerance - Automatic retries and error recovery

This recipe shows complete webhook implementations in 4 languages (Node.js, PHP, Java, and testing with curl).

What You'll Learn

  • When to use async vs sync mode

  • How to enable async dispatch

  • Implementing webhook handlers

  • Webhook security and verification

  • Handling retries and idempotency

  • Complete working examples

Prerequisites

  • Docs-Dispatcher account with email and password

  • HTTPS webhook endpoint (required)

  • Provider configured

  • Template created

  • Basic understanding of webhooks

circle-exclamation

When to Use Async Mode

Use Async When:

Scenario
Why Async

Long-running operations

Operations taking > 30 seconds

High volume

Processing hundreds/thousands of requests

Background jobs

Batch processing, scheduled tasks

Non-interactive

No user waiting for immediate result

Better UX

Don't block UI while processing

Resilience

Automatic retries on failures

Use Sync When:

Scenario
Why Sync

Quick operations

Expected completion < 10 seconds

Interactive workflows

User waiting for result

Simple error handling

Immediate error feedback needed

Testing/development

Easier debugging

Low volume

Few requests per minute

Async vs Sync Comparison

Aspect
Sync Mode
Async Mode

Response Time

2-30 seconds

< 200ms

Timeout

120 seconds

No timeout

Result

Immediate in response

Via webhook

Scalability

Limited

High

User Experience

Blocks until complete

Instant acknowledgment

Error Handling

Immediate

Via webhook

Use Case

Interactive

Background/Batch

Step 1: Authentication

Dispatcher API uses HTTP Basic Authentication. You'll need your Dispatcher account email and password for all API calls.

Setup Credentials

circle-info

No token management needed! Unlike JWT-based APIs, Basic Auth doesn't require separate authentication endpoints or token refresh. Your credentials are sent with each request.

Quick links:

Step 2: Enable Async Mode

Add ?async=true query parameter to the endpoint URL:

Sync Mode (Default)

Async Mode

Async Request Example

Immediate Async Response

Key fields:

  • dispatchId - Track this ID for status

  • status - Always "queued" initially

  • queuedAt - When queued

  • estimatedCompletionTime - Expected completion (estimate)

Step 3: Implement Webhook Handler

Your webhook endpoint must:

  1. โœ… Be accessible via HTTPS

  2. โœ… Return 200 OK within 10 seconds

  3. โœ… Handle duplicate events (idempotency)

  4. โœ… Process async (don't block response)

  5. โœ… Verify webhook signatures (recommended)

Webhook Payload Structure

Success Webhook:

Failure Webhook:

Complete Webhook Implementations

Node.js Webhook Handler

PHP Webhook Handler

Java Webhook Handler (Spring Boot)

Webhook Security

1. Verify Signatures

Always verify webhook signatures to prevent spoofed requests:

2. Use HTTPS Only

3. Implement Rate Limiting

Idempotency

Handle duplicate webhooks gracefully:

Testing Webhooks

Test with ngrok

Manual Webhook Testing

Retry Logic

Implement exponential backoff for failed webhooks:

Next Steps

Core Concepts

Summary

You've learned:

  • โœ… When to use async vs sync mode

  • โœ… How to enable async dispatch

  • โœ… Implementing secure webhook handlers

  • โœ… Handling idempotency and retries

  • โœ… Complete implementations in Node.js, PHP, Java

  • โœ… Testing and debugging webhooks

Async mode with webhooks is essential for production scalability!

Last updated