Skip to content
AgenticAIWiki
  1. Learn
  2. Part 13
  3. 68. Serving patterns
  4. 68.1

Lesson 68.1 · 1 of 5 · 4 min read · Reviewed 24 Nov 2026

Sync, streaming and async jobs

By the end, you can

  • Choose between synchronous, streaming and async job designs.
  • Match the pattern to user expectations.

How you serve a model call depends on how long it takes and who is waiting.

Three patterns

sync:       client --request--> API --model--> API --answer--> client
streaming:  client --request--> API ==tokens==> client (as made)
async job:  client --request--> API --job id--> client
            worker --model--> store; client polls or gets a webhook
Pattern Good for Watch out for
Sync Short classify or extract calls, server to server Timeouts on long outputs
Streaming Chat UIs, long answers people read Errors can arrive mid-stream; handle partial output
Async job Agents, documents, anything over about 30 s Needs a job store, status and retries

Picking

  • A person reading the answer? StreamStreaming: Receiving a response as a series of server-sent events while it is generated, instead of waiting for the whole reply.. Time to first tokenTime to first token (TTFT): How long a user waits between sending a request and seeing the first token of the reply. matters more than total time.
  • Another service needs one result fast? Sync, with a timeout.
  • Minutes of work, or many steps? Async job. Show status and progress events if you can.
  • Nobody is waiting at all? Consider batch (68.4).

Many products mix them: an async agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. job that streams progress events to the page while it runs.

Key points

  • Synchronous: the caller waits for the full answer. Fine for short, fast calls.
  • Streaming: tokens arrive as they are made, so a person sees progress within a second or two.
  • Async jobs: accept the request, return a job id, and deliver the result later by polling or webhook.
Hands-on labRuns in the Playground

Choose a serving pattern per request

Match each kind of request to synchronous, streaming or an async job.

You will have: A pattern() rule that labels five request types, plus a working submit-and-poll job flow.

Steps

  1. Run the starter: everything is labelled sync.
  2. Send anything longer than the HTTP limit to an async job.
  3. Stream work that a person watches and that takes more than about 2 seconds.
  4. Make worker_step() complete a queued job so polling shows done.
  5. Add a request type of your own and check its label makes sense.

Done when

  • research agent and PDF report are async jobs.
  • chat reply streams; autocomplete stays sync.
  • The job status goes from queued to done.

Open in the Playground No API key needed.

Starter code (Python)
# Pick sync, streaming or an async job for each kind of request, then run one async job.
REQUESTS = [
    {"name": "autocomplete", "seconds": 0.4, "watched": True},
    {"name": "chat reply", "seconds": 8, "watched": True},
    {"name": "tag one ticket", "seconds": 1.5, "watched": False},
    {"name": "PDF report", "seconds": 150, "watched": True},
    {"name": "research agent", "seconds": 300, "watched": False},
]
HTTP_LIMIT_SECONDS = 30


def pattern(req):
    # TODO: long work (over HTTP_LIMIT_SECONDS) should be an async job
    # TODO: work a person watches that takes more than ~2 s should stream
    return "sync"


for r in REQUESTS:
    print(f"{r['name']:<15} ~{r['seconds']:>5} s  -> {pattern(r)}")

# A tiny async job flow: submit returns a job id at once; a worker finishes it later.
JOBS = {}


def submit(name):
    job_id = f"job-{len(JOBS) + 1}"
    JOBS[job_id] = {"name": name, "status": "queued"}
    return job_id


def worker_step():
    # TODO: find the first queued job, mark it "done" and store a result
    pass


jid = submit("research agent")
print(jid, "status:", JOBS[jid]["status"])
worker_step()
print(jid, "status:", JOBS[jid]["status"], "|", JOBS[jid].get("result"))
Show a solution
# Pick sync, streaming or an async job for each kind of request, then run one async job.
REQUESTS = [
    {"name": "autocomplete", "seconds": 0.4, "watched": True},
    {"name": "chat reply", "seconds": 8, "watched": True},
    {"name": "tag one ticket", "seconds": 1.5, "watched": False},
    {"name": "PDF report", "seconds": 150, "watched": True},
    {"name": "research agent", "seconds": 300, "watched": False},
]
HTTP_LIMIT_SECONDS = 30


def pattern(req):
    if req["seconds"] > HTTP_LIMIT_SECONDS:
        return "async job"
    if req["watched"] and req["seconds"] > 2:
        return "streaming"
    return "sync"


for r in REQUESTS:
    print(f"{r['name']:<15} ~{r['seconds']:>5} s  -> {pattern(r)}")

# A tiny async job flow: submit returns a job id at once; a worker finishes it later.
JOBS = {}


def submit(name):
    job_id = f"job-{len(JOBS) + 1}"
    JOBS[job_id] = {"name": name, "status": "queued"}
    return job_id


def worker_step():
    for job in JOBS.values():
        if job["status"] == "queued":
            job["status"], job["result"] = "done", f"{job['name']} finished"
            return


jid = submit("research agent")
print(jid, "status:", JOBS[jid]["status"])
worker_step()
print(jid, "status:", JOBS[jid]["status"], "|", JOBS[jid]["result"])
Quick checkAn agent task takes 3 to 10 minutes. How should the web app serve it?
How sure are you?
Pick an answer and how sure you are