{"slug": "our-19-report-has-no-database-row-the-whole-purchase-lives-in-the-url-fragment", "title": "Our $19 report has no database row. The whole purchase lives in the URL fragment.", "summary": "A developer at check.tattoo, a service that scores tattoo ideas before purchase, built a stateless restore mechanism that stores the entire $19 paid report in the URL fragment rather than a server-side database. Because the report is generated by a model at temperature 0.4, re-running the check would produce different wording and possibly different numbers, so the team rejected restore codes in favor of a base64url-encoded positional JSON payload that browsers never transmit to a server. Real reports measured between 2,829 and 3,443 characters, and decoding validates a version number, integer scores from 0 to 100, exactly six dimensions, and per-field length caps.", "body_md": "[check.tattoo](https://check.tattoo) scores a tattoo idea before you get it. The score is free. The full report is a one-time $19 payment for one design: the reasoning behind each score, what to change, and a brief for the artist.\n\nThere are no accounts, and that created a problem.\n\nAfter payment, two things are written to the browser: the entitlement (\"this design is unlocked\") and the report itself. Both live in `localStorage`.\n\n`localStorage` is not durable. Safari's tracking prevention can evict script-written storage after about a week without a return visit. So a buyer could pay, come back ten days later on an iPhone, and find nothing.\n\nThe usual fix is a restore code and a table: store the purchase server-side, hand the buyer a code, and look it up later. We considered it and rejected it for a reason specific to this product.\n\n**A lookup would restore the right to the report, not the report.** The report is generated by a model running at temperature 0.4. If you re-grant the unlock and re-run the check, you get a *different* report, with different wording and maybe different numbers. Handing back different numbers isn't restoring a purchase.\n\nSo the restore link carries the whole report.\n\nAfter paying, the buyer gets a link like this:\n\n```\nhttps://check.tattoo/restore#r=<base64url of the whole report>\n```\n\nEverything after `#` is the fragment, and browsers never send the fragment to a server. So this design stores nothing: no table of purchases, no codes anyone could guess, no personal data, nothing to delete later.\n\nOpening the link re-installs the exact report that was paid for, for that one design.\n\nThe trade-off is explicit in the code: **anyone holding the link gets that report.** That's the same property a downloaded PDF has. It covers one design and can't unlock anything else.\n\nThe payload is JSON, base64url-encoded. Three things go wrong if you write this the obvious way:\n\n``` js\nexport const encodeFragment = (payload: unknown): string => {\n  const bytes = new TextEncoder().encode(JSON.stringify(payload));\n  let latin1 = \"\";\n  for (const b of bytes) latin1 += String.fromCharCode(b);\n  return btoa(latin1).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n};\n```\n\n`btoa` is latin1-only and throws on anything above U+00FF.`TextEncoder` first.`+`, `/` and `=` are not safe in a fragment\n\n``` js\nexport const decodeFragment = (hash: string, key: string): unknown => {\n  try {\n    const m = new RegExp(`[#&]${key}=([A-Za-z0-9_-]+)`).exec(hash);\n    if (!m) return undefined;\n    const b64 = m[1].replace(/-/g, \"+\").replace(/_/g, \"/\");\n    const latin1 = atob(b64 + \"=\".repeat((4 - (b64.length % 4)) % 4));\n    const bytes = new Uint8Array(latin1.length);\n    for (let i = 0; i < latin1.length; i += 1) bytes[i] = latin1.charCodeAt(i);\n    return JSON.parse(new TextDecoder().decode(bytes));\n  } catch {\n    return undefined;\n  }\n};\n```\n\nThe report includes six dimension summaries, two or three recommendations and an artist brief. To keep the URL manageable, the payload is **positional**: an array, not an object. Keys would add hundreds of characters.\n\n```\n[version, designKey, orderId, overall, headline,\n [[score, verdict, summary] × 6],\n [[priority, title, detail] × n],\n artistBrief, contextLine]\n```\n\nEvery field has a length cap (headline 300, each summary 1,200, the brief 4,000, at most five recommendations). According to a note in the code, five real reports measured between 2,829 and 3,443 characters. That's long for a URL, but it's the whole purchase.\n\nA version number comes first, so the layout can change later without old links decoding into garbage.\n\nDecoding checks the shape and rejects anything off. The version must match, scores must be integers from 0 to 100, and there must be exactly six dimensions. Strings are cut to their caps again on the way in. A shortened excerpt:\n\n```\nif (v !== RECOVERY_VERSION) return null;\nif (typeof designKey !== \"string\" || !designKey) return null;\nif (!isScore(overall) || typeof headline !== \"string\") return null;\nif (!Array.isArray(dims) || dims.length !== DIMENSION_IDS.length) return null;\n```\n\nThe browser doesn't send the fragment, but scripts on the page can read it. Our host injects a page-view measurement script into every page, and that script posts `window.location.href`, fragment included, to its own endpoint shortly after load. We can't change that script.\n\nSo the fragment has to leave the address bar before any deferred script runs. A **synchronous inline script at the top of `<head>`** does it:\n\n``` js\n<script>\n  (function () {\n    function strip() {\n      try {\n        var l = window.location;\n        if (/^\\/restore\\/?$/i.test(l.pathname) && /[#&]r=/.test(l.hash)) {\n          window.__restoreFragment = l.hash;\n          try { sessionStorage.setItem(\"checktattoo.restoreFragment.v1\", l.hash); } catch (e) {}\n          history.replaceState(history.state, \"\", l.pathname + l.search);\n        }\n      } catch (e) {}\n    }\n    strip();\n    window.addEventListener(\"hashchange\", strip, true);\n    window.addEventListener(\"popstate\", strip, true);\n  })();\n</script>\n```\n\nThree details:\n\n`location.href`, the address is plain `/restore`.` sessionStorage``hashchange` and `popstate` listeners, in the capture phase.\nOpening a recovery link doesn't restore anything by itself. Restoring writes to `localStorage` and replaces whatever report is already there. Someone who opens a friend's link out of curiosity shouldn't lose their own report without being asked. So `/restore` shows what it found and waits for a click. If a *different* paid report is already in that slot, it's archived rather than overwritten.\n\nIt doesn't fit if a purchase needs to be revocable, or if the payload is too large or too sensitive to hand to the user.\n\nOur site has [a page about the restore link](https://check.tattoo/restore) for buyers. The tool itself is free to try at [check.tattoo](https://check.tattoo).", "url": "https://wpnews.pro/news/our-19-report-has-no-database-row-the-whole-purchase-lives-in-the-url-fragment", "canonical_source": "https://dev.to/alondrilich/our-19-report-has-no-database-row-the-whole-purchase-lives-in-the-url-fragment-5coj", "published_at": "2026-11-28 23:32:40+00:00", "updated_at": "2026-11-28 23:43:51.948261+00:00", "lang": "en", "topics": ["ai-products", "developer-tools", "ai-tools"], "entities": ["check.tattoo"], "also_reported_by": [], "takeaway": "Encode the full generated report as a versioned, positional base64url JSON payload in the URL fragment so a paid artifact can be restored exactly without a database, since re-running a temperature-0.4 model would return different content.", "recommendation": {"advice": "When a paid artifact must be restored exactly, store the full payload in the URL fragment with a version prefix and strict shape validation instead of re-generating it or keeping a lookup table.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/our-19-report-has-no-database-row-the-whole-purchase-lives-in-the-url-fragment", "markdown": "https://wpnews.pro/news/our-19-report-has-no-database-row-the-whole-purchase-lives-in-the-url-fragment.md", "text": "https://wpnews.pro/news/our-19-report-has-no-database-row-the-whole-purchase-lives-in-the-url-fragment.txt", "jsonld": "https://wpnews.pro/news/our-19-report-has-no-database-row-the-whole-purchase-lives-in-the-url-fragment.jsonld"}}