An order API seems straightforward until a client times out during creation or two agents edit the same order. In a REST API interview, explain which behavior follows from HTTP and which is a promise your application must implement. Use one order from creation through updates so those promises stay consistent.

Decide what a repeated request means

1. Does idempotency mean every response is identical?

No. An idempotent method has the same intended effect when the same request is sent more than once. A successful DELETE followed by another DELETE may return different status codes while leaving the resource absent both times. Safe methods such as GET should not request a state change like placing an order, even though the server may record logs or metrics.

2. How can a client retry creating an order?

POST is not inherently idempotent. Define an application-level retry contract: scope the client's operation key to its identity, compare the retry with the original request, and atomically record the creation and outcome. Returning the previous order for a matching retry prevents duplicate creation when the original response is lost. Reject reuse with a different payload and document the retention period. If work runs asynchronously, a duplicate request should report the existing operation rather than start another one.

Make conflicts explicit

3. How do you prevent a stale edit from overwriting a newer one?

Return a strong ETag with the order representation and use If-Match on writes. If the validator no longer matches, the server can reject the edit with 412 Precondition Failed. Perform the precondition check together with the update; a separate check followed by an unconditional write leaves a race. A 409 Conflict can instead describe a business rule conflict, such as trying to edit an already shipped order.

PUT /orders/123 HTTP/1.1
Host: api.example.com
If-Match: "order-v7"
Content-Type: application/json

{"shippingMethod":"standard"}

This illustrative contract assumes the order's editable representation contains only the shipping method; PUT asks to replace the target representation. If more editable fields exist and the request sets only one, define a partial update contract rather than quietly treating PUT as a merge.

4. What makes an error actionable without exposing internals?

Separate the HTTP status from application detail. Use a documented problem type for predictable cases, explain what the caller can do, and keep internal stack traces out of the response. A validation error can identify which field needs correction; a stale edit can tell the caller to fetch the latest representation. In practice, clients should not have to parse a free-text error message to decide whether to retry.

5. Does cursor pagination make a changing list consistent?

Not automatically. Start with a deterministic sort, for example creation time plus ID, and make the cursor correspond to the ordering and active filters. This avoids common offset shifts caused by inserts before the current position. It does not create a snapshot if records change or move in the sort order between requests. Decide whether the list is a live view or a stable export, and state that contract.

Rehearse the boundary cases

  • Trace a successful POST whose response is lost, followed by two retries arriving together.
  • Have two clients edit version seven. Say which request succeeds and how the other client recovers.
  • Page through equal timestamps while inserting a new order. Explain what the cursor does and does not guarantee.

For a broader design exercise, try the reservation system walkthrough. Then practice saying your retry contract aloud with Mentaro's free practice demo.

Sources