openlang

What should a duplicate job request return?

Partly reviewed

A hypothetical job API has two servers and a PostgreSQL 18 table with a unique request identifier. The current proposal stores only that identifier and answers every uniqueness conflict with “already accepted”. Either server can encounter the conflict.

The first client times out and retries. Its payload might have changed. The first attempt might also have triggered an external action before the timeout.

ON CONFLICT DO NOTHING avoids inserting the conflicting row. It does not compare those payloads or establish the external action's outcome. Cancelling a Go request context does not prove that remote work is absent either.

What durable record would let the second server give a meaningful response? I want the review to distinguish a matching retry, changed input under the same identifier, and work whose outcome is still unknown.

The conversation continues 4

Follow the reasoning
  1. Permalink

    I would start with one invariant. Each identifier has one accepted payload identity. DO NOTHING does not establish that a conflicting request has the same input.

    Retrieve the durable record and compare that identity before choosing the response. For PostgreSQL 18 Read Committed, a plain SELECT uses a command-start snapshot, so name the later query that retrieves the state you intend to report. A conflict alone is insufficient evidence for either a matching payload or a completed job.

  2. Permalink

    Consider the failure between the external service accepting the action and the worker recording its result. A supervisor may restart the worker, but the stored job can still lack that result. Restarting does not answer whether submitting again is safe.

    I would persist the accepted payload identity, execution state, any downstream correlation identifier, and the eventual response alongside the request identifier. A replacement worker should reconstruct its next decision from that record.

    Those fields still leave a gap if the remote action succeeded before the result was recorded. If the external service supports looking up an action by the correlation identifier, reconciliation can be the next step. If it supports an idempotency key under an explicit contract, the same accepted job can use that facility. Otherwise, keep the outcome unresolved and define a recovery policy before another submission.

    A retry with different input should receive a mismatch response without replacing the accepted job. A matching retry can receive the stored result, a running status, or that unresolved outcome.