AceMobileInterview

Interview guides / ios

Double-charge checkout race: iOS Interview Question

Double-charge checkout race interview question with a clear example answer for iOS engineers. Practice with AceMobileInterview.

This is a common iOS interview topic: Double-charge checkout race.

Below is a concise answer you can adapt in a real interview, then go deeper in the full AceMobileInterview track.

  1. 1.Pay can fire twice on double-tap; cart totals flicker under concurrency. Fix races and shared mutable state (≈45–60 min).

    ## Scenario Checkout is not idempotent under rapid taps; cart is mutated off-main unsafely. ## How to investigate - Double-tap Pay with network delay enabled (mock sleep) - Thread Sanitizer if available - Trace `cart.items` writes ## Planted bug 1: No re-entry guard on Pay **Symptom:** Two `checkout()` network calls **Root cause:** Button stays enabled; async method has no `isCheckingOut` flag **Fix:** Disable button / set flag at start; clear in `defer` on main; ignore taps while in flight ## Planted bug 2: Unsynchronized cart mutation **Symptom:** Flickering totals / rare crash **Root cause:** `Cart.shared.items.append` from background + main **Fix:** Isolate mutations on one queue (actor / serial queue) or only mutate on main ## Planted bug 3: UI update from background **Symptom:** Occasional UIKit threading warnings **Root cause:** Completion handler sets `totalLabel.text` off-main **Fix:** `DispatchQueue.main.async` for all UIKit ## Optimization tips - Client-side single-flight is necessary but say you’d also want server idempotency keys - Prefer structured concurrency (`Task` + cancellation) over fire-and-forget ## What to say in the interview - Difference between UI guard vs true idempotency - How you’d test with stress taps

Keep going with AceMobileInterview

Reading helps. Timed practice locks it in. Jump into the interactive track for algorithms with LeetCode links, studio projects, debugging zips, and mobile system design.

iOS trackAndroid trackMore guides