Webhooks vs Polling for Long File Conversions

Most file conversions finish in a few seconds, and for those the simplest design wins: send the file, wait, get the result in the same response. But a 300-slide presentation or a large scanned document can take long enough to collide with the timeouts sitting between you and the API. At that point you switch to an async job, and you face the real question: do you keep asking whether it is done, or do you wait to be told?

When one request is no longer enough

A synchronous conversion holds an HTTP connection open for the whole conversion. That is fine until something in the path decides the connection has been idle for too long. Load balancers, API gateways, CDNs and serverless platforms all have limits, typically somewhere between 30 seconds and a few minutes, and they cut the connection whether or not the conversion is still running.

Async jobs remove the problem. You submit the file and get a 202 with a job id back immediately, the conversion runs on its own, and you collect the result when it is ready. On PrivConvert every tool that works synchronously also works as a job, with the same parameters and the same credit cost. Jobs also absorb short bursts: a submitted job waits out a moment of high load and retries internally, where a synchronous call would have received a 503.

Polling: simple and works anywhere

Polling means asking GET /api/jobs/{id} until the status changes from processing to finished or failed. With the official client it is one call:

from privconvert import PrivConvert

pc = PrivConvert()

job = pc.submit_job("pptx-to-pdf", "deck.pptx")
result = pc.wait(job)  # polls with backoff, downloads, then deletes the stored result
result.save("deck.pdf")

Polling is the right choice when:

  • The code is a script, a CLI, a cron job or a worker that is waiting anyway.
  • The machine has no public address: a laptop, a private network, a CI runner.
  • You want the fewest moving parts. There is no endpoint to expose, secure or monitor.

The cost is wasted requests, and the fix is backoff. Most jobs finish in seconds, so check early and then slow down. The clients start at two seconds and stretch the gap by half each time up to ten seconds, which catches quick jobs fast without turning a long one into hundreds of requests. A status check uses no conversion credit.

Webhooks: no waiting, more responsibility

With a webhook you pass a webhook_url when submitting, and PrivConvert sends a signed POST to that URL when the job finishes or fails. Nothing on your side has to wait, which suits web apps, queues and anything event-driven.

In exchange, your endpoint has to do four things properly:

  1. Be publicly reachable over HTTPS on port 443. Private and internal addresses are refused when you submit the job.
  2. Verify the signature. Anyone can send a POST to a public URL. The X-PrivConvert-Signature header is an HMAC over the raw body, keyed from the job key that only you hold, with a timestamp to stop replays.
  3. Deduplicate. Deliveries are retried, so the same event can arrive twice. Every retry carries the same event_id: record it and skip repeats.
  4. Answer fast. Any 2xx acknowledges the delivery. Download and process the result in a background task, not inside the request.

Submitting a job with a webhook, keeping the job key:

job = pc.submit_job(
    "pptx-to-pdf",
    upload_bytes,
    filename="deck.pptx",
    webhook_url="https://app.example.com/hooks/privconvert",
)
# job.key is returned exactly once. Store it: you need it to verify
# the webhook and to download the result.
db.save_job(id=job.id, key=job.key, submitted_at=now())

The receiving endpoint, with verification, deduplication and the real work moved to a queue:

from flask import Flask, abort, request
from privconvert import Job, PrivConvert, verify_webhook

app = Flask(__name__)
pc = PrivConvert()

@app.post("/hooks/privconvert")
def privconvert_hook():
    event = request.get_json()
    row = db.get_job(event["id"])
    if row is None:
        abort(404)
    # Verify against the raw bytes, not the parsed JSON.
    if not verify_webhook(row.key, request.headers.get("X-PrivConvert-Signature"), request.get_data()):
        abort(400)
    if db.seen_event(event["event_id"]):
        return "", 200  # duplicate delivery, already handled
    queue.enqueue(handle_job_event, event)  # answer fast, work later
    return "", 200

def handle_job_event(event):
    row = db.get_job(event["id"])
    if row.done:
        return  # the webhook and the sweep can both arrive here
    if event["event"] == "job.finished":
        result = pc.download_job(Job(id=row.id, key=row.key, status="finished"))
        storage.put(row.id + ".pdf", result.content)
        pc.delete_job(row.id)
        db.mark_done(row.id)
    else:
        db.mark_failed(row.id, event["error"]["code"])  # also sets done

The payload never contains the file or the job key. Downloading still requires your API key and the job key, sent in an X-Job-Key header, so a webhook body that ends up in a log file gives nobody access to the result. The webhooks guide has the same endpoint for Node.js and Express.

The production answer: both

Webhooks fail in boring ways. You deploy at the wrong second, a firewall rule changes, your endpoint returns a 500 for a minute. PrivConvert retries up to 4 times over roughly 45 seconds, and after that it stops. The job itself is not affected: a finished result stays available for 30 minutes. So the robust design is a webhook for speed plus a small polling sweep for anything the webhook missed:

# Runs every 2 minutes from cron or your scheduler.
for row in db.jobs_not_done_older_than(minutes=3):
    status = pc.get_job(row.id)
    if status.status in ("finished", "failed"):
        handle_job_event({"id": row.id, "event": "job." + status.status, **status.raw})

Because the handler skips jobs that are already done, it does not matter whether the webhook or the sweep gets there first. Run the sweep well inside the 30-minute window, every few minutes is plenty, and it costs almost nothing when webhooks are healthy, because there is nothing pending to check.

Details that bite in production

  • The job key is shown once. It is returned only in the submit response and we store just a hash of it. Lose it and the result cannot be downloaded or decrypted, by you or by us.
  • Results do not wait forever. A finished result is kept for 30 minutes, then GET answers 410. Delete it as soon as you have it; the clients' wait() does this for you.
  • A 404 on a job you did not delete means resubmit. Jobs are held in memory only, so a job that was still running during a service restart is gone rather than half-finished.
  • Up to 4 jobs run at once per account. For large runs, keep a pool of four in flight rather than submitting everything at once. Converting thousands of files covers sizing it.

Quick decision

SituationUse
Short files, interactive requestSynchronous conversion
Script, cron job, CI, no public addressAsync job with polling
Web app or queue-based systemWebhook plus a polling sweep
Thousands of filesJobs or batches, with a fixed pool of four

Converting Word files specifically? How to convert DOCX to PDF in Node.js and Python covers the synchronous side with full examples.

FAQ

Should I use webhooks or polling for an async API?

Polling is simpler and works anywhere, including scripts, cron jobs and machines with no public address. Webhooks avoid wasted status requests and react the moment a job finishes, but they need a public HTTPS endpoint, signature verification and deduplication. Production systems usually use a webhook with a polling sweep as the fallback.

How often should I poll a job status?

Start at about two seconds and back off to about ten. Most conversions finish in seconds, so a fast first check catches them, and backing off keeps long jobs from generating hundreds of requests. The official PrivConvert clients do exactly this in wait().

What if my webhook endpoint is down?

PrivConvert makes up to 4 delivery attempts over roughly 45 seconds. If all of them fail, the job itself is not affected: the result stays available for 30 minutes after it finishes, so a polling sweep can still collect it.

Can a webhook be delivered twice?

Yes. Retries resend the same body with the same event_id, and a delivery can succeed on your side even if the acknowledgement is lost. Record each event_id you process and acknowledge repeats without doing the work again.

Does the webhook contain the converted file?

No. The payload carries the job id, status, output metadata and a download path, never the file and never the job key. Downloading needs your API key plus the job key you stored, so a leaked webhook body is useless on its own.

Developer resources:
Async jobs Webhooks guide Plans & free trial