A Report Export That Outlasts the Lunch Break
Your team is building a report export. A customer uploads a long document, asks for a detailed analysis, and clicks Generate. The AI work takes four minutes. Keeping the browser waiting on one request makes the feature fragile: a connection can drop even while the work continues.
A background job gives that work its own identity. Your application accepts the request, creates a job, and returns a job ID quickly. The customer can leave the page and return later. Polling and webhooks are two ways to discover when that job finishes.
The job ID connects the request to its result
Think of the job ID as a collection receipt. It lets your application ask about one specific task without submitting the task again. A job record usually includes a status such as queued, running, succeeded, or failed. A successful job also points to its result.
First check what your chosen API actually supports. An OpenAI-compatible interface does not automatically provide background jobs, job-status endpoints, or webhooks. If those features are unavailable, your own server can create the job record and put the AI request on a queue for a worker to process.
Polling checks the job on a schedule
With polling, your application repeatedly asks for the job's current status. For example, the report page might check your server every five seconds. Each response either says the report is still running or provides the finished result.
This is often the easiest starting point. You need a status endpoint and a timer, and it works during local development without exposing an incoming webhook endpoint to the internet.
The tradeoff is extra requests. Checking every five seconds during a four-minute job produces about 48 checks. Most will report no change. There is also a small delay between completion and the next check.
- Start with a modest interval, such as five seconds, and increase it for longer waits.
- Add a little random variation so many clients do not check at exactly the same moment.
- Stop checking after success or failure, and pause browser checks when the page is hidden.
- Respect rate limits and any retry timing the API provides.
Webhooks send a completion notice to your server
With a webhook, the system running the job sends an HTTP request to an endpoint you control when something happens. A completion notice might include the job ID, its final status, and an event ID.
Your server receives that notice and updates the saved job record. The browser can then get the result from your server. A webhook reaches your server; it does not automatically update an open browser tab. Your page still needs a way to receive or check for that update.
Webhooks reduce repeated status requests and can report completion promptly. They also require an accessible endpoint and careful handling of incoming events.
A finished report needs reliable event handling
Webhook delivery can fail temporarily, and retries can deliver the same event more than once. Verify the sender using the service's documented signature method. Record the event durably, acknowledge it quickly, and process it separately if the work is substantial.
Use the event ID, when supplied, to detect duplicates. Also make the completion action safe to repeat: receiving the same notice twice should not email two reports or charge twice. Follow the service's documented retry and event-ordering behavior.
Keep a recovery path. If the service offers a status lookup, a scheduled check can find jobs whose webhook never arrived. A missing notice does not prove the AI job failed.
The first report feature can start with polling
For a small feature, polling is usually a practical first choice. Add webhooks when the upstream service supports them and request volume or update speed makes them worthwhile. Both approaches can share the same saved job record.
Separate the customer's waiting limit from the job's actual state. After several minutes, show “Still processing” and let the customer return later. Do not automatically submit another paid AI request because one status check timed out.
For the model calls behind your report worker, consider RelayVano as a pay-as-you-go option with OpenAI-compatible SDK access at https://api.relayvano.com. Sign up to try your workload, and confirm the endpoint's supported execution mode before choosing your job workflow.