Story #28 Asynchronous API Contracts · Long-Running Operations

The Operation That Finished After the Client Gave Up

"The client timed out and retried. The original operation had already completed—twice"

Northstar Data Services used HTTP 202 for long-running migrations. When clients polled for status and received no response, they resubmitted—creating duplicate operations that weren't safe to run concurrently and corrupted customer datasets.

What happened

Northstar Data Services exposed a migration API that returned HTTP 202 for large jobs, with an operation URL for polling status. The design was correct. What wasn’t correct was the error handling on both sides.

When a client polled for status and received a timeout or connection error, it resubmitted the original migration request. The API created a new operation. Meanwhile, the original operation completed successfully—it had just been slow to respond to the status poll. Now two migration operations were running against the same customer dataset.

The migrations weren’t designed to be run concurrently. Data was written in ways that conflicted. Some records were duplicated, others were inconsistently updated, and some were left in a partially migrated state.

Detecting the problem required correlating operation logs across multiple service instances, which took days. Recovery required manual data reconstruction and verification for affected customers.

Root cause

The API’s 202 response included an operation URL, but the contract didn’t define what clients should do when the operation URL was unreachable. No idempotency key prevented duplicate operation creation. Tests covered polling for a completed operation but not network failures during polling or concurrent operations on the same resource.

The fix

The API was updated to associate each migration with a stable client-provided idempotency key. Resubmitting the same key returned the existing operation rather than creating a new one. The contract was expanded to document exactly how long to poll, how to handle poll failures, and what to do if an operation appears to hang. Concurrency guards were added to prevent two active migrations against the same dataset.

Lesson learned

Asynchronous API contracts must define failure behavior, not just success behavior. What should a client do when a status poll fails? The answer must be in the contract—and must be enforced by the implementation.

The Operation That Finished After the Client Gave Up