Google AIP-151 long-running operations: model status and results
For work that takes too long for an ordinary API response, Google AIP-151 represents the job with a google.longrunning.Operation. The client keeps its name, checks status, and receives progress metadata plus either the typed result or an error. This is a Google API design pattern, not a requirement for every REST API.
For work that takes too long for an ordinary API response, Google AIP-151 represents the job with a google.longrunning.Operation. The client keeps its name, checks status, and receives progress metadata plus either the typed result or an error. This is a Google API design pattern, not a requirement for every REST API.
What an Operation represents
A background job is the server's execution mechanism; an Operation is the client-visible status resource. Whatever queue or worker runs the job, clients need to know whether it was accepted, whether it is progressing, and where to retrieve its result or failure. AIP-151 recommends returning an Operation and using the common Operations service to retrieve it.
Separate progress from the final result
An Operation has a name, a done flag, metadata for progress, and a terminal response or error. While done is false, the result is not available. On successful completion, done is true and response carries the declared result type. On failure, done is true and error carries a status error. Metadata can report progress or partial failures and is distinct from the final result.
Declare both response_type and metadata_type in the API method. For example, a long-running book creation can resolve to Book and use a service-defined OperationMetadata. Avoid Empty metadata unless you are certain no progress information will ever be needed.
Client flow
Call the API method and save Operation.name.
Poll GetOperation with that name, or wait for a documented notification.
While incomplete, present metadata as progress. When complete, handle response or error.
Follow the API's retry rules for errors; do not assume every failure is retryable.
Respect the documented retention period; an old operation name may eventually expire.
AIP-151 offers about 10 seconds as a rule of thumb for what may count as significant duration, and about 30 days as a rule of thumb for operation expiry. Neither value is a required threshold or service guarantee.
Errors and concurrent work
Reject a request that cannot start with the method's ordinary error response. If accepted work later fails, put the failure in the completed Operation.error field. A non-terminal problem may be reported in metadata.
Document whether multiple operations on one resource may run concurrently, queue, or conflict. If concurrent work is not allowed, AIP-151 advises returning ABORTED with an explanation. If a newer operation can replace an older one, document the older operation's terminal state.
Design checklist
Return the standard Operation type and provide the common Operations service.
Define final response and progress metadata as separate types.
Explain start-time errors, execution failures, and non-terminal issues.
Explain whether a resource being created or deleted is visible but not yet usable.
Publish retention, concurrency, retry, and result-retrieval rules.
Treat changes to response_type or metadata_type as compatibility-sensitive.
This is a design guide based on Google AIPs, not a claim that every API follows this contract. Other platforms may use different fields, errors, and retention rules. No API or client code was run for this article.
Sources
[Google AIP-151: Long-running operations](https://google.aip.dev/151)
[Google AIP-134: Standard methods: Update](https://google.aip.dev/134)
[Google AIP-135: Standard methods: Delete](https://google.aip.dev/135)