Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Define a platform standard for asynchronous and long-running operations across 50 teams' REST APIs, covering status resources, callbacks and failure semantics.

The standard defines one operation resource shape for every team (id, status enum, created and updated times, progress, error as problem details, result link) and fixed rules: 202 with Location and Retry-After, idempotency keys on creation, a uniform cancel action and final states that never change. Webhooks are signed, retried with backoff, carry a deduplication id and only point clients back to the operation, internal consumers can subscribe to events on the messaging platform instead of polling, and a shared library plus OpenAPI templates make following the standard the easiest path.

Why this question is asked

When 50 teams each invent their own way of handling slow operations, client developers pay for it: one API returns 202, another 200 with a 'processing' flag, a third makes you poll a URL you have to build yourself, and every webhook is signed differently, if at all. Interviewers ask this question at senior level to see whether we can write a standard that is precise enough to be useful and easy enough to be adopted. In this answer, we will define the operation resource, the rules for starting, polling and cancelling, the failure semantics, the webhook standard, events for internal consumers, and the tooling that makes teams adopt it.

1The Operation Resource Shape

The heart of the standard is one resource shape that every long-running operation uses, whatever it does. A client library written once then works for reports, imports, payouts and provisioning alike. We publish it as a shared schema in the API catalog, and every team's spec refers to it.

YAML
# components/schemas/Operation, shared by every API
{
"id": "op_7Hc2",
"kind": "invoice-export",
"status": "RUNNING", # PENDING | RUNNING | SUCCEEDED | FAILED | CANCELLED
"createdAt": "2026-11-05T09:00:00Z",
"updatedAt": "2026-11-05T09:04:12Z",
"progress": { "percent": 40, "message": "3 of 8 files written" },
"error": null, # problem details object when FAILED
"result": null, # { "href": "...", "expiresAt": "..." } when SUCCEEDED
"links": { "self": "/operations/op_7Hc2", "cancel": "/operations/op_7Hc2/cancel" }
}
Operation states in the standard
StatusFinal?What the client may rely on
PENDINGNoAccepted and stored; work not started
RUNNINGNoA worker is active; progress may change
SUCCEEDEDYesresult.href is readable until result.expiresAt
FAILEDYeserror is problem details; error says if retrying is safe
CANCELLEDYesStopped on request; effects described in the docs

Notice that the status enum is closed and small, and three of the states are final: SUCCEEDED, FAILED and CANCELLED. Clients stop polling at any of them, and the standard forbids moving out of a final state. Progress is optional because some operations cannot estimate it; when present it is a percent and a human message, not a team-specific structure.

2Rules for Starting, Polling and Cancelling

Starting an operation returns 202 Accepted, a Location header with the operation URL, a Retry-After header in seconds, and the operation in its first state. Every creation endpoint accepts an Idempotency-Key header: a repeat with the same key and body returns the original operation, and the same key with a different body is rejected with 422. Keys are kept for at least 24 hours.

GET on an operation always returns 200 while the operation exists and the caller may see it, including when it failed, and 404 for operations the caller does not own. Servers set Retry-After on every non-final response, and clients must respect it. Cancellation is POST on the cancel link: it returns 202 if cancellation started, 409 if the operation is already final, and the operation itself reports when it reaches CANCELLED. Teams that cannot cancel safely omit the link.

3Failure Semantics

Failure is where standards usually stay vague, and where clients most need precision. The standard says that error is a problem details object (RFC 9457) with a type URI per failure reason, so clients can branch on type rather than parsing text. It adds one required extension member, retryable, which tells the client whether starting the same operation again is safe and sensible.

It also requires each API to document what a failed or cancelled operation leaves behind. An import that failed at file 5 of 8 may have written four files; the client must know whether those stay, are rolled back, or are listed in the error. We do not force one behaviour on all teams, because a payout and a report differ, but we force them to say which it is. Finally, operations that exceed their documented maximum duration must move to FAILED with a timeout type, so no operation can stay RUNNING forever.

4The Webhook Standard

For external clients who do not want to poll, operations can notify a registered URL when they reach a final state. Webhooks are where security and reliability problems hide, so the standard is strict. Every delivery carries a unique delivery id, a timestamp and an HMAC signature computed over the id, timestamp and body with a secret shared per subscriber. The receiver recomputes it and rejects messages whose timestamp is more than five minutes old. Adopting an existing convention such as the Standard Webhooks specification saves us from inventing header names.

Java
POST https://client.example.com/hooks/operations
webhook-id: msg_2Kf9
webhook-timestamp: 1793869452
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=
Content-Type: application/json
{"type": "operation.completed", "operationId": "op_7Hc2", "status": "SUCCEEDED"}
// receiver: recompute HMAC-SHA256(secret, id + "." + timestamp + "." + body) and compare in constant time
Step throughWebhook delivery with retry
Operations serviceClient endpointOperations API
POST signed webhook msg_2Kf9
503, client busy
retry after backoff, same webhook-id
200, recorded msg_2Kf9
GET /operations/op_7Hc2
SUCCEEDED, result href

6 messages in order. Play them, or step through them one at a time.

Notice that the payload is thin: just the type, the operation id and the status. The receiver fetches the operation to get the details. That way a leaked or replayed webhook cannot inject data, and the operation resource stays the single source of truth. Deliveries that fail are retried with exponential backoff, for example over 24 hours, and because retries mean duplicates, receivers deduplicate on webhook-id. If all retries fail, the client can still poll, so nothing is lost.

5Events for Internal Consumers

Inside the company we have something better than webhooks: the messaging platform. Every operation state change is also published as an event, such as operation.completed, on a topic for that kind of operation, using the same thin payload. Internal services subscribe instead of polling or registering HTTP callbacks, and they get the platform's retention, replay and consumer groups for free.

Events are published through a transactional outbox, so a state change in the database and its event cannot get out of step. The event schemas are registered in the schema registry with the same compatibility rules as every other event.

6Making the Standard Easy to Adopt

A standard in a wiki is advice; a standard in a library is the default. We ship a Spring Boot starter that provides the operation table, the controller helpers that return 202 with the right headers, idempotency handling, a sweeper for stuck operations, webhook signing and delivery, and outbox publishing. A team adds the dependency, implements one interface for the actual work, and gets the rest.

For the contract, we publish OpenAPI templates with the shared Operation schema and the standard responses, and Spectral rules that lint every spec in CI: a 202 without Location, a missing Idempotency-Key parameter or a private status enum fails the check. We pilot it with three teams, adjust, then make it mandatory for new APIs and for existing ones when they next change their async endpoints.

7Follow-up questions

Why not let each team design its own status values?

Because every client would need custom code per API, and generic tools such as SDK helpers, dashboards and support scripts would be impossible. Teams can still describe their work in progress.message and in the kind field; only the lifecycle is shared.

Should the standard allow long polling or server-sent events?

It can allow them as optional extras for browser clients, but not as a replacement. The required baseline is the operation resource with polling, because it works through every proxy and survives disconnects; webhooks, events and server-sent events are faster ways to learn that the resource changed.

8Conclusion

In this answer, we wrote a platform standard for long-running operations across 50 teams. It defines one operation resource with a small status enum and final states, errors as problem details with a retryable flag, and result links with expiry; it fixes 202 with Location and Retry-After, idempotency keys and a uniform cancel action; it specifies signed, retried and deduplicated webhooks that point back to the resource, events on the messaging platform for internal consumers, and a starter library with OpenAPI templates and lint rules so teams adopt it by default.

What to say in the interviewAbout 90 seconds aloud

Open with

I would make the operation resource the centre of the standard. Every long-running endpoint returns 202 Accepted with a Location to /operations/{id}, a Retry-After header and the operation body, and accepts an Idempotency-Key so repeats return the same operation.

Then, if they want more

The operation has one shared shape: id, kind, a status enum of PENDING, RUNNING, SUCCEEDED, FAILED and CANCELLED, with the last three final, created and updated times, optional progress, a result link with an expiry, and an error that is a problem details object with a type per reason and a retryable flag.

Each API must also document what a failed or cancelled operation leaves behind, and operations past their maximum duration fail with a timeout type. Cancel is a POST on a cancel link, with 409 if already final.

For external clients, webhooks are signed with HMAC over id, timestamp and body, retried with backoff, deduplicated by delivery id, and carry only the id and status so the client re-fetches the resource. Internal consumers subscribe to operation events on the messaging platform via an outbox instead of polling.

And to make it stick, I would ship a Spring Boot starter that implements all of this, OpenAPI templates with the shared schema, and Spectral rules in CI, pilot it with a few teams, then require it for new APIs.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Define a platform standard for asynchronous and long-running operations across 50 teams'...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/35f9545549/