<mxfile host="thecodeclouds.com" agent="hand-built" version="24.0.0" type="device">
<diagram id="hld" name="1. Checkout: one store per service"><mxGraphModel dx="1400" dy="900" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1500" pageHeight="860" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="c1" value="Checkout architecture: each service owns its data, and events leave through an outbox" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=18;fontColor=#232F3E;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="16" width="1300" height="24" as="geometry"/></mxCell>
<mxCell id="c2" value="Sync calls carry a deadline and an idempotency key. Nothing reads another service's database." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="44" width="1300" height="18" as="geometry"/></mxCell>
<mxCell id="user" value='&lt;b&gt;Shopper&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;web / mobile app&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="60" y="95" width="150" height="60" as="geometry"/></mxCell>
<mxCell id="gw" value='&lt;b&gt;API gateway&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;auth, rate limit,&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;requires Idempotency-Key&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="270" y="88" width="190" height="74" as="geometry"/></mxCell>
<mxCell id="co" value='&lt;b&gt;Checkout service&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;saga orchestrator&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#E8F0FE;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="560" y="90" width="230" height="70" as="geometry"/></mxCell>
<mxCell id="codb" value='&lt;b&gt;Saga state&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;PostgreSQL&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;one row per checkout&lt;/font&gt;' style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=8;strokeColor=#1A73E8;fillColor=#E8F0FE;fontSize=12;fontColor=#202124;dashed=0;" vertex="1" parent="1"><mxGeometry x="870" y="82" width="190" height="86" as="geometry"/></mxCell>
<mxCell id="c3" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="user" target="gw"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c4" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="gw" target="co"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c5" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=block;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="co" target="codb"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c6" value="POST /checkout&lt;br&gt;Idempotency-Key: 7f3c…" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1A73E8;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="280" y="172" width="180" height="32" as="geometry"/></mxCell>
<mxCell id="c7" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="675" y="160" as="sourcePoint"/><mxPoint x="675" y="250" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c8" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="160" y="250" as="sourcePoint"/><mxPoint x="1140" y="250" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c9" value="sync calls from the orchestrator (gRPC/HTTP, 2 s deadline, retried with the same key)" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1A73E8;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="360" y="222" width="640" height="17" as="geometry"/></mxCell>
<mxCell id="cart" value="&lt;b&gt;Cart service&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="60" y="330" width="200" height="56" as="geometry"/></mxCell>
<mxCell id="c10" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="160" y="250" as="sourcePoint"/><mxPoint x="160" y="330" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="cartdb" value='&lt;b&gt;Redis&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;key-value, TTL 7 days&lt;/font&gt;' style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=8;strokeColor=#E8710A;fillColor=#FEF1E3;fontSize=12;fontColor=#202124;dashed=0;" vertex="1" parent="1"><mxGeometry x="75" y="430" width="170" height="78" as="geometry"/></mxCell>
<mxCell id="c11" style="edgeStyle=none;html=1;rounded=0;strokeColor=#5F6368;strokeWidth=2;dashed=0;startArrow=block;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="cart" target="cartdb"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c12" value="losing a cart is cheap;&lt;br&gt;speed matters more" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="60" y="518" width="200" height="32" as="geometry"/></mxCell>
<mxCell id="cat" value="&lt;b&gt;Catalog + pricing&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="305" y="330" width="200" height="56" as="geometry"/></mxCell>
<mxCell id="c13" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="405" y="250" as="sourcePoint"/><mxPoint x="405" y="330" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="catdb" value='&lt;b&gt;Document DB&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;+ search index&lt;/font&gt;' style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=8;strokeColor=#E8710A;fillColor=#FEF1E3;fontSize=12;fontColor=#202124;dashed=0;" vertex="1" parent="1"><mxGeometry x="320" y="430" width="170" height="78" as="geometry"/></mxCell>
<mxCell id="c14" style="edgeStyle=none;html=1;rounded=0;strokeColor=#5F6368;strokeWidth=2;dashed=0;startArrow=block;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="cat" target="catdb"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c15" value="flexible attributes,&lt;br&gt;read-heavy, cacheable" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="305" y="518" width="200" height="32" as="geometry"/></mxCell>
<mxCell id="inv" value="&lt;b&gt;Inventory service&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#E8F0FE;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="550" y="330" width="200" height="56" as="geometry"/></mxCell>
<mxCell id="c16" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="650" y="250" as="sourcePoint"/><mxPoint x="650" y="330" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="invdb" value='&lt;b&gt;PostgreSQL&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;stock + reservations&lt;/font&gt;' style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=8;strokeColor=#1E8E3E;fillColor=#E6F4EA;fontSize=12;fontColor=#202124;dashed=0;" vertex="1" parent="1"><mxGeometry x="565" y="430" width="170" height="78" as="geometry"/></mxCell>
<mxCell id="c17" style="edgeStyle=none;html=1;rounded=0;strokeColor=#5F6368;strokeWidth=2;dashed=0;startArrow=block;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="inv" target="invdb"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c18" value="conditional updates,&lt;br&gt;no oversell" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="550" y="518" width="200" height="32" as="geometry"/></mxCell>
<mxCell id="ord" value="&lt;b&gt;Order service&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#E8F0FE;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="795" y="330" width="200" height="56" as="geometry"/></mxCell>
<mxCell id="c19" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="895" y="250" as="sourcePoint"/><mxPoint x="895" y="330" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="orddb" value='&lt;b&gt;PostgreSQL&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;orders + outbox&lt;/font&gt;' style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=8;strokeColor=#1E8E3E;fillColor=#E6F4EA;fontSize=12;fontColor=#202124;dashed=0;" vertex="1" parent="1"><mxGeometry x="810" y="430" width="170" height="78" as="geometry"/></mxCell>
<mxCell id="c20" style="edgeStyle=none;html=1;rounded=0;strokeColor=#5F6368;strokeWidth=2;dashed=0;startArrow=block;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="ord" target="orddb"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c21" value="multi-row ACID,&lt;br&gt;reporting joins" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="795" y="518" width="200" height="32" as="geometry"/></mxCell>
<mxCell id="pay" value="&lt;b&gt;Payment service&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#E8F0FE;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="1040" y="330" width="200" height="56" as="geometry"/></mxCell>
<mxCell id="c22" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1140" y="250" as="sourcePoint"/><mxPoint x="1140" y="330" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="paydb" value='&lt;b&gt;PostgreSQL&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;idempotency keys + ledger&lt;/font&gt;' style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=8;strokeColor=#1E8E3E;fillColor=#E6F4EA;fontSize=12;fontColor=#202124;dashed=0;" vertex="1" parent="1"><mxGeometry x="1055" y="430" width="170" height="78" as="geometry"/></mxCell>
<mxCell id="c23" style="edgeStyle=none;html=1;rounded=0;strokeColor=#5F6368;strokeWidth=2;dashed=0;startArrow=block;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="pay" target="paydb"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c24" value="exactly one charge;&lt;br&gt;audit trail" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1040" y="518" width="200" height="32" as="geometry"/></mxCell>
<mxCell id="bus" value="&lt;b&gt;Event broker   (Kafka, Pub/Sub, Service Bus, EventBridge)&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#E8710A;fillColor=#FEF1E3;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="60" y="630" width="1180" height="50" as="geometry"/></mxCell>
<mxCell id="c25" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="650" y="568" as="sourcePoint"/><mxPoint x="650" y="630" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c26" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="895" y="568" as="sourcePoint"/><mxPoint x="895" y="630" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c27" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1140" y="568" as="sourcePoint"/><mxPoint x="1140" y="630" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c28" value="outbox relay publishes committed rows" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#E8710A;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="520" y="590" width="280" height="17" as="geometry"/></mxCell>
<mxCell id="c29" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="160" y="630" as="sourcePoint"/><mxPoint x="160" y="568" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c30" value="cart cleared on&lt;br&gt;OrderPlaced" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#E8710A;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="60" y="592" width="200" height="32" as="geometry"/></mxCell>
<mxCell id="c0" value='&lt;b&gt;Email + SMS&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;OrderPlaced, PaymentFailed&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="90" y="750" width="240" height="60" as="geometry"/></mxCell>
<mxCell id="c31" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="210" y="680" as="sourcePoint"/><mxPoint x="210" y="750" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c1" value='&lt;b&gt;Fulfilment / WMS&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;OrderConfirmed&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="380" y="750" width="240" height="60" as="geometry"/></mxCell>
<mxCell id="c32" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="500" y="680" as="sourcePoint"/><mxPoint x="500" y="750" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c2" value='&lt;b&gt;Search indexer&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;StockChanged&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="670" y="750" width="240" height="60" as="geometry"/></mxCell>
<mxCell id="c33" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="790" y="680" as="sourcePoint"/><mxPoint x="790" y="750" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c3" value='&lt;b&gt;Analytics&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;every event, for the warehouse&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="960" y="750" width="240" height="60" as="geometry"/></mxCell>
<mxCell id="c34" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1080" y="680" as="sourcePoint"/><mxPoint x="1080" y="750" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c35" value="Consumers dedupe on event id: the broker delivers at least once." style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=12;fontColor=#E8710A;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="90" y="825" width="1150" height="18" as="geometry"/></mxCell>
<mxCell id="psp" value='&lt;b&gt;Payment gateway (PSP)&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;authorize, capture, refund&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#8430CE;fillColor=#F3E8FD;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="1290" y="330" width="190" height="60" as="geometry"/></mxCell>
<mxCell id="c36" style="edgeStyle=none;html=1;rounded=0;strokeColor=#8430CE;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.35;exitDx=0;exitDy=0;entryX=0;entryY=0.35;entryDx=0;entryDy=0;" edge="1" parent="1" source="pay" target="psp"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c37" style="edgeStyle=none;html=1;rounded=0;strokeColor=#8430CE;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0;exitY=0.8;exitDx=0;exitDy=0;entryX=1;entryY=0.8;entryDx=0;entryDy=0;" edge="1" parent="1" source="psp" target="pay"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c38" value="same key on&lt;br&gt;every retry" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#8430CE;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="1240" y="290" width="100" height="32" as="geometry"/></mxCell>
<mxCell id="c39" value="webhook" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#8430CE;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="1238" y="384" width="60" height="17" as="geometry"/></mxCell>
<mxCell id="rec" value='&lt;b&gt;Reconciler&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;hourly: PSP report vs ledger&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#D93025;fillColor=#FCE8E6;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="1290" y="450" width="190" height="60" as="geometry"/></mxCell>
<mxCell id="c40" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=block;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1385" y="390" as="sourcePoint"/><mxPoint x="1385" y="450" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c41" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1290" y="480" as="sourcePoint"/><mxPoint x="1205" y="470" as="targetPoint"/><Array as="points"><mxPoint x="1250" y="480"/><mxPoint x="1250" y="470"/></Array></mxGeometry></mxCell>
<mxCell id="c42" value='fixes "unknown"&lt;br&gt;payments' style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#D93025;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="1300" y="520" width="170" height="32" as="geometry"/></mxCell>
<mxCell id="c43" value="&lt;b&gt;Legend&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#9AA0A6;fillColor=#FFFFFF;dashed=0;fontSize=12;fontStyle=0;fontColor=#3C4043;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="1290" y="640" width="190" height="114" as="geometry"/></mxCell>
<mxCell id="c44" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1304" y="678" as="sourcePoint"/><mxPoint x="1344" y="678" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c45" value="sync call" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#3C4043;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1356" y="671" width="114" height="17" as="geometry"/></mxCell>
<mxCell id="c46" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1304" y="699" as="sourcePoint"/><mxPoint x="1344" y="699" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c47" value="event (async)" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#3C4043;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1356" y="692" width="114" height="17" as="geometry"/></mxCell>
<mxCell id="c48" style="edgeStyle=none;html=1;rounded=0;strokeColor=#8430CE;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1304" y="720" as="sourcePoint"/><mxPoint x="1344" y="720" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c49" value="external PSP" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#3C4043;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1356" y="713" width="114" height="17" as="geometry"/></mxCell>
<mxCell id="c50" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1304" y="741" as="sourcePoint"/><mxPoint x="1344" y="741" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c51" value="repair job" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#3C4043;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1356" y="734" width="114" height="17" as="geometry"/></mxCell></root></mxGraphModel></diagram>
<diagram id="saga" name="2. Checkout saga and compensations"><mxGraphModel dx="1400" dy="900" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1500" pageHeight="760" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="c1" value="The checkout saga: local transactions forward, compensations backward" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=18;fontColor=#232F3E;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="16" width="1300" height="24" as="geometry"/></mxCell>
<mxCell id="c2" value="The orchestrator writes its state before every call, so a crash resumes from the last step instead of starting over." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="44" width="1300" height="18" as="geometry"/></mxCell>
<mxCell id="s1" value='&lt;b&gt;Create order&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;Order service&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;status = PENDING&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#E6F4EA;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="40" y="150" width="200" height="74" as="geometry"/></mxCell>
<mxCell id="c3" value="1" style="ellipse;html=1;fillColor=#1E8E3E;strokeColor=none;fontColor=#FFFFFF;fontStyle=1;fontSize=12;aspect=fixed;" vertex="1" parent="1"><mxGeometry x="32" y="140" width="22" height="22" as="geometry"/></mxCell>
<mxCell id="s2" value='&lt;b&gt;Reserve stock&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;Inventory service&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;hold expires in 15 min&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#E6F4EA;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="284" y="150" width="200" height="74" as="geometry"/></mxCell>
<mxCell id="c4" value="2" style="ellipse;html=1;fillColor=#1E8E3E;strokeColor=none;fontColor=#FFFFFF;fontStyle=1;fontSize=12;aspect=fixed;" vertex="1" parent="1"><mxGeometry x="276" y="140" width="22" height="22" as="geometry"/></mxCell>
<mxCell id="c5" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="s1" target="s2"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="s3" value='&lt;b&gt;Authorize payment&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;Payment service&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;money held, not taken&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#E6F4EA;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="528" y="150" width="200" height="74" as="geometry"/></mxCell>
<mxCell id="c6" value="3" style="ellipse;html=1;fillColor=#1E8E3E;strokeColor=none;fontColor=#FFFFFF;fontStyle=1;fontSize=12;aspect=fixed;" vertex="1" parent="1"><mxGeometry x="520" y="140" width="22" height="22" as="geometry"/></mxCell>
<mxCell id="c7" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="s2" target="s3"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="s4" value='&lt;b&gt;Confirm order&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;Order service&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;status = CONFIRMED&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#E8F0FE;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="772" y="150" width="200" height="74" as="geometry"/></mxCell>
<mxCell id="c8" value="4" style="ellipse;html=1;fillColor=#1A73E8;strokeColor=none;fontColor=#FFFFFF;fontStyle=1;fontSize=12;aspect=fixed;" vertex="1" parent="1"><mxGeometry x="764" y="140" width="22" height="22" as="geometry"/></mxCell>
<mxCell id="c9" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="s3" target="s4"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="s5" value='&lt;b&gt;Commit reservation&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;Inventory service&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;hold becomes allocation&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#E8F0FE;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="1016" y="150" width="200" height="74" as="geometry"/></mxCell>
<mxCell id="c10" value="5" style="ellipse;html=1;fillColor=#1A73E8;strokeColor=none;fontColor=#FFFFFF;fontStyle=1;fontSize=12;aspect=fixed;" vertex="1" parent="1"><mxGeometry x="1008" y="140" width="22" height="22" as="geometry"/></mxCell>
<mxCell id="c11" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="s4" target="s5"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="s6" value='&lt;b&gt;Capture payment&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;Payment service&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;when the parcel ships&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#E8F0FE;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="1260" y="150" width="200" height="74" as="geometry"/></mxCell>
<mxCell id="c12" value="6" style="ellipse;html=1;fillColor=#1A73E8;strokeColor=none;fontColor=#FFFFFF;fontStyle=1;fontSize=12;aspect=fixed;" vertex="1" parent="1"><mxGeometry x="1252" y="140" width="22" height="22" as="geometry"/></mxCell>
<mxCell id="c13" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="s5" target="s6"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c14" style="edgeStyle=none;html=1;rounded=0;strokeColor=#202124;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="750" y="100" as="sourcePoint"/><mxPoint x="750" y="260" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c15" value="PIVOT" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=1;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="710" y="96" width="80" height="18" as="geometry"/></mxCell>
<mxCell id="c16" value="Left of the line: any failure is undone&lt;br&gt;with compensations." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="40" y="98" width="500" height="32" as="geometry"/></mxCell>
<mxCell id="c17" value="Right of the line: no going back. Steps are&lt;br&gt;retried until they succeed (they are idempotent)." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#1A73E8;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="770" y="98" width="520" height="32" as="geometry"/></mxCell>
<mxCell id="k1" value='&lt;b&gt;C1  Cancel order&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;status = CANCELLED, tell shopper&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#D93025;fillColor=#FCE8E6;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="40" y="330" width="200" height="60" as="geometry"/></mxCell>
<mxCell id="c18" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="s1" target="k1"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="k2" value='&lt;b&gt;C2  Release stock&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;reserved -= qty (if still held)&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#D93025;fillColor=#FCE8E6;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="284" y="330" width="200" height="60" as="geometry"/></mxCell>
<mxCell id="c19" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="s2" target="k2"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c20" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="k2" target="k1"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="k3" value='&lt;b&gt;C3  Void authorization&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;only if PSP says AUTHORIZED&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#D93025;fillColor=#FCE8E6;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="528" y="330" width="200" height="60" as="geometry"/></mxCell>
<mxCell id="c21" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="s3" target="k3"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c22" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="k3" target="k2"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c23" value="declined, fraud,&lt;br&gt;or out of retries" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#D93025;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="630" y="250" width="110" height="32" as="geometry"/></mxCell>
<mxCell id="c24" value="Compensations run in reverse order and are idempotent too." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#D93025;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="40" y="405" width="680" height="18" as="geometry"/></mxCell>
<mxCell id="unk" value='&lt;b&gt;Payment timed out?&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;state = PAYMENT_UNKNOWN&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;ask the PSP by idempotency key,&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;then go forward or compensate&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#E8710A;fillColor=#FEF1E3;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="800" y="300" width="300" height="96" as="geometry"/></mxCell>
<mxCell id="c25" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="713" y="224" as="sourcePoint"/><mxPoint x="800" y="348" as="targetPoint"/><Array as="points"><mxPoint x="713" y="285"/><mxPoint x="765" y="285"/><mxPoint x="765" y="348"/></Array></mxGeometry></mxCell>
<mxCell id="c26" value="no answer in 2 s" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#E8710A;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="775" y="262" width="110" height="17" as="geometry"/></mxCell>
<mxCell id="c27" value="&lt;b&gt;Saga state table (checkout DB), the orchestrator's memory&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#FFFFFF;dashed=0;fontSize=12;fontStyle=0;fontColor=#1A73E8;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="40" y="460" width="640" height="200" as="geometry"/></mxCell>
<mxCell id="c28" value="checkout_id" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="55" y="495" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c29" value="step" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="155" y="495" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c30" value="status" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="320" y="495" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c31" value="attempts" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="450" y="495" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c32" value="updated_at" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="530" y="495" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c33" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=1;dashed=0;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="50" y="515" as="sourcePoint"/><mxPoint x="670" y="515" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c34" value="ck_8812" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="55" y="525" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c35" value="AUTHORIZE_PAYMENT" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="155" y="525" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c36" value="IN_PROGRESS" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="320" y="525" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c37" value="2" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="450" y="525" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c38" value="10:41:07.218" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="530" y="525" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c39" value="ck_8813" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="55" y="555" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c40" value="CAPTURE_PAYMENT" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="155" y="555" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c41" value="DONE" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="320" y="555" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c42" value="1" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="450" y="555" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c43" value="10:41:09.004" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="530" y="555" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c44" value="ck_8814" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="55" y="585" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c45" value="RELEASE_STOCK" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="155" y="585" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c46" value="COMPENSATING" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#D93025;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="320" y="585" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c47" value="1" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="450" y="585" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c48" value="10:41:10.551" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="530" y="585" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c49" value="ck_8815" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="55" y="615" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c50" value="AUTHORIZE_PAYMENT" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="155" y="615" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c51" value="UNKNOWN" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#E8710A;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="320" y="615" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c52" value="3" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="450" y="615" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c53" value="10:41:12.930" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="530" y="615" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c54" value="A recovery worker picks up rows stuck IN_PROGRESS for over 30 s and replays that step with the same key." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="55" y="640" width="620" height="16" as="geometry"/></mxCell>
<mxCell id="c55" value="&lt;b&gt;Rules that keep a saga honest&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#202124;fillColor=#FFFFFF;dashed=0;fontSize=12;fontStyle=0;fontColor=#202124;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="720" y="460" width="400" height="200" as="geometry"/></mxCell>
<mxCell id="c56" value="1. Save the step, then call. Never the other way round." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="735" y="495" width="380" height="18" as="geometry"/></mxCell>
<mxCell id="c57" value="2. Every step and compensation is idempotent." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="735" y="521" width="380" height="18" as="geometry"/></mxCell>
<mxCell id="c58" value='3. A timeout is "unknown", not "failed".' style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="735" y="547" width="380" height="18" as="geometry"/></mxCell>
<mxCell id="c59" value="4. Nothing irreversible before the pivot." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="735" y="573" width="380" height="18" as="geometry"/></mxCell>
<mxCell id="c60" value="5. Shoppers see PENDING; email only on CONFIRMED." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="735" y="599" width="380" height="18" as="geometry"/></mxCell>
<mxCell id="c61" value="6. Alert on sagas older than 10 minutes." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="735" y="625" width="380" height="18" as="geometry"/></mxCell>
<mxCell id="c62" value="&lt;b&gt;Legend&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#9AA0A6;fillColor=#FFFFFF;dashed=0;fontSize=12;fontStyle=0;fontColor=#3C4043;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="1160" y="460" width="320" height="114" as="geometry"/></mxCell>
<mxCell id="c63" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1174" y="498" as="sourcePoint"/><mxPoint x="1214" y="498" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c64" value="compensable step" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#3C4043;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1226" y="491" width="244" height="17" as="geometry"/></mxCell>
<mxCell id="c65" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1174" y="519" as="sourcePoint"/><mxPoint x="1214" y="519" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c66" value="retriable step (after pivot)" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#3C4043;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1226" y="512" width="244" height="17" as="geometry"/></mxCell>
<mxCell id="c67" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1174" y="540" as="sourcePoint"/><mxPoint x="1214" y="540" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c68" value="compensation" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#3C4043;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1226" y="533" width="244" height="17" as="geometry"/></mxCell>
<mxCell id="c69" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1174" y="561" as="sourcePoint"/><mxPoint x="1214" y="561" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c70" value="unknown outcome path" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#3C4043;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1226" y="554" width="244" height="17" as="geometry"/></mxCell>
<mxCell id="c71" value="Choreography (services reacting to each other's events) works for 2 or 3 steps. Past that, an orchestrator&lt;br&gt;with a state table is far easier to debug at 3 a.m.: one row tells you where every checkout is." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="40" y="690" width="1100" height="34" as="geometry"/></mxCell></root></mxGraphModel></diagram>
<diagram id="idempotency" name="3. Idempotent payment on retry"><mxGraphModel dx="1400" dy="900" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1500" pageHeight="900" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="c1" value="Scenario: the shopper taps Pay, the network drops the response, the app retries" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=18;fontColor=#232F3E;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="16" width="1300" height="24" as="geometry"/></mxCell>
<mxCell id="c2" value="Without a key this is two charges. With one, the retry gets the first answer back and the PSP is never called twice." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="44" width="1300" height="18" as="geometry"/></mxCell>
<mxCell id="app" value="&lt;b&gt;Shopper app&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="15" y="80" width="190" height="50" as="geometry"/></mxCell>
<mxCell id="c3" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="110" y="130" as="sourcePoint"/><mxPoint x="110" y="860" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="pay" value="&lt;b&gt;Payment service&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#E8F0FE;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="325" y="80" width="190" height="50" as="geometry"/></mxCell>
<mxCell id="c4" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="420" y="130" as="sourcePoint"/><mxPoint x="420" y="860" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="db" value='&lt;b&gt;Payments DB&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;idempotency_keys&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#E6F4EA;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="635" y="80" width="190" height="50" as="geometry"/></mxCell>
<mxCell id="c5" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="730" y="130" as="sourcePoint"/><mxPoint x="730" y="860" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="psp" value="&lt;b&gt;Payment gateway (PSP)&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#8430CE;fillColor=#F3E8FD;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="945" y="80" width="190" height="50" as="geometry"/></mxCell>
<mxCell id="c6" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1040" y="130" as="sourcePoint"/><mxPoint x="1040" y="860" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c7" value="Attempt 1" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="150" width="80" height="18" as="geometry"/></mxCell>
<mxCell id="c8" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="110" y="190" as="sourcePoint"/><mxPoint x="420" y="190" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c9" value="POST /payments  Idempotency-Key: 7f3c-…  £79.99" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1A73E8;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="120" y="158" width="290" height="17" as="geometry"/></mxCell>
<mxCell id="c10" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="420" y="250" as="sourcePoint"/><mxPoint x="730" y="250" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c11" value="INSERT key, request_hash, status=STARTED" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="430" y="218" width="290" height="17" as="geometry"/></mxCell>
<mxCell id="c12" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="730" y="300" as="sourcePoint"/><mxPoint x="420" y="300" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c13" value="inserted (we own this key)" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="430" y="268" width="290" height="17" as="geometry"/></mxCell>
<mxCell id="c14" style="edgeStyle=none;html=1;rounded=0;strokeColor=#8430CE;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="420" y="360" as="sourcePoint"/><mxPoint x="1040" y="360" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c15" value="authorize £79.99, idempotency key 7f3c-…" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#8430CE;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="430" y="328" width="600" height="17" as="geometry"/></mxCell>
<mxCell id="c16" style="edgeStyle=none;html=1;rounded=0;strokeColor=#8430CE;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1040" y="410" as="sourcePoint"/><mxPoint x="420" y="410" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c17" value="AUTHORIZED, auth_id pi_91X" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#8430CE;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="430" y="378" width="600" height="17" as="geometry"/></mxCell>
<mxCell id="c18" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="420" y="470" as="sourcePoint"/><mxPoint x="730" y="470" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c19" value="UPDATE status=SUCCEEDED, response=…" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="430" y="438" width="290" height="17" as="geometry"/></mxCell>
<mxCell id="c20" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="420" y="520" as="sourcePoint"/><mxPoint x="265" y="520" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c21" value="✕" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=18;fontColor=#D93025;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="257" y="509" width="20" height="24" as="geometry"/></mxCell>
<mxCell id="c22" value="201 Created (lost: tunnel, app killed, LB timeout)" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#D93025;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="120" y="526" width="290" height="17" as="geometry"/></mxCell>
<mxCell id="c23" style="edgeStyle=none;html=1;rounded=0;strokeColor=#5F6368;strokeWidth=1;dashed=0;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="20" y="570" as="sourcePoint"/><mxPoint x="1180" y="570" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c24" value="Attempt 2 (app retries 3 s later with the SAME key)" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="580" width="600" height="18" as="geometry"/></mxCell>
<mxCell id="c25" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="110" y="640" as="sourcePoint"/><mxPoint x="420" y="640" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c26" value="POST /payments  Idempotency-Key: 7f3c-…  £79.99" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1A73E8;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="120" y="608" width="290" height="17" as="geometry"/></mxCell>
<mxCell id="c27" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="420" y="700" as="sourcePoint"/><mxPoint x="730" y="700" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c28" value="INSERT … ON CONFLICT DO NOTHING → 0 rows" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="430" y="668" width="290" height="17" as="geometry"/></mxCell>
<mxCell id="c29" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="730" y="750" as="sourcePoint"/><mxPoint x="420" y="750" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c30" value="existing row: SUCCEEDED, same request_hash" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="430" y="718" width="290" height="17" as="geometry"/></mxCell>
<mxCell id="c31" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="420" y="810" as="sourcePoint"/><mxPoint x="110" y="810" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c32" value="201 Created (stored response replayed)" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1A73E8;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="120" y="778" width="290" height="17" as="geometry"/></mxCell>
<mxCell id="c33" value="PSP also dedupes on the key,&lt;br&gt;in case WE retry" style="text;html=1;whiteSpace=wrap;align=right;verticalAlign=top;fontSize=11;fontColor=#8430CE;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="865" y="440" width="165" height="32" as="geometry"/></mxCell>
<mxCell id="nocall" value='&lt;b&gt;PSP not called.&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;One charge.&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#E6F4EA;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="950" y="690" width="180" height="56" as="geometry"/></mxCell>
<mxCell id="c34" value="&lt;b&gt;What the key row decides&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#202124;fillColor=#FFFFFF;dashed=0;fontSize=12;fontStyle=0;fontColor=#202124;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="1200" y="80" width="280" height="330" as="geometry"/></mxCell>
<mxCell id="c35" value="STARTED, under 30 s old" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#E8710A;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="1215" y="116" width="255" height="18" as="geometry"/></mxCell>
<mxCell id="c36" value='409, "still processing,&lt;br&gt;retry in 1 s"' style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1215" y="136" width="255" height="32" as="geometry"/></mxCell>
<mxCell id="c37" value="STARTED, stale" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#E8710A;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="1215" y="188" width="255" height="18" as="geometry"/></mxCell>
<mxCell id="c38" value="take over: ask PSP&lt;br&gt;for key 7f3c-… first" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1215" y="208" width="255" height="32" as="geometry"/></mxCell>
<mxCell id="c39" value="SUCCEEDED / FAILED" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#1E8E3E;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="1215" y="260" width="255" height="18" as="geometry"/></mxCell>
<mxCell id="c40" value="replay stored&lt;br&gt;response as is" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1215" y="280" width="255" height="32" as="geometry"/></mxCell>
<mxCell id="c41" value="same key, different body" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#D93025;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="1215" y="332" width="255" height="18" as="geometry"/></mxCell>
<mxCell id="c42" value="422, key reuse&lt;br&gt;is a client bug" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1215" y="352" width="255" height="32" as="geometry"/></mxCell>
<mxCell id="c43" value="&lt;b&gt;Table&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#FFFFFF;dashed=0;fontSize=12;fontStyle=0;fontColor=#1E8E3E;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="1200" y="430" width="280" height="210" as="geometry"/></mxCell>
<mxCell id="c44" value="CREATE TABLE idempotency_keys (" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="458" width="265" height="16" as="geometry"/></mxCell>
<mxCell id="c45" value="   key text PRIMARY KEY," style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="477" width="265" height="16" as="geometry"/></mxCell>
<mxCell id="c46" value="   merchant_id bigint NOT NULL," style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="496" width="265" height="16" as="geometry"/></mxCell>
<mxCell id="c47" value="   request_hash bytea NOT NULL," style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="515" width="265" height="16" as="geometry"/></mxCell>
<mxCell id="c48" value="   status text NOT NULL," style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="534" width="265" height="16" as="geometry"/></mxCell>
<mxCell id="c49" value="   response jsonb," style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="553" width="265" height="16" as="geometry"/></mxCell>
<mxCell id="c50" value="   locked_at timestamptz," style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="572" width="265" height="16" as="geometry"/></mxCell>
<mxCell id="c51" value="   created_at timestamptz DEFAULT now()" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="591" width="265" height="16" as="geometry"/></mxCell>
<mxCell id="c52" value="); -- keep 24 to 72 h, then purge" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=10;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="610" width="265" height="16" as="geometry"/></mxCell>
<mxCell id="c53" value="&lt;b&gt;Who makes the key?&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#FFFFFF;dashed=0;fontSize=12;fontStyle=0;fontColor=#1A73E8;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="1200" y="660" width="280" height="140" as="geometry"/></mxCell>
<mxCell id="c54" value='The client, once per checkout&lt;br&gt;attempt, before the first tap.&lt;br&gt;Stored with the cart so a reload&lt;br&gt;reuses it. A new key means&lt;br&gt;"I really want to pay again".' style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1212" y="690" width="260" height="82" as="geometry"/></mxCell></root></mxGraphModel></diagram>
<diagram id="inventory" name="4. Inventory reservation without oversell"><mxGraphModel dx="1400" dy="900" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1500" pageHeight="900" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="c1" value="Scenario: one unit left, two shoppers press Pay 40 ms apart" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=18;fontColor=#232F3E;fontStyle=1;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="16" width="1300" height="24" as="geometry"/></mxCell>
<mxCell id="c2" value="Read-then-write lets both win. One conditional UPDATE lets exactly one win, and a reservation with an expiry gives the stock back if checkout dies." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="20" y="44" width="1400" height="18" as="geometry"/></mxCell>
<mxCell id="c3" value="&lt;b&gt;Wrong: read, check in code, then write&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#D93025;fillColor=#FFFBFA;dashed=0;fontSize=12;fontStyle=0;fontColor=#D93025;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="20" y="80" width="700" height="440" as="geometry"/></mxCell>
<mxCell id="a" value="&lt;b&gt;Shopper A&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="60" y="115" width="160" height="46" as="geometry"/></mxCell>
<mxCell id="c4" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="140" y="161" as="sourcePoint"/><mxPoint x="140" y="445" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="row" value="&lt;b&gt;stock row sku-123&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#E6F4EA;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="290" y="115" width="160" height="46" as="geometry"/></mxCell>
<mxCell id="c5" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="370" y="161" as="sourcePoint"/><mxPoint x="370" y="445" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="b" value="&lt;b&gt;Shopper B&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="520" y="115" width="160" height="46" as="geometry"/></mxCell>
<mxCell id="c6" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="600" y="161" as="sourcePoint"/><mxPoint x="600" y="445" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c7" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="140" y="200" as="sourcePoint"/><mxPoint x="370" y="200" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c8" value="SELECT available → 1" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1A73E8;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="146" y="174" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="c9" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="600" y="245" as="sourcePoint"/><mxPoint x="370" y="245" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c10" value="SELECT available → 1" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1A73E8;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="376" y="219" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="c11" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="140" y="300" as="sourcePoint"/><mxPoint x="370" y="300" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c12" value="UPDATE available = 0" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#D93025;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="146" y="274" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="c13" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="600" y="345" as="sourcePoint"/><mxPoint x="370" y="345" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c14" value="UPDATE available = 0" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#D93025;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="376" y="319" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="c15" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="370" y="400" as="sourcePoint"/><mxPoint x="140" y="400" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c16" value="order placed" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="146" y="374" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="c17" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="370" y="400" as="sourcePoint"/><mxPoint x="600" y="400" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c18" value="order placed" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="376" y="374" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="bad" value='&lt;b&gt;2 orders, 1 unit. Someone gets a "sorry" email.&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;Raising the isolation level to SERIALIZABLE fixes it&lt;/font&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;but aborts and retries under load.&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#D93025;fillColor=#FCE8E6;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="70" y="455" width="600" height="56" as="geometry"/></mxCell>
<mxCell id="c19" value="&lt;b&gt;Right: let the database do the check, atomically&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#FAFFFB;dashed=0;fontSize=12;fontStyle=0;fontColor=#1E8E3E;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="780" y="80" width="700" height="440" as="geometry"/></mxCell>
<mxCell id="a2" value="&lt;b&gt;Shopper A&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="820" y="115" width="160" height="46" as="geometry"/></mxCell>
<mxCell id="c20" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="900" y="161" as="sourcePoint"/><mxPoint x="900" y="365" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="row2" value="&lt;b&gt;stock row sku-123&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#E6F4EA;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="1050" y="115" width="160" height="46" as="geometry"/></mxCell>
<mxCell id="c21" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1130" y="161" as="sourcePoint"/><mxPoint x="1130" y="365" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="b2" value="&lt;b&gt;Shopper B&lt;/b&gt;" style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="1280" y="115" width="160" height="46" as="geometry"/></mxCell>
<mxCell id="c22" style="edgeStyle=none;html=1;rounded=0;strokeColor=#BDC1C6;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1360" y="161" as="sourcePoint"/><mxPoint x="1360" y="365" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c23" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="900" y="200" as="sourcePoint"/><mxPoint x="1130" y="200" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c24" value="UPDATE … WHERE on_hand - reserved &amp;gt;= 1" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="906" y="174" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="c25" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1130" y="245" as="sourcePoint"/><mxPoint x="900" y="245" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c26" value="1 row: reserved" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="906" y="219" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="c27" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1360" y="300" as="sourcePoint"/><mxPoint x="1130" y="300" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c28" value="same UPDATE (waits on row lock)" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1A73E8;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="1136" y="274" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="c29" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1130" y="345" as="sourcePoint"/><mxPoint x="1360" y="345" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c30" value="0 rows: sold out" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#E8710A;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="1136" y="319" width="218" height="17" as="geometry"/></mxCell>
<mxCell id="c31" value="&lt;b&gt;&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#FFFFFF;dashed=0;fontSize=12;fontStyle=0;fontColor=#3C4043;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="800" y="380" width="660" height="132" as="geometry"/></mxCell>
<mxCell id="c32" value="BEGIN;" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="812" y="386" width="640" height="17" as="geometry"/></mxCell>
<mxCell id="c33" value="UPDATE stock SET reserved = reserved + :qty" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="812" y="403" width="640" height="17" as="geometry"/></mxCell>
<mxCell id="c34" value=" WHERE sku = :sku AND on_hand - reserved &amp;gt;= :qty;" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="812" y="420" width="640" height="17" as="geometry"/></mxCell>
<mxCell id="c35" value="-- 0 rows? ROLLBACK, tell the shopper it sold out" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="812" y="437" width="640" height="17" as="geometry"/></mxCell>
<mxCell id="c36" value="INSERT INTO reservations (id, sku, qty, checkout_id, expires_at)" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="812" y="454" width="640" height="17" as="geometry"/></mxCell>
<mxCell id="c37" value=" VALUES (:id, :sku, :qty, :ck, now() + interval '15 min');" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="812" y="471" width="640" height="17" as="geometry"/></mxCell>
<mxCell id="c38" value="COMMIT;" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="812" y="488" width="640" height="17" as="geometry"/></mxCell>
<mxCell id="c39" value="&lt;b&gt;Reservation lifecycle&lt;/b&gt;" style="rounded=1;arcSize=8;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#FFFFFF;dashed=0;fontSize=12;fontStyle=0;fontColor=#1A73E8;align=left;verticalAlign=top;spacingLeft=8;" vertex="1" parent="1"><mxGeometry x="20" y="550" width="1460" height="320" as="geometry"/></mxCell>
<mxCell id="av" value='&lt;b&gt;Available&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;on_hand - reserved&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#5F6368;fillColor=#F1F3F4;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="50" y="650" width="170" height="60" as="geometry"/></mxCell>
<mxCell id="held" value='&lt;b&gt;HELD&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;expires_at = now() + 15 min&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#E8710A;fillColor=#FEF1E3;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="330" y="650" width="220" height="60" as="geometry"/></mxCell>
<mxCell id="com" value='&lt;b&gt;COMMITTED&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;on_hand -= qty, reserved -= qty&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1E8E3E;fillColor=#E6F4EA;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="700" y="600" width="260" height="60" as="geometry"/></mxCell>
<mxCell id="ship" value='&lt;b&gt;SHIPPED&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;pick, pack, capture payment&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#1A73E8;fillColor=#E8F0FE;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="1080" y="600" width="240" height="60" as="geometry"/></mxCell>
<mxCell id="rel" value='&lt;b&gt;RELEASED&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;reserved -= qty&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#D93025;fillColor=#FCE8E6;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="700" y="700" width="260" height="56" as="geometry"/></mxCell>
<mxCell id="exp" value='&lt;b&gt;EXPIRED&lt;/b&gt;&lt;br&gt;&lt;font style="font-size:10px" color="#5F6368"&gt;reserved -= qty&lt;/font&gt;' style="rounded=1;arcSize=10;html=1;whiteSpace=wrap;strokeColor=#D93025;fillColor=#FCE8E6;strokeWidth=1.5;dashed=0;fontSize=12;fontColor=#202124;align=center;verticalAlign=middle;" vertex="1" parent="1"><mxGeometry x="700" y="790" width="260" height="56" as="geometry"/></mxCell>
<mxCell id="c40" style="edgeStyle=none;html=1;rounded=0;strokeColor=#E8710A;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="av" target="held"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c41" value="reserve (step 2)" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#E8710A;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="225" y="655" width="100" height="17" as="geometry"/></mxCell>
<mxCell id="c42" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1E8E3E;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.3;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="held" target="com"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c43" value="order confirmed (step 5)" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#1E8E3E;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="545" y="585" width="140" height="17" as="geometry"/></mxCell>
<mxCell id="c44" style="edgeStyle=none;html=1;rounded=0;strokeColor=#1A73E8;strokeWidth=2;dashed=0;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="com" target="ship"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c45" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=1;exitY=0.7;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="held" target="rel"><mxGeometry relative="1" as="geometry"></mxGeometry></mxCell>
<mxCell id="c46" value="payment failed (C2)" style="text;html=1;whiteSpace=wrap;align=center;verticalAlign=top;fontSize=11;fontColor=#D93025;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="565" y="705" width="130" height="17" as="geometry"/></mxCell>
<mxCell id="c47" style="edgeStyle=none;html=1;rounded=0;strokeColor=#D93025;strokeWidth=2;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="held" target="exp"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="440" y="818"/></Array></mxGeometry></mxCell>
<mxCell id="c48" value="sweeper, every minute:&lt;br&gt;expires_at &amp;lt; now() AND status = HELD" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#D93025;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="345" y="760" width="250" height="32" as="geometry"/></mxCell>
<mxCell id="c49" style="edgeStyle=none;html=1;rounded=0;strokeColor=#5F6368;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=block;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="960" y="728" as="sourcePoint"/><mxPoint x="100" y="710" as="targetPoint"/><Array as="points"><mxPoint x="1000" y="728"/><mxPoint x="1000" y="855"/><mxPoint x="100" y="855"/></Array></mxGeometry></mxCell>
<mxCell id="c50" style="edgeStyle=none;html=1;rounded=0;strokeColor=#5F6368;strokeWidth=1.5;dashed=1;startArrow=none;startFill=1;endArrow=none;endFill=1;endSize=4;startSize=4;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="960" y="818" as="sourcePoint"/><mxPoint x="1000" y="818" as="targetPoint"/></mxGeometry></mxCell>
<mxCell id="c51" value="stock returns to the pool" style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=11;fontColor=#5F6368;fontStyle=0;spacing=0;labelBackgroundColor=#FFFFFF;" vertex="1" parent="1"><mxGeometry x="1010" y="770" width="160" height="17" as="geometry"/></mxCell>
<mxCell id="c52" value="Release and expiry both use&lt;br&gt;WHERE status = 'HELD', so&lt;br&gt;they can race safely: only one&lt;br&gt;of them changes the row." style="text;html=1;whiteSpace=wrap;align=left;verticalAlign=top;fontSize=12;fontColor=#202124;fontStyle=0;spacing=0;" vertex="1" parent="1"><mxGeometry x="1210" y="690" width="260" height="66" as="geometry"/></mxCell></root></mxGraphModel></diagram>
</mxfile>
