[{"data":1,"prerenderedAt":352},["ShallowReactive",2],{"tag-labels":3,"site-header":4,"article-the-answer-make-the-two-rules-agree-en":75},{},{"featuredPost":5,"navigations":29},{"id":6,"title":7,"title_id":8,"slug":9,"excerpt":10,"excerpt_id":11,"has_translation":12,"published_at":13,"reading_time":14,"hidden_from_listing":15,"tags":16,"thumbnail_image":21,"og_image":22,"series":23,"authors":28},110,"When You Pick a Framework Just to Look Different","Ketika Pilih Framework Cuma Biar Kelihatan Beda","ketika-pilih-framework-cuma-biar-kelihatan-beda","The last time you chose a new framework or library, was it because your problem needed that tool, or because it sounded cool and few people around you were using it? That question is uncomfortable. Technology decisions are often made for reasons that never appear in any technical document.","Terakhir kali kamu milih framework atau library baru, itu karena masalahmu butuh alat itu, atau karena alatnya kedengaran keren dan belum banyak yang pakai? Pertanyaan ini nggak enak dijawab. Soalnya keputusan teknologi sering diambil dengan alasan yang nggak pernah ditulis di dokumen teknis mana pun.",true,"2026-10-06T15:25:21.000Z",5,false,[17,18,19,20],"karier","framework","opini","pengalaman",null,"\u002Fog\u002Fketika-pilih-framework-cuma-biar-kelihatan-beda.png",{"id":24,"title":25,"title_id":26,"slug":27},9,"Articles","Artikel","all",[],[30,49,70],{"collection":31,"item":32},"series",{"__typename":31,"title":25,"title_id":26,"slug":27,"children_series":33},[34,38,42,46],{"title":35,"title_id":36,"slug":37},"Artificial Intelligence","Kecerdasan Artifisial","kecerdasan-artifisial",{"title":39,"title_id":40,"slug":41},"Programming Fundamentals","Konsep Dasar Pemrograman","konsep-dasar-pemrograman",{"title":43,"title_id":44,"slug":45},"Algorithms and Data Structures","Algoritma dan Struktur Data","algoritma-struktur-data",{"title":47,"title_id":47,"slug":48},"LLM Systems","llm-systems",{"collection":31,"item":50},{"__typename":31,"title":51,"title_id":51,"slug":52,"children_series":53},"Tutorial","tutorial",[54,58,62,66],{"title":55,"title_id":56,"slug":57},"Learning Python","Belajar Python","belajar-python",{"title":59,"title_id":60,"slug":61},"Learning Go","Belajar Golang","belajar-golang",{"title":63,"title_id":64,"slug":65},"Learning Java","Belajar Java","belajar-java",{"title":67,"title_id":68,"slug":69},"Learning Pascal","Belajar Pascal","belajar-pascal",{"collection":31,"item":71},{"__typename":31,"title":72,"title_id":72,"slug":73,"children_series":74},"Lab","lab",[],{"article":76,"renderedBody":235,"renderedTakeaway":236,"latestArticles":237,"toc":332},{"id":77,"title":78,"title_id":79,"slug":80,"excerpt":81,"excerpt_id":82,"has_translation":12,"published_at":83,"reading_time":14,"hidden_from_listing":12,"tags":84,"thumbnail_image":21,"og_image":88,"series":89,"authors":226,"seoTitle":21,"seoDescription":21,"body_locale":229,"available_locales":230,"body":232,"takeway":233,"prerequisite":234},153,"The Answer: Make the Two Rules Agree","Jawaban: Bikin Dua Aturannya Sepakat","the-answer-make-the-two-rules-agree","Three independent fixes, measured one at a time. The one you reach for first makes the log quiet and leaves the product on sale, and that is the most useful row in the table.","Tiga perbaikan independen, diukur satu per satu. Yang pertama kamu jangkau bikin log sunyi dan produknya tetap dijual: itu baris paling berguna di tabelnya.","2026-12-01T01:00:00.000Z",[85,86,87,73],"webhook","event-driven","distributed-systems","\u002Fog\u002Fthe-answer-make-the-two-rules-agree.png",{"id":90,"title":72,"title_id":72,"slug":73,"description":91,"description_id":92,"articles":93,"children_series":225,"parent_series":21},29,"Practice labs: work the problem first, then read the answer. Every lab ships with a repo you can clone, production-sized data, and a target you have to hit yourself. The write-up lives in this series too, and it only opens from the problem article.","Lab praktik: kerjakan masalahnya dulu, baru lihat jawabannya. Tiap lab punya repo yang bisa di-clone, data seukuran produksi, dan target yang harus kamu capai sendiri. Artikel jawabannya ada di seri ini juga, dan cuma bisa kamu buka dari artikel masalahnya.",[94,115,132,148,165,180,197,210],{"id":95,"title":96,"title_id":97,"slug":98,"excerpt":99,"excerpt_id":100,"has_translation":12,"published_at":101,"reading_time":14,"hidden_from_listing":15,"tags":102,"thumbnail_image":21,"og_image":106,"series":107,"authors":108},104,"N+1 Was Never the Bottleneck: 41 Queries Down to 2, Still One Second","Query-nya Tinggal 2, Tapi Response-nya Masih 1 Detik","query-tinggal-2-tapi-response-masih-1-detik","A feed endpoint that shows 20 posts takes a full second and hits the database with 41 queries. Apply the standard N+1 advice, get it down to 2 queries, and the latency does not move. This is that problem as it happened, plus the lab.","Endpoint feed yang cuma menampilkan 20 tulisan butuh satu detik, dan server database dihujani 41 query. Kamu kerjakan nasihat N+1 yang standar, query-nya turun jadi 2, dan latency-nya nggak bergerak. Ini versi \"apa adanya\" dari masalah itu, plus lab-nya.","2026-10-04T09:59:21.000Z",[103,104,105],"database","performance","backend","\u002Fog\u002Fquery-tinggal-2-tapi-response-masih-1-detik.png",{"id":90,"title":72,"title_id":72,"slug":73},[109],{"authors_id":110},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},1,"Daffa Izzuddin","izzudd","Writer",{"id":116,"title":117,"title_id":118,"slug":119,"excerpt":120,"excerpt_id":121,"has_translation":12,"published_at":122,"reading_time":123,"hidden_from_listing":15,"tags":124,"thumbnail_image":21,"og_image":127,"series":128,"authors":129},114,"One Payment, Four Ledger Rows: An Idempotency Lab","Saldo Naik Empat Kali untuk Satu Pembayaran","saldo-naik-empat-kali-untuk-satu-pembayaran","The code is not wrong and the gateway is not wrong, yet one payment shows up four times in the ledger. Guess why, then make `make check` green in the lab.","Kodenya nggak salah, dan gateway-nya juga nggak salah. Tapi satu pembayaran muncul empat kali di ledger. Coba tebak kenapa — lalu bikin `make check` hijau di lab-nya.","2026-10-11T13:45:00.000Z",4,[125,85,126,103,73],"idempotency","postgres","\u002Fog\u002Fsaldo-naik-empat-kali-untuk-satu-pembayaran.png",{"id":90,"title":72,"title_id":72,"slug":73},[130],{"authors_id":131},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":133,"title":134,"title_id":135,"slug":136,"excerpt":137,"excerpt_id":138,"has_translation":12,"published_at":139,"reading_time":140,"hidden_from_listing":15,"tags":141,"thumbnail_image":21,"og_image":143,"series":144,"authors":145},116,"The Webhook Arrived Late. The Reconciliation Job Had Already Run.","Webhook-nya Telat, Job Rekonsiliasinya Keburu Jalan","webhook-telat-job-rekonsiliasi-keburu-jalan","The webhook path is already idempotent. Then a morning reconciliation job appears, and one payment gets recorded twice from two paths that are both right. Guess where the key is wrong.","Jalur webhook sudah idempotent. Lalu ada job rekonsiliasi pagi, dan satu pembayaran tercatat dua kali dari dua jalur yang dua-duanya benar. Coba tebak kuncinya salah di mana.","2026-10-11T13:44:00.000Z",3,[125,142,85,126,73],"reconciliation","\u002Fog\u002Fwebhook-telat-job-rekonsiliasi-keburu-jalan.png",{"id":90,"title":72,"title_id":72,"slug":73},[146],{"authors_id":147},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":149,"title":150,"title_id":151,"slug":152,"excerpt":153,"excerpt_id":154,"has_translation":12,"published_at":155,"reading_time":123,"hidden_from_listing":15,"tags":156,"thumbnail_image":21,"og_image":160,"series":161,"authors":162},120,"Every Receipt in This Café Lists the Same Order","Tiap Nota di Kafe Ini Isinya Pesanan yang Sama","tiap-nota-isinya-pesanan-yang-sama","Every table's receipt holds the same items, and the total is Rp0, even though each table ordered exactly one thing. Guess why, then make `make check` green. A Python scope and mutation lab.","Nota tiap meja isinya sama semua, dan totalnya Rp0 — padahal tiap meja cuma pesan satu barang. Coba tebak kenapa.","2026-10-11T23:00:15.000Z",[157,158,159,73],"python","scope","mutasi","\u002Fog\u002Ftiap-nota-isinya-pesanan-yang-sama.png",{"id":90,"title":72,"title_id":72,"slug":73},[163],{"authors_id":164},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":166,"title":167,"title_id":168,"slug":169,"excerpt":170,"excerpt_id":171,"has_translation":12,"published_at":155,"reading_time":123,"hidden_from_listing":15,"tags":172,"thumbnail_image":21,"og_image":175,"series":176,"authors":177},122,"A Script That Cannot Say Where It Went Wrong","Script yang Nggak Bisa Bilang di Mana Salahnya","script-yang-tidak-bilang-di-mana-salahnya","A script that stops at the first bad line reports only part of the problem. This is what shows up on screen right now.","Script yang berhenti di baris jelek pertama cuma melaporkan sebagian masalah yang ada. Ini yang muncul di layar sekarang.",[157,173,174,73],"error-handling","validasi","\u002Fog\u002Fscript-yang-tidak-bilang-di-mana-salahnya.png",{"id":90,"title":72,"title_id":72,"slug":73},[178],{"authors_id":179},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":181,"title":182,"title_id":183,"slug":184,"excerpt":185,"excerpt_id":186,"has_translation":12,"published_at":187,"reading_time":140,"hidden_from_listing":15,"tags":188,"thumbnail_image":21,"og_image":192,"series":193,"authors":194},141,"A 6,000-Token Handbook and a 0% Cache Hit Rate","Buku Panduan 6.000 Token dan Hit Rate Cache 0%","cache-hit-rate-zero","Twenty-four turns, caching switched on, and a bill 21% higher than running with no cache at all. A support agent whose prompt looks static, and the three lines that quietly change it every turn.","Dua puluh empat giliran, caching menyala, dan tagihan 21% lebih tinggi daripada menjalankannya tanpa cache sama sekali. Agen support yang prompt-nya kelihatan statis, dan tiga baris yang diam-diam mengubahnya tiap giliran.","2026-11-08T01:20:00.000Z",[73,189,190,191],"llm","cache","api","\u002Fog\u002Fcache-hit-rate-zero.png",{"id":90,"title":72,"title_id":72,"slug":73},[195],{"authors_id":196},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":198,"title":199,"title_id":200,"slug":201,"excerpt":202,"excerpt_id":203,"has_translation":12,"published_at":83,"reading_time":14,"hidden_from_listing":15,"tags":204,"thumbnail_image":21,"og_image":205,"series":206,"authors":207},152,"Every Write Comes Back as News","Tiap Write Balik ke Kamu sebagai Kabar Baru","every-write-comes-back-as-news","A supplier file says the mug is gone, the app drafts it, the store puts it back, forty times. Seven checks, and the eager webhook handler is only the second problem.","File supplier bilang mug-nya habis, app bikin draft, store mengembalikannya, 40 kali. Tujuh pemeriksaan, handler webhook yang sigap cuma masalah kedua.",[85,86,87,73],"\u002Fog\u002Fevery-write-comes-back-as-news.png",{"id":90,"title":72,"title_id":72,"slug":73},[208],{"authors_id":209},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":211,"title":212,"title_id":213,"slug":214,"excerpt":215,"excerpt_id":216,"has_translation":12,"published_at":217,"reading_time":218,"hidden_from_listing":15,"tags":219,"thumbnail_image":21,"og_image":220,"series":221,"authors":222},155,"Stock Says Four, the Shelf Says Six","Stok Bilang Empat, Raknya Bilang Enam","stock-says-four-the-shelf-says-six","Eleven stock messages, three of them out of order: the mug reads four while six sit on the shelf, and the cap counted at zero still sold. Five checks, one guard.","Sebelas pesan stok, tiga di antaranya datang tidak berurutan: mug terbaca empat sementara enam ada di rak, dan topi yang dihitung nol tetap terjual. Lima pemeriksaan, satu penjaga.","2026-11-13T01:00:00.000Z",6,[73,86,87],"\u002Fog\u002Fstock-says-four-the-shelf-says-six.png",{"id":90,"title":72,"title_id":72,"slug":73},[223],{"authors_id":224},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},[],[227],{"authors_id":228},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},"en",[229,231],"id","\nThe first fix most people write turns two checks green, quiets the log, and still leaves the mug on\nsale. If you stop there, the output looks solved while the core bug remains.\n\n## Measurements\n\nEach row is one edit applied alone to the starter, then `make check`. Nothing is estimated:\n\n| applied | green | what the detail says |\n|---|---|---|\n| starter, unchanged | none | `0\u002F7` |\n| 1. send only what differs | D, G | `2\u002F7`; A still `status=ACTIVE after 40 writes`, C still throttles MUG-01 |\n| 2. own both fields | A | `1\u002F7`; F turns into `out: DRAFT\u002F0, back: DRAFT\u002F0` |\n| 3. decide from the newest answer | E | `1\u002F7`; G still `39 redundant of 160 writes` |\n| all three | A–G | `7\u002F7`; `writes=2  throttled=0`, `0 redundant of 5 writes` |\n\nThree disjoint sets: {D, G}, {A}, {E}. B, C and F need the first two together, because the loop has to\nstop before a second phase can even be measured.\n\n## 1. Send only what differs\n\nThe starter's worker writes whatever the app wants, every time:\n\n```python\nlive = store.get(gid)\nstore.write(gid, **desired(job, live))\nwrites += 1\n```\n\nIt looks right because `live` is fetched and passed in. It is fetched and then ignored. The store\naccepts a write that repeats the value it already has, and fires `products\u002Fupdate` for it anyway, so\nevery redundant write generates a new event and runs the handler again.\n\n```python\nchanges = {\n    field: value\n    for field, value in desired(job, live).items()\n    if live.get(field) != value\n}\nif not changes:\n    continue\n```\n\nD and G go green, while A still fails with `status=ACTIVE after 40 writes`. The diff removes redundant\nwrites, yet the app and the store automation still flip the product back and forth.\n\n## 2. Own both fields, or neither\n\nThe store's automation reads `inventory_quantity`. The app writes `status`. The app is making an\nargument it cannot win, because the field that decides the argument is not in its payload:\n\n```python\ndef desired(job: Job, live: dict) -> dict:\n    return {\"status\": \"DRAFT\" if not job.available else \"ACTIVE\"}\n```\n\nThe fix is to satisfy the other side's invariant instead of contradicting it. A draft has to mean no\nstock on hand, so drafting is a two-field write:\n\n```python\nif not feed.available(sku_of(gid)):\n    if live[\"inventory_quantity\"] > 0:\n        _STOCK[gid] = live[\"inventory_quantity\"]\n    return {\"status\": \"DRAFT\", \"inventory_quantity\": 0}\n```\n\nNow the automation has nothing to object to, the webhook the app receives says what the app already\nbelieves, and there is no next write to make. A goes green.\n\nF does not, and it gets worse before it gets better: `out: DRAFT\u002F0, back: DRAFT\u002F0`. The product is\ncorrectly drafted and now permanently unsellable, because the stock it had is gone and nothing\nremembers it. That is why `_STOCK` exists in the fix: without it, drafting a product permanently loses\nits inventory count.\n\n## 3. Decide from the newest answer\n\nThe starter's handler queues the first event and drops the rest:\n\n```python\nif gid in queue:\n    return\nqueue[gid] = Job(gid=gid, available=feed.available(sku_of(gid)))\n```\n\nThat guard drops burst traffic at the cost of keeping stale data: five supplier updates arriving before\nthe worker runs collapse to the first, so the app acts on the oldest answer. Two changes fix it:\n\n```python\nqueue[gid] = Job(gid=gid)          # the newest event wins\n...\nreturn {\"status\": \"DRAFT\" if not feed.available(sku_of(job.gid)) else \"ACTIVE\"}\n```\n\nCoalesce toward the newest, and read the input when the job runs rather than when the event arrived.\nE goes green.\n\n## What the lab still does not teach\n\nThe lab runs on one thread with one queue, so it never exercises concurrency. In production, this bug\nclass also requires one lane per product so two workers cannot interleave writes to the same object,\neven though adding locking here will not change a single check.\n\nThe forty-write cap is also a harness convenience that turns a hang into a readable log. A real store\ncharges query cost against a shared budget, so a looping sync on one product starves every other API\ncall the app makes for that merchant.\n\n## Before you ship\n\nBecause the three fixes are independent, you can ship them in any order and get partial green checks.\nDiffing first is cheap and misleading, so you need a check that verifies final product state rather than\nwrite volume alone. Beyond this lab, map every field the other system's automation reads so both sides\nagree on the same state.\n","- Diffing before writing is necessary and not sufficient: it fixes the log and leaves the field wrong.\n- The app has to own every field the other side's rule reads, or it owns neither.\n- Drafting a product without zeroing its stock moves the failure from 'still on sale' to 'never coming back'.\n- Coalescing a queue keeps the newest event, not the first, and reads the input when the job runs.\n- Each fix moves a disjoint set of checks, which is why the table has five rows instead of two.",{"id":198,"title":199,"slug":201},"\u003Cp>The first fix most people write turns two checks green, quiets the log, and still leaves the mug on\nsale. If you stop there, the output looks solved while the core bug remains.\u003C\u002Fp>\n\u003Ch2 id=\"measurements\">Measurements\u003C\u002Fh2>\n\u003Cp>Each row is one edit applied alone to the starter, then \u003Ccode>make check\u003C\u002Fcode>. Nothing is estimated:\u003C\u002Fp>\n\u003Ctable>\n\u003Cthead>\n\u003Ctr>\n\u003Cth>applied\u003C\u002Fth>\n\u003Cth>green\u003C\u002Fth>\n\u003Cth>what the detail says\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\u003Ctr>\n\u003Ctd>starter, unchanged\u003C\u002Ftd>\n\u003Ctd>none\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>0\u002F7\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>1. send only what differs\u003C\u002Ftd>\n\u003Ctd>D, G\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>2\u002F7\u003C\u002Fcode>; A still \u003Ccode>status=ACTIVE after 40 writes\u003C\u002Fcode>, C still throttles MUG-01\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>2. own both fields\u003C\u002Ftd>\n\u003Ctd>A\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>1\u002F7\u003C\u002Fcode>; F turns into \u003Ccode>out: DRAFT\u002F0, back: DRAFT\u002F0\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>3. decide from the newest answer\u003C\u002Ftd>\n\u003Ctd>E\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>1\u002F7\u003C\u002Fcode>; G still \u003Ccode>39 redundant of 160 writes\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>all three\u003C\u002Ftd>\n\u003Ctd>A–G\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>7\u002F7\u003C\u002Fcode>; \u003Ccode>writes=2  throttled=0\u003C\u002Fcode>, \u003Ccode>0 redundant of 5 writes\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftbody>\u003C\u002Ftable>\n\u003Cp>Three disjoint sets: {D, G}, {A}, {E}. B, C and F need the first two together, because the loop has to\nstop before a second phase can even be measured.\u003C\u002Fp>\n\u003Ch2 id=\"1-send-only-what-differs\">1. Send only what differs\u003C\u002Fh2>\n\u003Cp>The starter&#39;s worker writes whatever the app wants, every time:\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">PYTHON\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"live%20%3D%20store.get(gid)%0Astore.write(gid%2C%20**desired(job%2C%20live))%0Awrites%20%2B%3D%201\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">live \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> store.get(gid)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">store.write(gid, \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">**\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">desired(job, live))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">writes \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 1\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>It looks right because \u003Ccode>live\u003C\u002Fcode> is fetched and passed in. It is fetched and then ignored. The store\naccepts a write that repeats the value it already has, and fires \u003Ccode>products\u002Fupdate\u003C\u002Fcode> for it anyway, so\nevery redundant write generates a new event and runs the handler again.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">PYTHON\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"changes%20%3D%20%7B%0A%20%20%20%20field%3A%20value%0A%20%20%20%20for%20field%2C%20value%20in%20desired(job%2C%20live).items()%0A%20%20%20%20if%20live.get(field)%20!%3D%20value%0A%7D%0Aif%20not%20changes%3A%0A%20%20%20%20continue\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">changes \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    field: value\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    for\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> field, value \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">in\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> desired(job, live).items()\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    if\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> live.get(field) \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">!=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> value\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">if\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> not\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> changes:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    continue\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>D and G go green, while A still fails with \u003Ccode>status=ACTIVE after 40 writes\u003C\u002Fcode>. The diff removes redundant\nwrites, yet the app and the store automation still flip the product back and forth.\u003C\u002Fp>\n\u003Ch2 id=\"2-own-both-fields-or-neither\">2. Own both fields, or neither\u003C\u002Fh2>\n\u003Cp>The store&#39;s automation reads \u003Ccode>inventory_quantity\u003C\u002Fcode>. The app writes \u003Ccode>status\u003C\u002Fcode>. The app is making an\nargument it cannot win, because the field that decides the argument is not in its payload:\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">PYTHON\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"def%20desired(job%3A%20Job%2C%20live%3A%20dict)%20-%3E%20dict%3A%0A%20%20%20%20return%20%7B%22status%22%3A%20%22DRAFT%22%20if%20not%20job.available%20else%20%22ACTIVE%22%7D\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">def\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> desired\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(job: Job, live: \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">dict\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">) -> \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">dict\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    return\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"status\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"DRAFT\"\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> if\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> not\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> job.available \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">else\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"ACTIVE\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>The fix is to satisfy the other side&#39;s invariant instead of contradicting it. A draft has to mean no\nstock on hand, so drafting is a two-field write:\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">PYTHON\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"if%20not%20feed.available(sku_of(gid))%3A%0A%20%20%20%20if%20live%5B%22inventory_quantity%22%5D%20%3E%200%3A%0A%20%20%20%20%20%20%20%20_STOCK%5Bgid%5D%20%3D%20live%5B%22inventory_quantity%22%5D%0A%20%20%20%20return%20%7B%22status%22%3A%20%22DRAFT%22%2C%20%22inventory_quantity%22%3A%200%7D\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">if\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> not\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> feed.available(sku_of(gid)):\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    if\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> live[\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"inventory_quantity\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">] \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">>\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">        _STOCK\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">[gid] \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> live[\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"inventory_quantity\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">]\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    return\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"status\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"DRAFT\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"inventory_quantity\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">0\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>Now the automation has nothing to object to, the webhook the app receives says what the app already\nbelieves, and there is no next write to make. A goes green.\u003C\u002Fp>\n\u003Cp>F does not, and it gets worse before it gets better: \u003Ccode>out: DRAFT\u002F0, back: DRAFT\u002F0\u003C\u002Fcode>. The product is\ncorrectly drafted and now permanently unsellable, because the stock it had is gone and nothing\nremembers it. That is why \u003Ccode>_STOCK\u003C\u002Fcode> exists in the fix: without it, drafting a product permanently loses\nits inventory count.\u003C\u002Fp>\n\u003Ch2 id=\"3-decide-from-the-newest-answer\">3. Decide from the newest answer\u003C\u002Fh2>\n\u003Cp>The starter&#39;s handler queues the first event and drops the rest:\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">PYTHON\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"if%20gid%20in%20queue%3A%0A%20%20%20%20return%0Aqueue%5Bgid%5D%20%3D%20Job(gid%3Dgid%2C%20available%3Dfeed.available(sku_of(gid)))\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">if\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> gid \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">in\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> queue:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    return\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">queue[gid] \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> Job(\u003C\u002Fspan>\u003Cspan style=\"color:#FFAB70\">gid\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">gid, \u003C\u002Fspan>\u003Cspan style=\"color:#FFAB70\">available\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">feed.available(sku_of(gid)))\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>That guard drops burst traffic at the cost of keeping stale data: five supplier updates arriving before\nthe worker runs collapse to the first, so the app acts on the oldest answer. Two changes fix it:\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">PYTHON\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"queue%5Bgid%5D%20%3D%20Job(gid%3Dgid)%20%20%20%20%20%20%20%20%20%20%23%20the%20newest%20event%20wins%0A...%0Areturn%20%7B%22status%22%3A%20%22DRAFT%22%20if%20not%20feed.available(sku_of(job.gid))%20else%20%22ACTIVE%22%7D\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">queue[gid] \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> Job(\u003C\u002Fspan>\u003Cspan style=\"color:#FFAB70\">gid\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">gid)          \u003C\u002Fspan>\u003Cspan style=\"color:#6A737D\"># the newest event wins\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">...\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">return\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"status\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"DRAFT\"\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> if\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> not\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> feed.available(sku_of(job.gid)) \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">else\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"ACTIVE\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>Coalesce toward the newest, and read the input when the job runs rather than when the event arrived.\nE goes green.\u003C\u002Fp>\n\u003Ch2 id=\"what-the-lab-still-does-not-teach\">What the lab still does not teach\u003C\u002Fh2>\n\u003Cp>The lab runs on one thread with one queue, so it never exercises concurrency. In production, this bug\nclass also requires one lane per product so two workers cannot interleave writes to the same object,\neven though adding locking here will not change a single check.\u003C\u002Fp>\n\u003Cp>The forty-write cap is also a harness convenience that turns a hang into a readable log. A real store\ncharges query cost against a shared budget, so a looping sync on one product starves every other API\ncall the app makes for that merchant.\u003C\u002Fp>\n\u003Ch2 id=\"before-you-ship\">Before you ship\u003C\u002Fh2>\n\u003Cp>Because the three fixes are independent, you can ship them in any order and get partial green checks.\nDiffing first is cheap and misleading, so you need a check that verifies final product state rather than\nwrite volume alone. Beyond this lab, map every field the other system&#39;s automation reads so both sides\nagree on the same state.\u003C\u002Fp>\n","\u003Cul>\n\u003Cli>Diffing before writing is necessary and not sufficient: it fixes the log and leaves the field wrong.\u003C\u002Fli>\n\u003Cli>The app has to own every field the other side&#39;s rule reads, or it owns neither.\u003C\u002Fli>\n\u003Cli>Drafting a product without zeroing its stock moves the failure from &#39;still on sale&#39; to &#39;never coming back&#39;.\u003C\u002Fli>\n\u003Cli>Coalescing a queue keeps the newest event, not the first, and reads the input when the job runs.\u003C\u002Fli>\n\u003Cli>Each fix moves a disjoint set of checks, which is why the table has five rows instead of two.\u003C\u002Fli>\n\u003C\u002Ful>\n",[238,243,257,275,296,315],{"id":198,"title":199,"title_id":200,"slug":201,"excerpt":202,"excerpt_id":203,"has_translation":12,"published_at":83,"reading_time":14,"hidden_from_listing":15,"tags":204,"thumbnail_image":21,"og_image":205,"series":239,"authors":240},{"id":90,"title":72,"title_id":72,"slug":73},[241],{"authors_id":242},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":244,"title":245,"title_id":246,"slug":247,"excerpt":248,"excerpt_id":249,"has_translation":12,"published_at":83,"reading_time":123,"hidden_from_listing":15,"tags":250,"thumbnail_image":21,"og_image":252,"series":253,"authors":254},151,"The Status That Changed Itself","Status yang Mengubah Dirinya Sendiri","the-status-that-changed-itself","A product's status blinks between published and draft, nothing errors, and the guard you wrote first works right up until it doesn't. The loop was never an echo.","Status produk berkedip antara published dan draft, tidak ada yang error, dan penjaga pertamamu jalan sampai akhirnya tidak. Loop-nya bukan gema.",[85,86,87,251],"post-mortem","\u002Fog\u002Fthe-status-that-changed-itself.png",{"id":24,"title":25,"title_id":26,"slug":27},[255],{"authors_id":256},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":258,"title":259,"title_id":260,"slug":261,"excerpt":262,"excerpt_id":263,"has_translation":12,"published_at":264,"reading_time":265,"hidden_from_listing":15,"tags":266,"thumbnail_image":21,"og_image":269,"series":270,"authors":272},164,"Python Capstone: Why a Blank CSV Field Cut the Class Average","Python Capstone: Kenapa Satu Kolom CSV Kosong Memotong Rata-rata Kelas","python-capstone-gradebook","A gradebook reads four students and writes a JSON report. The class average says 52.42, because two empty fields became zeros.","Buku nilai membaca empat siswa dan menulis laporan JSON. Rata-rata kelasnya bilang 52.42, karena dua kolom kosong berubah jadi nol.","2026-11-21T01:00:00.000Z",8,[157,267,268],"input-output","cli","\u002Fog\u002Fpython-capstone-gradebook.png",{"id":271,"title":55,"title_id":56,"slug":57},10,[273],{"authors_id":274},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":276,"title":277,"title_id":278,"slug":279,"excerpt":280,"excerpt_id":281,"has_translation":12,"published_at":264,"reading_time":123,"hidden_from_listing":15,"tags":282,"thumbnail_image":21,"og_image":287,"series":288,"authors":293},48,"What a Linked List Actually Is","Tentang Struktur Data LinkedList","tentang-struktur-data-linked-list","A linked list is a linear chain of nodes, each holding data and a pointer to the next node. Here is what that chain looks like, what it costs next to an array, and the same minimal implementation in Java, Python, and JavaScript.","Linked list adalah rantai linear berisi node, dan setiap node menyimpan data plus pointer ke node berikutnya. Ini bentuk rantainya, ongkosnya dibanding array, dan implementasi paling sederhana dalam Java, Python, serta JavaScript.",[283,284,285,286],"struktur-data","linked-list","pointer","konsep","\u002Fog\u002Ftentang-struktur-data-linked-list.png",{"id":289,"title":290,"title_id":291,"slug":292},28,"Linear Data Structures","Struktur Data Linear","asd-struktur-linear",[294],{"authors_id":295},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":297,"title":298,"title_id":299,"slug":300,"excerpt":301,"excerpt_id":302,"has_translation":12,"published_at":303,"reading_time":218,"hidden_from_listing":15,"tags":304,"thumbnail_image":21,"og_image":309,"series":310,"authors":312},163,"Pascal Capstone: Why Every Gradebook Score Came Back Zero","Capstone Pascal: Kenapa Semua Skor Buku Nilai Kembali Nol","pascal-gradebook-capstone","A gradebook reads three students from a file, prints three rows, and every score is 0. The procedure filled a copy of the array, because the parameter was missing `var`. Add the word and the report matches the file; the compiler had already warned about the call that filled nothing.","Sebuah buku nilai membaca tiga siswa dari berkas, mencetak tiga baris, dan setiap skornya 0. Prosedurnya mengisi salinan array, karena parameternya kehilangan `var`. Tambahkan kata itu dan laporannya cocok dengan berkasnya; kompilator sudah memperingatkan soal pemanggilan yang tidak mengisi apa pun.","2026-11-20T01:00:00.000Z",[305,306,307,308],"pascal","record","array","prosedur","\u002Fog\u002Fpascal-gradebook-capstone.png",{"id":311,"title":67,"title_id":68,"slug":69},14,[313],{"authors_id":314},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},{"id":316,"title":317,"title_id":318,"slug":319,"excerpt":320,"excerpt_id":321,"has_translation":12,"published_at":303,"reading_time":218,"hidden_from_listing":15,"tags":322,"thumbnail_image":21,"og_image":323,"series":324,"authors":329},162,"Python File I\u002FO: Why the Second Read Came Back Empty","Python File I\u002FO: Kenapa Pembacaan Kedua Kembali Kosong","python-file-read-write","A notes script saves a line, prints it back, then counts zero. The file on disk is correct: `read()` left the pointer at the end, so the second call returned an empty string. Read once into a variable, or `seek(0)`, and the count matches the file.","Skrip catatan menyimpan satu baris, mencetaknya kembali, lalu menghitung nol. Berkas di disk sudah benar: `read()` meninggalkan pointer di ujung, jadi panggilan kedua mengembalikan string kosong. Baca sekali ke sebuah variabel, atau `seek(0)`, dan hitungannya cocok dengan berkas.",[157,267],"\u002Fog\u002Fpython-file-read-write.png",{"id":325,"title":326,"title_id":327,"slug":328},18,"Working with Python Scripts","Menggunakan Script Python","python-pemrograman-dengan-script",[330],{"authors_id":331},{"id":111,"name":112,"slug":113,"role":114,"profile_picture":21},[333,337,340,343,346,349],{"text":334,"depth":335,"id":336},"Measurements",2,"measurements",{"text":338,"depth":335,"id":339},"1. Send only what differs","1-send-only-what-differs",{"text":341,"depth":335,"id":342},"2. Own both fields, or neither","2-own-both-fields-or-neither",{"text":344,"depth":335,"id":345},"3. Decide from the newest answer","3-decide-from-the-newest-answer",{"text":347,"depth":335,"id":348},"What the lab still does not teach","what-the-lab-still-does-not-teach",{"text":350,"depth":335,"id":351},"Before you ship","before-you-ship",1796084020651]