After a handler sends 202, a Promise may still be pending in the process. That does not turn the Promise into a queue. If the instance loses CPU, is terminated, or disappears before the effect finishes, the client has already received a response that seemed to confirm more than the system actually guaranteed.

The safe boundary is to persist or enqueue the work before responding. Google Cloud documents that Cloud Run can execute short tasks after the response when a service uses instance-based billing, but it also says idle instances can be terminated. For work that must not disappear, use a queue or another durable store. Cloud Tasks can call an HTTP service with retries; Cloud Run Jobs provide their own execution lifecycle for work that can run longer.

This article is a spoke of the Cloud Run introduction guide. The focus here is the decision between the request and the work: what must exist before the 202, which resource should execute the task, and which worker response can confirm completion.

Diagram compares a pending Promise with a durable queue and an idempotent Cloud Run worker.

Short answer

  • Do not run void processLater() and return 202 as if the work were protected.
  • Store an intent or create a durable queue task before responding.
  • Use instance-based billing for short background work that can tolerate termination and whose cost you accept. It keeps CPU available outside the request, but it does not replace a queue.
  • Use Cloud Tasks for HTTP work with retries and a bounded duration. For an execution that should live outside a request lifecycle, evaluate Cloud Run Jobs.
  • The worker should return 2xx only after it completes the effect or records an idempotent completion.

What changes after the HTTP response leaves?

Cloud Run separates request processing from the instance lifecycle. With request-based billing, CPU is allocated while the request is processed. With instance-based billing, CPU remains allocated throughout the instance lifecycle. The Cloud Run billing settings documentation, retrieved on 2026-12-02, lists asynchronous work after the response as a possible use of the second mode.

That is not a guarantee that an instance will stay alive until the Promise finishes. The same documentation says idle instances can be terminated and recommends considering Cloud Tasks for asynchronous tasks. Cloud Run can also send SIGTERM; an instance has a 10-second grace period to exit, not permission to keep critical work only in memory.

There are two separate questions:

  1. Does the application have enough CPU to keep running after the request?
  2. Can the system recover the task if the process dies before the effect?

--no-cpu-throttling can answer the first question. Only a queue, durable record, or another recovery contract answers the second.

If the decision also involves cost and idle capacity, the Cloud Run billing comparison covers that choice. It is related, but it does not replace the delivery contract described here.

Choose the boundary by the work

There is no single way to run everything that happens after a response. Match the boundary to duration, retry needs, trigger, and tolerance for losing an execution.

Boundary When it fits What the response can confirm
Same request The effect is small and part of what the client expects The effect finished
Service with instance-based CPU Short internal work that can tolerate termination The request finished, not durable work
Cloud Tasks plus an HTTP service Asynchronous work with retries, rate control, and a private endpoint The task was enqueued
Cloud Run Job Work that needs its own lifecycle and can finish outside the request The execution was requested
Worker pool A continuous pull consumer with no need for an HTTP endpoint The worker accepted the message under its own contract

The Cloud Run overview separates Service, Job, and worker pool by execution model. The asynchronous tasks documentation is also explicit: the service receiving a task must return 200 after processing is complete. A worker's 2xx should not mean only that the process started.

For Cloud Tasks, there is another boundary. The task is delivered as an HTTPS request and must finish within its configured timeout. The current documentation says Cloud Tasks supports runs of up to 30 minutes; for work that needs longer, it points to Cloud Run Jobs. Do not increase an endpoint timeout just to hide a boundary that should be a queue.

The fire-and-forget mistake

This handler responds quickly, but it has no delivery contract:

app.post("/reports", async (request, response) => {
  const report = await createReport(request.body);

  // The Promise continues in the process memory.
  void generatePdf(report.id);

  response.status(202).json({ reportId: report.id });
});

The problem is not async itself. The problem is responding before a recoverable unit of work exists. If generatePdf fails after the 202, the client does not know whether it should retry. If it retries, it may create two PDFs or apply the same effect twice. If the process is terminated, there is no queue to redeliver the work.

A safe version moves the intent outside process memory before responding:

app.post("/reports", async (request, response) => {
  const report = await createReport(request.body);
  const task = await queue.enqueue({
    kind: "generate-pdf",
    reportId: report.id,
    idempotencyKey: `report:${report.id}:pdf`,
  });

  response.status(202).json({ reportId: report.id, taskId: task.id });
});

The queue.enqueue call is illustrative. In a real system, creating the report and recording the task may need a transaction or a transactional outbox. The property to verify is the order: if the queue has not confirmed the task, the handler should not return a response that promises asynchronous processing.

A Node.js fixture for testing the handoff

Before integrating Cloud Tasks, test the local rule. The fixture below uses only node:test and node:assert/strict. It does not call Google Cloud. Its purpose is to prove that the handler waits for enqueue confirmation before building the response.

Save it as background-handoff.test.mjs and run node --test background-handoff.test.mjs on a Node.js version that supports the native test runner:

import assert from "node:assert/strict";
import { test } from "node:test";

function makeHandler({ enqueue }) {
  return async function handle({ reportId }) {
    const task = await enqueue({
      kind: "generate-pdf",
      reportId,
      idempotencyKey: `report:${reportId}:pdf`,
    });

    return {
      statusCode: 202,
      body: { reportId, taskId: task.id },
    };
  };
}

test("does not return 202 before the task is durable", async () => {
  let releaseEnqueue;
  const enqueue = () => new Promise((resolve) => {
    releaseEnqueue = () => resolve({ id: "task-1" });
  });
  const handle = makeHandler({ enqueue });

  const pendingResponse = handle({ reportId: "report-1" });
  let settled = false;
  pendingResponse.finally(() => { settled = true; });

  await new Promise((resolve) => setImmediate(resolve));
  assert.equal(settled, false);

  releaseEnqueue();
  assert.deepEqual(await pendingResponse, {
    statusCode: 202,
    body: { reportId: "report-1", taskId: "task-1" },
  });
});

The test does not prove that the queue provider persisted the bytes. It proves a smaller, useful property: the adapter does not announce acceptance while the queue adapter is still pending. The queue SDK, transaction, and retry policy need their own integration tests.

The worker must be repeatable

A queue turns a failure into another possible attempt. It does not make the effect idempotent by itself. The worker should use the task identifier or a business key to discover whether it already completed the effect.

export async function processTask(task, { jobs, generatePdf }) {
  const previous = await jobs.find(task.idempotencyKey);
  if (previous?.status === "done") return { status: "already-done" };

  const claimed = await jobs.claim(task.idempotencyKey);
  if (!claimed) return { status: "already-running" };

  try {
    await generatePdf(task.reportId);
    await jobs.markDone(task.idempotencyKey);
    return { status: "done" };
  } catch (error) {
    await jobs.markRetryable(task.idempotencyKey, String(error));
    throw error;
  }
}

The jobs store must support concurrency between instances. A process-local Map is not enough when two instances receive the same task or when a new instance takes over after termination. The page on Cloud Run Job retries and checkpoints explores the same boundary for Job executions.

In the HTTP handler that receives Cloud Tasks, confirm the work only after generatePdf and markDone finish. If the worker returns an error before then, the task service can try again. If the external effect cannot be safely repeated, record a receipt or reconcile it before marking the task complete.

When is instance-based CPU enough?

There are legitimate cases for running a short activity after the response. The Cloud Run documentation describes instance-based billing as a way to keep CPU available outside request processing and provides --no-cpu-throttling for this setting:

gcloud run services update SERVICE --no-cpu-throttling

This solves CPU allocation, not durability. Autoscaling, instance termination, and the SIGTERM limit still exist. Use this mode when the task is an optimization or when the system has an independent way to rebuild the work. Do not use a pending Promise as the only copy of an effect the user considers mandatory.

If the process needs to finish a short step during shutdown, handle SIGTERM to stop accepting new work and save a recovery point. The Cloud Run SIGTERM guide covers that lifecycle. A signal handler is a shutdown layer, not proof of delivery.

How to verify the configuration without trusting 202

Verify the boundary in layers:

  1. Handoff: force enqueue to fail. The endpoint should return an error or a response that does not promise the task.
  2. Identity: confirm that taskId, reportId, and the idempotency key are persisted together.
  3. Retry: make the worker fail after a controlled call and verify that the next attempt does not duplicate the effect.
  4. Completion: make the worker return 2xx only after recording the postcondition.
  5. Shutdown: send SIGTERM while the task is pending and verify that the queue or checkpoint recovers the unit.
  6. Observability: record a correlation ID across the request, task, attempt, and external effect.

To create a queue, the documentation uses gcloud tasks queues create QUEUE_ID. For a Job with its own timeout, the current command is gcloud run jobs create JOB_NAME --image IMAGE_URL --task-timeout TIMEOUT. These commands configure resources, but they do not prove that your idempotency or completion contract is correct.

Failures that look fine in development

Responding and starting the Promise

In a local container, the Promise often finishes before you notice the risk. In production, the process may lose CPU, be terminated, or receive more load. The useful test measures whether the intent was persisted, not whether a log appeared a few milliseconds later.

Returning 200 when the task only started

For a queue that uses HTTP status as confirmation, 200 should represent completed processing. If the task was only accepted, let the ingress API confirm the request and let the worker confirm the effect later.

Increasing the request timeout forever

The request timeout changes how long the service waits for a response. Cloud Run documents a service limit of up to 60 minutes, but also recommends reconnection and retry for long requests. That does not turn a long operation into a recoverable task.

Using instance-based CPU as a queue

Available CPU helps finish background work. It does not create history, retries, an idempotency key, or a way for another instance to discover what is missing. If losing the work matters, create the durable unit first.

Method and limits

Samuel Fajreldines is responsible for the source selection, cluster decision, fixture, and writing. I consulted current Google Cloud documentation for billing, asynchronous tasks, request timeouts, and resource models on 2026-12-02. I also reviewed current English, Portuguese, and Spanish results and public discussions to recognize vocabulary and objections. Discussions were not used as technical proof.

The fixture is a local check of the adapter contract. I did not deploy a Cloud Run service, create a Google Cloud queue, measure cost or delivery, or claim production experience. AI assistance supported source discovery, organization, prose review, image preparation, and localization. It did not run a deployment or supply operational evidence.

Conclusion

Cloud Run can keep executing work after a response, but a pending Promise is not a delivery mechanism. First decide what the API actually confirms. Then persist or enqueue the work before 202, choose between a service, Cloud Tasks, Job, or worker pool, and make the effect repeatable.

Instance-based CPU is an execution option for short tasks. The queue is what protects the work when an instance disappears. Making that distinction explicit in the contract and tests lets the endpoint respond quickly without turning apparent success into missing work.

Sources