Interview guides / android
Double-charge checkout race: Android Interview Question
Double-charge checkout race interview question with a clear example answer for Android engineers. Practice with AceMobileInterview.
This is a common Android 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.Double-tapping Pay charges twice; cart state races. Fix concurrency (≈45–60 min).
## Scenario Checkout isn’t single-flight; shared cart mutates unsafely. ## How to investigate - Double-tap Pay with delay in fake API - Watch duplicate requests in Logcat - Trace `Cart.items` mutations ## Planted bug 1: No in-flight guard **Symptom:** Two checkout calls **Root cause:** Button stays enabled; ViewModel method re-entrant **Fix:** `if (isCheckingOut) return`; disable button; use `Mutex` or atomic flag ## Planted bug 2: Unsynchronized mutable list **Symptom:** Wrong totals / rare CME **Root cause:** `MutableList` edited from IO + Main **Fix:** Confine to Main; or `Mutex`; expose immutable snapshots via StateFlow ## Planted bug 3: UI update off main **Symptom:** Occasional threading issues **Root cause:** Updating LiveData/state from wrong context inconsistently **Fix:** Always emit UI state on Main ## Optimization tips - Mention server idempotency keys as the real backstop - `callbackFlow` / structured concurrency over ad-hoc threads ## What to say in the interview - UI disable vs true idempotency - How you’d write a stress test
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.