{"type":"excalidraw","version":2,"source":"https://AwesomeSystemDesign.dev","elements":[{"angle":0,"strokeColor":"#6577aa","backgroundColor":"#eef1fc","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0.7,"opacity":100,"version":1,"versionNonce":1,"isDeleted":false,"groupIds":["step-1"],"frameId":null,"roundness":null,"boundElements":[{"type":"text","id":"shape-1"}],"updated":0,"link":null,"locked":false,"id":"shape-0","type":"rectangle","seed":41,"x":16,"y":16,"width":288,"height":836.8000000000001,"customData":{"revealStep":1}},{"angle":0,"strokeColor":"#394557","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0.7,"opacity":100,"version":1,"versionNonce":1,"isDeleted":false,"groupIds":["step-1"],"frameId":null,"roundness":null,"boundElements":null,"updated":0,"link":null,"locked":false,"id":"shape-1","type":"text","seed":114,"x":36,"y":34,"width":248,"height":800.8000000000001,"fontSize":22,"fontFamily":1,"text":"Layer 2: Internal\nRequest ID for\nNetwork Calls\n\nOur system assigns\nunique request_id\nfor each network call\n\nIf we crash after\nsending to network:\n1. On restart, find\n\"in-flight\" payments\n(status=PROCESSIN\nG)\n2. Query network:\n\"what happened to\nrequest_id=REQ-123?\n\"\n3. Network returns:\n\"approved\" or\n\"declined\" or \"not\nfound\"\n4. Update our state\naccordingly\n\nThis is called\n\"recovery/reconciliatio\nn\"","originalText":"Layer 2: Internal\nRequest ID for\nNetwork Calls\n\nOur system assigns\nunique request_id\nfor each network call\n\nIf we crash after\nsending to network:\n1. On restart, find\n\"in-flight\" payments\n(status=PROCESSIN\nG)\n2. Query network:\n\"what happened to\nrequest_id=REQ-123?\n\"\n3. Network returns:\n\"approved\" or\n\"declined\" or \"not\nfound\"\n4. Update our state\naccordingly\n\nThis is called\n\"recovery/reconciliatio\nn\"","textAlign":"left","verticalAlign":"middle","containerId":"shape-0","lineHeight":1.3,"autoResize":false,"customData":{"revealStep":1}},{"angle":0,"strokeColor":"#6577aa","backgroundColor":"#eef1fc","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0.7,"opacity":100,"version":1,"versionNonce":1,"isDeleted":false,"groupIds":["step-2"],"frameId":null,"roundness":null,"boundElements":[{"type":"text","id":"shape-3"}],"updated":0,"link":null,"locked":false,"id":"shape-2","type":"rectangle","seed":187,"x":16,"y":896.8000000000001,"width":288,"height":1037,"customData":{"revealStep":2}},{"angle":0,"strokeColor":"#394557","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0.7,"opacity":100,"version":1,"versionNonce":1,"isDeleted":false,"groupIds":["step-2"],"frameId":null,"roundness":null,"boundElements":null,"updated":0,"link":null,"locked":false,"id":"shape-3","type":"text","seed":260,"x":36,"y":914.8000000000001,"width":248,"height":1001,"fontSize":22,"fontFamily":1,"text":"Layer 1: Client-Side\nIdempotency Key\n\nEvery API request\nincludes:\nIdempotency-Key:\n\"order-1234-charge\"\n\nProcessing:\n1. SETNX in Redis:\nidempotency:{merchan\nt}:{key} →\n\"processing\"\nTTL = 48 hours\n2. If key already\nexists:\n→ Check status:\n\"processing\" → return\n409 (in progress)\n→ Check status:\n\"completed\" → return\nstored result (200)\n3. Process payment\n4. Store result:\nidempotency:{merchan\nt}:{key} → {result\nJSON}\n5. Return result to\nclient\n\nMerchant retries\nsame key → gets\nidentical response\nNo duplicate charge\npossible","originalText":"Layer 1: Client-Side\nIdempotency Key\n\nEvery API request\nincludes:\nIdempotency-Key:\n\"order-1234-charge\"\n\nProcessing:\n1. SETNX in Redis:\nidempotency:{merchan\nt}:{key} →\n\"processing\"\nTTL = 48 hours\n2. If key already\nexists:\n→ Check status:\n\"processing\" → return\n409 (in progress)\n→ Check status:\n\"completed\" → return\nstored result (200)\n3. Process payment\n4. Store result:\nidempotency:{merchan\nt}:{key} → {result\nJSON}\n5. Return result to\nclient\n\nMerchant retries\nsame key → gets\nidentical response\nNo duplicate charge\npossible","textAlign":"left","verticalAlign":"middle","containerId":"shape-2","lineHeight":1.3,"autoResize":false,"customData":{"revealStep":2}},{"angle":0,"strokeColor":"#6577aa","backgroundColor":"#eef1fc","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0.7,"opacity":100,"version":1,"versionNonce":1,"isDeleted":false,"groupIds":["step-3"],"frameId":null,"roundness":null,"boundElements":[{"type":"text","id":"shape-5"}],"updated":0,"link":null,"locked":false,"id":"shape-4","type":"rectangle","seed":333,"x":16,"y":1977.8000000000002,"width":288,"height":894,"customData":{"revealStep":3}},{"angle":0,"strokeColor":"#394557","backgroundColor":"transparent","fillStyle":"solid","strokeWidth":1.5,"strokeStyle":"solid","roughness":0.7,"opacity":100,"version":1,"versionNonce":1,"isDeleted":false,"groupIds":["step-3"],"frameId":null,"roundness":null,"boundElements":null,"updated":0,"link":null,"locked":false,"id":"shape-5","type":"text","seed":406,"x":36,"y":1995.8000000000002,"width":248,"height":858,"fontSize":22,"fontFamily":1,"text":"Layer 3: Database\nTransaction for\nState Changes\n\nBEGIN\nTRANSACTION;\nUPDATE\npayment_intents SET\nstatus='succeeded'\nWHERE id=...;\nINSERT INTO\nledger_entries\n(debit) VALUES (...);\nINSERT INTO\nledger_entries\n(credit) VALUES (...);\nINSERT INTO\nevents\n(payment_intent.succ\needed) VALUES (...);\nCOMMIT;\n\nAll state changes\nare atomic:\nPayment status +\nledger + event log\ncommitted together\nIf any fails, all roll\nback → consistent\nstate guaranteed","originalText":"Layer 3: Database\nTransaction for\nState Changes\n\nBEGIN\nTRANSACTION;\nUPDATE\npayment_intents SET\nstatus='succeeded'\nWHERE id=...;\nINSERT INTO\nledger_entries\n(debit) VALUES (...);\nINSERT INTO\nledger_entries\n(credit) VALUES (...);\nINSERT INTO\nevents\n(payment_intent.succ\needed) VALUES (...);\nCOMMIT;\n\nAll state changes\nare atomic:\nPayment status +\nledger + event log\ncommitted together\nIf any fails, all roll\nback → consistent\nstate guaranteed","textAlign":"left","verticalAlign":"middle","containerId":"shape-4","lineHeight":1.3,"autoResize":false,"customData":{"revealStep":3}}],"appState":{"viewBackgroundColor":"#fbfbf8","gridSize":null},"files":{}}