Frontend reliability
Keeping Checkout Correct When Responses Arrive Late
The cart can change while a request is in flight. I tied checkout responses to the decision that created them, so a late result could not redirect a customer after they changed their mind.
Senior AI Engineer · M.S. Computer Science, Tsinghua University · See the products I built
In this article · 5 sections
The engineering decisions
- Wait for discount validation before creating checkout.
- Invalidate stale responses when the cart or purchase confirmation changes.
- Recover from timeout and browser-back navigation without losing the cart.
Two asynchronous actions competed for one decision
The storefront allowed a customer to validate a discount and proceed to checkout. If checkout started before validation finished, the pending discount could be ignored or arrive too late. A happy-path click test did not expose the ordering problem.
I reproduced the race with the real React component and controlled network responses, then made validation an explicit checkout dependency. Once validation completed, checkout used the corresponding confirmed code. Editing or removing the code, or changing the cart, invalidated the older validation result.
A response belongs to the request that created it
A checkout request can outlive the customer’s decision. They may change quantities, withdraw purchase confirmation, leave the page or return through the browser cache. A late response must not redirect them merely because it contains a valid provider URL.
The repaired flow invalidated the old request context on those transitions. A stale result could neither trigger navigation nor overwrite a newer request’s state. Request cancellation helped stop unnecessary work, but the response-side validity check was still necessary: cancellation is not proof that the remote operation never completed.
A network failure should preserve the cart
The request gained a bounded timeout, a synchronous duplicate-click lock and an abort signal. Network errors, non-JSON gateway responses and timeout restored an actionable retry state. They did not discard the cart or silently transform the checkout into a personal-information sales request.
Purchase confirmation also cleared when quantities changed. On returning from the hosted checkout, the browser-restored page recovered its controls so the customer was not trapped behind a permanent loading state. The pending-validation interlock and the retry state were tested as visible interactions, not only helper functions.
Use controlled delays for races, a browser for the journey
The controlled-component regressions exercised delayed validation, repeated clicks, confirmation withdrawal, request timeout and late responses. Browser checks on the U.S. test deployment verified discount waiting, confirmation recovery, provider navigation and returning to the cart at desktop and mobile sizes.
The record distinguishes those checks from a completed payment. The hosted test store still had an access boundary, and the work did not establish final shipping, taxes or collected amounts. Timeout and gateway failures were injected locally, not claimed as observations from a live provider incident.
Keep customer intent in the state machine
The key invariant was small: only a result belonging to the still-current, confirmed cart may advance checkout. That made a collection of button, discount and network bugs easier to reason about as one interaction. It also gave each regression a concrete failure to reproduce.
Project context and evidence
Written from my September 2026 U.S. storefront checkout repair and test-release records. Public links below support the product and attribution context. Internal project records are summarized, with customer records, credentials, and employer source code omitted.
- GolfJoy U.S. preview ↗
Public product context, separate from the historical acceptance fixtures.
- GolfJoy engineering case study ↗
Public product interfaces and attribution for the delivered projects.


