The Real Fullstack

The Double-Charged Customer

Frontend added a key, backend checks it, messaging retries safely. Why does finance still see duplicate charges?

アーキテクト15 分フローシミュレーターコード課題デバッグラボ
angularspring-bootpostgresqlkafka

この課題はまだ日本語に翻訳されていません。英語版を表示しています。

ミッション:Fix the payment flow from each role's perspective, then prove the whole chain charges once and sends one receipt under every failure combination.背景 · 学習目標 ▾

After an earlier incident, each team at Larkspur added “idempotency” on its own: the SPA generates a key on every click, the payment service checks for an existing key before inserting, and the receipt consumer was left alone. Duplicates went down — but not to zero.

ミッション: Fix the payment flow from each role's perspective, then prove the whole chain charges once and sends one receipt under every failure combination.

学習目標

  • See how idempotency spans frontend, backend and messaging.
  • Make each layer's guarantee hold, not just exist.
  • Verify the end-to-end property under all failures.
シミュレーションシミュレーション値
Checkout SPAGatewayPayment servicePayment providerPayments DBpayment-confirmedReceipt mailer
シミュレーションを実行
// key created once per checkout attempt, reused by clicks and retriesprivate readonly key = crypto.randomUUID();pay() {  return this.http.post('/payments', this.cart(), { headers: { 'Idempotency-Key': this.key } })    .pipe(retry({ count: 2, delay: (_, n) => timer(300 * 2 ** n) }));}

簡略化

Reuses the payment idempotency model with an extra key-scope choice. 教育用モデルです。数値は挙動を示すためのもので、ベンチマークではありません。

コンセプト

先に取り組むと役立つ課題

関連する課題

参考資料