logo

Polling

Polling is a technique where a client sends repeated requests to a server at regular intervals to detect changes — such as a task completing, a file becoming available, or new data arriving. It’s the simplest way to monitor asynchronous work without webhooks or WebSockets.

How Polling Works

  1. Client sends a request to check the status of a resource
  2. Server responds with the current status
  3. If not done, client waits a fixed interval and checks again
  4. Once the status indicates completion, client stops polling
const pollForResult = async (jobId) => {
  const res = await fetch(`/api/jobs/${jobId}`);
  const data = await res.json();

  if (data.status === 'completed') {
    return data.result;
  } else if (data.status === 'failed') {
    throw new Error('Job failed');
  }

  // Wait and try again
  await new Promise(r => setTimeout(r, 3000));
  return pollForResult(jobId);
};

Polling vs. Webhooks

AspectPollingWebhooks
LatencyUp to one polling intervalNear-instant
Server loadHigher (many repeated requests)Lower (one request on completion)
ComplexitySimple client-side loopRequires a public endpoint
ReliabilityVery reliable — client controls the flowWebhook delivery can fail

Use polling when the client is a browser or mobile app without WebSocket infrastructure. Use webhooks when the consumer is a server that can receive HTTP callbacks.

Best Practices

  • Use exponential intervals: Start at 1 second, increase to 2s, 4s, 8s… to reduce server load
  • Set a maximum attempts limit: Don’t poll forever — give up after a reasonable number of attempts
  • Return progress information: Include a percentage or step indicator so the client can show meaningful progress
  • Consider long polling or SSE: For lower latency without WebSocket complexity