Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Background Jobs  ›  Capstone Project

Returning Results

Returning Results 15 minWhen work runs in the background, the caller gets a job ticket immediately and later learns the result by polling a status address, receiving a callback, or being pushed an update.

Returning Results

Hop business customers can upload a file with 50,000 long addresses and get 50,000 short links back. That takes about two minutes. Holding a web request open that long invites timeouts, dropped connections and angry retries. The work belongs in a background job — but then how does the answer get back to whoever asked?

The rule

Hand out a ticket now; deliver the answer later.

The first response comes immediately and carries a ticket — a job id or a status address:

POST /imports              (the file)
202 Accepted
Location: /jobs/5521

202 Accepted means "received, not finished". The finished result is then delivered one of three ways:

  • Polling — the client asks /jobs/5521 every few seconds: "queued", "running 40%", "done". Simple and works everywhere; costs some wasted requests.
  • Callback (webhook) — the client registers an address, and Hop calls it when the job ends. No wasted requests, but the client must run a server that can receive calls, and a lost callback needs a fallback.
  • Push — an open connection (such as a WebSocket or server-sent events) lets Hop send progress straight to a browser as it happens.

In every case the result itself — here, a file of 50,000 short links — is stored and fetched from a result address. It does not live inside the original request.

The shortcut

Ask: "Who is waiting, and can they receive a call?" A person in a browser → poll or push. Another company's server → webhook, with polling as the safety net.

Hop's bulk importStep 1 of 5
  1. Accept

    Store the file, create job 5521, reply 202 Accepted with /jobs/5521. Under 100 ms.

The trap is a job with no way to report failure. "Done" is not the only ending: jobs need a clear "failed" status with a reason, or clients poll forever.

Drills

Answer fast — trust the rule.

quick drill

What does an HTTP 202 Accepted response tell the client?

quick drill

A mobile app with no server of its own wants a job's result. Which approach fits best?

quick drill

What is the main advantage of a webhook over polling?

quick drill

A job hits an error halfway. What should the status address report?

quick drill

Where should the 50,000 new short links live when the job finishes?

Remember

  • Hand out a ticket now; deliver the answer later.
  • Shortcut: a person waiting → poll or push; a server waiting → webhook plus polling as backup.
  • Trap: no "failed" status, and results held inside a long open request.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainReturn the result of a bulk import

Hop business customers can upload a file of 50,000 long addresses to shorten at once, which takes about two minutes. Design how the result gets back to (a) a person using Hop's website and (b) another company's server calling Hop's API. Describe the first response and how each learns the job is done.