[{"data":1,"prerenderedAt":1087},["ShallowReactive",2],{"profile":3,"projects:page:\u002Fprojects\u002Fhighreel\u002Fbig-sheets":22,"projects:docs:\u002Fprojects\u002Fhighreel":1047,"structured-data:current-stack":1073},{"id":4,"alias":5,"current":6,"email":10,"extension":11,"headline":12,"links":13,"location":17,"meta":18,"name":19,"stem":20,"__hash__":21},"profile\u002Fprofile.yml","readonly",{"role":7,"company":8,"companyUrl":9},"Fullstack Engineer — Tech Lead","DataCose","https:\u002F\u002Fdatacose.com","redonemini18@gmail.com","yml","Fullstack Engineer",{"github":14,"linkedin":15,"twitch":16},"https:\u002F\u002Fgithub.com\u002FRedoni18","https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fredon-emini\u002F","https:\u002F\u002Fwww.twitch.tv\u002Fr3adonly","Pristina, Kosovo",{},"Redon Emini","profile","Fbb1IAp4nuUOOtgXdwpzcqSmG0CUKtZ4D0ifPqdK5QU",{"id":23,"title":24,"body":25,"description":1032,"extension":1033,"featured":1034,"kind":1035,"links":1036,"meta":1037,"navigation":1038,"order":1040,"path":1041,"period":1042,"preview":1042,"seo":1043,"stack":1044,"stem":1045,"year":1042,"__hash__":1046},"projects\u002Fprojects\u002Fhighreel\u002F2.big-sheets.md","50,000 rows in 128 MB",{"type":26,"value":27,"toc":1024},"minimark",[28,32,40,45,53,56,123,126,132,136,139,145,233,252,270,273,283,287,298,305,528,544,551,555,562,565,761,767,770,824,835,842,846,853,875,885,942,949,953,956,1009,1012,1020],[29,30,31],"p",{},"Every Highreel campaign starts from a spreadsheet, and some businesses have a lot of customers. A campaign can have up to 50,000 rows. Each one has to be imported, validated, shown in the grid, given its own link when the campaign is published, and written to the file of links the business downloads.",[29,33,34,35,39],{},"On a regular server, you'd load the whole sheet into memory and loop over it. A Cloudflare Worker runs your code in an isolate with ",[36,37,38],"strong",{},"128 MB of memory",", and that has to cover everything happening in it at once. This post is about fitting the work into that.",[41,42,44],"h2",{"id":43},"measure-on-the-real-runtime-first","Measure on the real runtime first",[29,46,47,48,52],{},"Before designing anything, I wrote a script (",[49,50,51],"code",{},"scripts\u002Fworker-sheets.mjs",") that runs the built Worker locally on workerd, the same runtime Cloudflare uses in production. It imports a 10,000-row and a 50,000-row sheet, loads the grid, publishes and exports, and reads the isolate's heap and CPU time through its debugging inspector while each request runs. workerd doesn't enforce the limits locally, so the numbers show how close each route gets.",[29,54,55],{},"In the straightforward version, each of those routes held the whole sheet. This is how much the heap grew during a single request:",[57,58,59,81],"table",{},[60,61,62],"thead",{},[63,64,65,69,72,75,78],"tr",{},[66,67,68],"th",{},"Rows",[66,70,71],{},"Import",[66,73,74],{},"Grid",[66,76,77],{},"Publish",[66,79,80],{},"Export",[82,83,84,102],"tbody",{},[63,85,86,90,93,96,99],{},[87,88,89],"td",{},"10,000",[87,91,92],{},"+26 MB",[87,94,95],{},"+29 MB",[87,97,98],{},"+22 MB",[87,100,101],{},"+15 MB",[63,103,104,107,112,117,120],{},[87,105,106],{},"50,000",[87,108,109],{},[36,110,111],{},"+144 MB",[87,113,114],{},[36,115,116],{},"+104 MB",[87,118,119],{},"+69 MB",[87,121,122],{},"+74 MB",[29,124,125],{},"CPU time was never the problem. Even 50,000 rows stayed far below the limit. Memory was: at 50,000 rows the import alone took the heap from 13 MB to 158 MB, and on Cloudflare that isolate would be killed partway through someone's upload.",[29,127,128,129],{},"Without that table, all I'd have had was \"big sheets might run out of memory\". With it, I had four routes to fix and a clear number to compare against. It led to one rule: ",[36,130,131],{},"no route ever holds a whole sheet.",[41,133,135],{"id":134},"pages-of-5000-rows","Pages of 5,000 rows",[29,137,138],{},"At 10,000 rows a request grew the heap by about 26 to 29 MB, so a page of 5,000 rows costs around 15 MB. That's a comfortable slice, and every route that touches rows now works in pages of that size.",[29,140,141,144],{},[36,142,143],{},"The grid"," loads a page, then the next one, into the same table. The pages are found with a cursor, the last row number the browser has, rather than with an offset:",[146,147,152],"pre",{"className":148,"code":149,"language":150,"meta":151,"style":151},"language-sql shiki shiki-themes vitesse-light vitesse-dark","select ... from recipients\n where campaign_id = ? and ...\n   and row_index > ?          -- the last row of the previous page\n order by row_index\n limit 5000\n","sql","",[49,153,154,173,195,214,223],{"__ignoreMap":151},[155,156,159,163,167,170],"span",{"class":157,"line":158},"line",1,[155,160,162],{"class":161},"sTPum","select",[155,164,166],{"class":165},"s8w-G"," ... ",[155,168,169],{"class":161},"from",[155,171,172],{"class":165}," recipients\n",[155,174,176,179,182,186,189,192],{"class":157,"line":175},2,[155,177,178],{"class":161}," where",[155,180,181],{"class":165}," campaign_id ",[155,183,185],{"class":184},"s5TCs","=",[155,187,188],{"class":165}," ? ",[155,190,191],{"class":161},"and",[155,193,194],{"class":165}," ...\n",[155,196,198,201,204,207,210],{"class":157,"line":197},3,[155,199,200],{"class":161},"   and",[155,202,203],{"class":165}," row_index ",[155,205,206],{"class":184},">",[155,208,209],{"class":165}," ?          ",[155,211,213],{"class":212},"snYqZ","-- the last row of the previous page\n",[155,215,217,220],{"class":157,"line":216},4,[155,218,219],{"class":161}," order by",[155,221,222],{"class":165}," row_index\n",[155,224,226,229],{"class":157,"line":225},5,[155,227,228],{"class":161}," limit",[155,230,232],{"class":231},"sqbOQ"," 5000\n",[29,234,235,236,239,240,243,244,247,248,251],{},"This is called ",[36,237,238],{},"keyset pagination",". With ",[49,241,242],{},"OFFSET 45000",", the database still steps over 45,000 rows to reach the page you asked for, so every page is slower than the one before it. With ",[49,245,246],{},"row_index > ?"," and an index on ",[49,249,250],{},"(campaign_id, row_index)",", it jumps straight to the right spot, and the tenth page costs the same as the first.",[29,253,254,257,258,261,262,265,266,269],{},[36,255,256],{},"Uploads"," come in parts. The browser parses the file itself (CSV with PapaParse, Excel with ",[49,259,260],{},"read-excel-file",") and sends it 5,000 rows at a time, as ",[49,263,264],{},"{ part, parts, rows }",". Each part is written in a single D1 ",[49,267,268],{},"batch()",", which runs as one transaction, so a part is either saved completely or not at all. The campaign remembers which part it expects next. If someone closes the tab halfway through an upload, the sheet says the last upload didn't finish, and publishing waits for a complete sheet instead of sending links for half of one.",[29,271,272],{},"Paging made one check harder: duplicate customer ids. Inside a part, the server can spot them in memory. Across parts it can't, because it never sees the whole sheet at once. So after the last part lands, a single SQL query finds the ids that appear more than once, and only those rows get flagged.",[29,274,275,278,279,282],{},[36,276,277],{},"Publishing"," checks the sheet again a page at a time, and from each page it keeps only what the next step needs: each row's id, whether it's valid, its link token and the value it's ranked by. ",[36,280,281],{},"The links file"," streams, sending each page to the browser as soon as it's read, so its memory stays flat no matter how big the sheet is.",[41,284,286],{"id":285},"_100-values-per-statement","100 values per statement",[29,288,289,290,293,294,297],{},"D1 has another limit that shapes every write: a statement can have at most ",[36,291,292],{},"100 bound values",". Inserting 5,000 rows with ten columns each the usual way, with ",[49,295,296],{},"values (?, ?, …), (?, ?, …)",", would take 500 separate statements.",[29,299,300,301,304],{},"Instead, each statement gets a single parameter: a JSON array of rows. SQLite's ",[49,302,303],{},"json_each"," turns that array back into a table inside the query, and the insert selects from it:",[146,306,311],{"className":307,"code":308,"filename":309,"language":310,"meta":151,"style":151},"language-ts shiki shiki-themes vitesse-light vitesse-dark","export function insertRowStatements(db: Db, campaignId: string, rows: NewRow[]) {\n  return jsonChunks(rows.map(r => ({ ...r, id: crypto.randomUUID() }))).map(chunk => db.d1.prepare(`\n    insert into recipients (id, campaign_id, row_index, customer_id, raw, data, errors \u002F* … *\u002F)\n    select json_extract(value, '$.id'), ?, json_extract(value, '$.row_index'),\n           json_extract(value, '$.customer_id'), json_extract(value, '$.raw'),\n           json_extract(value, '$.data'), json_extract(value, '$.errors') \u002F* … *\u002F\n      from json_each(?)\n     where ? in (select id from campaigns where business_id = ?)`)\n    .bind(campaignId, chunk, campaignId, db.businessId))\n}\n","server\u002Futils\u002Fdb.ts","ts",[49,312,313,367,447,453,458,463,469,475,487,522],{"__ignoreMap":151},[155,314,315,318,321,325,329,333,336,340,343,346,348,351,353,356,358,361,364],{"class":157,"line":158},[155,316,317],{"class":161},"export",[155,319,320],{"class":184}," function",[155,322,324],{"class":323},"s_xSY"," insertRowStatements",[155,326,328],{"class":327},"si6no","(",[155,330,332],{"class":331},"s9nN2","db",[155,334,335],{"class":327},": ",[155,337,339],{"class":338},"s_NWU","Db",[155,341,342],{"class":327},",",[155,344,345],{"class":331}," campaignId",[155,347,335],{"class":327},[155,349,350],{"class":338},"string",[155,352,342],{"class":327},[155,354,355],{"class":331}," rows",[155,357,335],{"class":327},[155,359,360],{"class":338},"NewRow",[155,362,363],{"class":327},"[])",[155,365,366],{"class":327}," {\n",[155,368,369,372,375,377,380,383,386,388,391,394,397,399,402,406,408,411,413,416,419,421,423,426,428,431,433,436,438,441,443],{"class":157,"line":175},[155,370,371],{"class":161},"  return",[155,373,374],{"class":323}," jsonChunks",[155,376,328],{"class":327},[155,378,379],{"class":331},"rows",[155,381,382],{"class":327},".",[155,384,385],{"class":323},"map",[155,387,328],{"class":327},[155,389,390],{"class":331},"r",[155,392,393],{"class":327}," =>",[155,395,396],{"class":327}," ({ ...",[155,398,390],{"class":331},[155,400,401],{"class":327},", ",[155,403,405],{"class":404},"sHLBJ","id",[155,407,335],{"class":327},[155,409,410],{"class":331},"crypto",[155,412,382],{"class":327},[155,414,415],{"class":323},"randomUUID",[155,417,418],{"class":327},"() }))).",[155,420,385],{"class":323},[155,422,328],{"class":327},[155,424,425],{"class":331},"chunk",[155,427,393],{"class":327},[155,429,430],{"class":331}," db",[155,432,382],{"class":327},[155,434,435],{"class":331},"d1",[155,437,382],{"class":327},[155,439,440],{"class":323},"prepare",[155,442,328],{"class":327},[155,444,446],{"class":445},"scnC2","`\n",[155,448,449],{"class":157,"line":197},[155,450,452],{"class":451},"spP0B","    insert into recipients (id, campaign_id, row_index, customer_id, raw, data, errors \u002F* … *\u002F)\n",[155,454,455],{"class":157,"line":216},[155,456,457],{"class":451},"    select json_extract(value, '$.id'), ?, json_extract(value, '$.row_index'),\n",[155,459,460],{"class":157,"line":225},[155,461,462],{"class":451},"           json_extract(value, '$.customer_id'), json_extract(value, '$.raw'),\n",[155,464,466],{"class":157,"line":465},6,[155,467,468],{"class":451},"           json_extract(value, '$.data'), json_extract(value, '$.errors') \u002F* … *\u002F\n",[155,470,472],{"class":157,"line":471},7,[155,473,474],{"class":451},"      from json_each(?)\n",[155,476,478,481,484],{"class":157,"line":477},8,[155,479,480],{"class":451},"     where ? in (select id from campaigns where business_id = ?)",[155,482,483],{"class":445},"`",[155,485,486],{"class":327},")\n",[155,488,490,493,496,498,501,503,506,508,510,512,514,516,519],{"class":157,"line":489},9,[155,491,492],{"class":327},"    .",[155,494,495],{"class":323},"bind",[155,497,328],{"class":327},[155,499,500],{"class":331},"campaignId",[155,502,342],{"class":327},[155,504,505],{"class":331}," chunk",[155,507,342],{"class":327},[155,509,345],{"class":331},[155,511,342],{"class":327},[155,513,430],{"class":331},[155,515,382],{"class":327},[155,517,518],{"class":331},"businessId",[155,520,521],{"class":327},"))\n",[155,523,525],{"class":157,"line":524},10,[155,526,527],{"class":327},"}\n",[29,529,530,533,534,537,538,543],{},[49,531,532],{},"jsonChunks"," splits the rows into arrays of up to 900 KB, because D1 caps a single string at 2 MB. A part of 5,000 rows becomes a handful of statements, all in the same batch. The ",[49,535,536],{},"where"," on the last line is the business check from the ",[539,540,542],"a",{"href":541},"\u002Fprojects\u002Fhighreel\u002Farchitecture","architecture post",": if the campaign isn't yours, the select produces no rows and nothing gets inserted.",[29,545,546,547,550],{},"Updates use the same trick, with ",[49,548,549],{},"update … from json_each(?)",". That's where the strangest bug in the project turned up.",[41,552,554],{"id":553},"_80-seconds-then-004","80 seconds, then 0.04",[29,556,557,558,561],{},"On the built Worker, publishing a 10,000-row sheet took 61 seconds. Only 136 ms of that was the Worker's own CPU time. The rest was spent waiting on the database. At 50,000 rows, publishing never finished. Running the same update in plain ",[49,559,560],{},"sqlite3",", one statement that updated 5,000 rows of a 50,000-row sheet took 80 seconds.",[29,563,564],{},"The statement looked harmless:",[146,566,568],{"className":148,"code":567,"language":150,"meta":151,"style":151},"update recipients\n   set token = coalesce(recipients.token, json_extract(x.value, '$.token')),\n       data = json_patch(recipients.data, json_extract(x.value, '$.ranks'))\n  from json_each(?) as x\n where recipients.id = json_extract(x.value, '$.id')\n   and recipients.campaign_id = ?\n   and recipients.campaign_id in (select id from campaigns where business_id = ?)\n",[49,569,570,577,625,662,676,709,725],{"__ignoreMap":151},[155,571,572,575],{"class":157,"line":158},[155,573,574],{"class":161},"update",[155,576,172],{"class":165},[155,578,579,582,585,587,590,592,596,598,601,604,607,609,612,614,617,620,622],{"class":157,"line":175},[155,580,581],{"class":161},"   set",[155,583,584],{"class":165}," token ",[155,586,185],{"class":184},[155,588,589],{"class":404}," coalesce",[155,591,328],{"class":165},[155,593,595],{"class":594},"sfsYZ","recipients",[155,597,382],{"class":165},[155,599,600],{"class":594},"token",[155,602,603],{"class":165},", json_extract(",[155,605,606],{"class":594},"x",[155,608,382],{"class":165},[155,610,611],{"class":594},"value",[155,613,401],{"class":165},[155,615,616],{"class":445},"'",[155,618,619],{"class":451},"$.token",[155,621,616],{"class":445},[155,623,624],{"class":165},")),\n",[155,626,627,630,633,636,638,640,643,645,647,649,651,653,655,658,660],{"class":157,"line":197},[155,628,629],{"class":161},"       data",[155,631,632],{"class":184}," =",[155,634,635],{"class":165}," json_patch(",[155,637,595],{"class":594},[155,639,382],{"class":165},[155,641,642],{"class":594},"data",[155,644,603],{"class":165},[155,646,606],{"class":594},[155,648,382],{"class":165},[155,650,611],{"class":594},[155,652,401],{"class":165},[155,654,616],{"class":445},[155,656,657],{"class":451},"$.ranks",[155,659,616],{"class":445},[155,661,521],{"class":165},[155,663,664,667,670,673],{"class":157,"line":216},[155,665,666],{"class":161},"  from",[155,668,669],{"class":165}," json_each(?) ",[155,671,672],{"class":161},"as",[155,674,675],{"class":165}," x\n",[155,677,678,680,683,685,687,689,692,694,696,698,700,702,705,707],{"class":157,"line":225},[155,679,178],{"class":161},[155,681,682],{"class":594}," recipients",[155,684,382],{"class":165},[155,686,405],{"class":594},[155,688,632],{"class":184},[155,690,691],{"class":165}," json_extract(",[155,693,606],{"class":594},[155,695,382],{"class":165},[155,697,611],{"class":594},[155,699,401],{"class":165},[155,701,616],{"class":445},[155,703,704],{"class":451},"$.id",[155,706,616],{"class":445},[155,708,486],{"class":165},[155,710,711,713,715,717,720,722],{"class":157,"line":465},[155,712,200],{"class":161},[155,714,682],{"class":594},[155,716,382],{"class":165},[155,718,719],{"class":594},"campaign_id",[155,721,632],{"class":184},[155,723,724],{"class":165}," ?\n",[155,726,727,729,731,733,735,738,741,743,746,748,751,753,756,758],{"class":157,"line":471},[155,728,200],{"class":161},[155,730,682],{"class":594},[155,732,382],{"class":165},[155,734,719],{"class":594},[155,736,737],{"class":161}," in",[155,739,740],{"class":165}," (",[155,742,162],{"class":161},[155,744,745],{"class":165}," id ",[155,747,169],{"class":161},[155,749,750],{"class":165}," campaigns ",[155,752,536],{"class":161},[155,754,755],{"class":165}," business_id ",[155,757,185],{"class":184},[155,759,760],{"class":165}," ?)\n",[29,762,763,764,766],{},"The problem was how SQLite decided to run it. It had two ways in: take each entry in the JSON list and look up its row by id (the primary key), or start from the index on ",[49,765,719],{},". It picked the index. That sounds reasonable until you see what it means here: for every row in the campaign, SQLite scanned the whole JSON list looking for a matching id. That's 50,000 rows times 5,000 entries, 250 million comparisons, for one statement.",[29,768,769],{},"The fix is a single character, twice:",[146,771,773],{"className":148,"code":772,"language":150,"meta":151,"style":151},"   and +recipients.campaign_id = ?\n   and +recipients.campaign_id in (select id from campaigns where business_id = ?)\n",[49,774,775,792],{"__ignoreMap":151},[155,776,777,779,782,784,786,788,790],{"class":157,"line":158},[155,778,200],{"class":161},[155,780,781],{"class":184}," +",[155,783,595],{"class":594},[155,785,382],{"class":165},[155,787,719],{"class":594},[155,789,632],{"class":184},[155,791,724],{"class":165},[155,793,794,796,798,800,802,804,806,808,810,812,814,816,818,820,822],{"class":157,"line":175},[155,795,200],{"class":161},[155,797,781],{"class":184},[155,799,595],{"class":594},[155,801,382],{"class":165},[155,803,719],{"class":594},[155,805,737],{"class":161},[155,807,740],{"class":165},[155,809,162],{"class":161},[155,811,745],{"class":165},[155,813,169],{"class":161},[155,815,750],{"class":165},[155,817,536],{"class":161},[155,819,755],{"class":165},[155,821,185],{"class":184},[155,823,760],{"class":165},[29,825,826,827,830,831,834],{},"A unary ",[49,828,829],{},"+"," doesn't change the value. But to SQLite, ",[49,832,833],{},"+column"," is an expression rather than a plain column, so it can't use an index for that condition. It's a documented way to steer SQLite's query planner. With the campaign index out of the picture, SQLite reads the JSON list once and finds each row by its primary key. The same statement went from 80 seconds to 0.04, and publishing all 50,000 rows now takes about 1.2 seconds. The business filter is still there; only the plan changed.",[29,836,837,838,841],{},"Two habits come out of this. When a query is slow, compare wall time with CPU time, because the gap tells you whether the time is going into your code or into something you're waiting on. And for any query that will run against a lot of data, look at ",[49,839,840],{},"EXPLAIN QUERY PLAN"," before trusting it. The query planner is making a guess, and sometimes the guess is badly wrong.",[41,843,845],{"id":844},"when-a-covering-index-isnt-one","When a covering index isn't one",[29,847,848,849,852],{},"The home page shows counts for each campaign: rows, errors, how many were opened, saved and shared. The table it counts has wide JSON columns (the raw cells and the parsed values), and reading those just to count rows would be wasteful. So there's a ",[36,850,851],{},"covering index",": an index that contains every column the query needs, so SQLite can answer from the index alone without opening the rows themselves.",[29,854,855,856,859,860,863,864,866,867,870,871,874],{},"In the first version, ",[49,857,858],{},"has_errors"," was a generated column, computed from ",[49,861,862],{},"errors \u003C> '{}'",". ",[49,865,840],{}," said ",[49,868,869],{},"USING INDEX recipients_home",", not ",[49,872,873],{},"USING COVERING INDEX",". SQLite doesn't treat an index that includes a generated column as covering, so it went back to the table for every row anyway, JSON and all.",[29,876,877,878,880,881,884],{},"The fix was to make ",[49,879,858],{}," an ordinary column that the data layer writes together with ",[49,882,883],{},"errors",", plus a check constraint that keeps the two in step:",[146,886,889],{"className":148,"code":887,"filename":888,"language":150,"meta":151,"style":151},"-- A plain column, not a generated one: SQLite never treats an index holding a\n-- generated column as covering, and the home must read recipients_home alone.\nhas_errors integer not null default 0 check (has_errors = (errors \u003C> '{}')),\n","migrations\u002F0001_init.sql",[49,890,891,896,901],{"__ignoreMap":151},[155,892,893],{"class":157,"line":158},[155,894,895],{"class":212},"-- A plain column, not a generated one: SQLite never treats an index holding a\n",[155,897,898],{"class":157,"line":175},[155,899,900],{"class":212},"-- generated column as covering, and the home must read recipients_home alone.\n",[155,902,903,906,909,912,915,918,921,924,926,929,932,935,938,940],{"class":157,"line":197},[155,904,905],{"class":165},"has_errors ",[155,907,908],{"class":184},"integer",[155,910,911],{"class":161}," not null",[155,913,914],{"class":184}," default",[155,916,917],{"class":231}," 0",[155,919,920],{"class":184}," check",[155,922,923],{"class":165}," (has_errors ",[155,925,185],{"class":184},[155,927,928],{"class":165}," (errors ",[155,930,931],{"class":184},"\u003C>",[155,933,934],{"class":445}," '",[155,936,937],{"class":451},"{}",[155,939,616],{"class":445},[155,941,624],{"class":165},[29,943,944,945,948],{},"Now both of the home's queries say ",[49,946,947],{},"USING COVERING INDEX recipients_home",". The check constraint keeps the guarantee a generated column would give (the two values can never disagree), and the plain column gets the speed.",[41,950,952],{"id":951},"where-it-ended-up","Where it ended up",[29,954,955],{},"The same script, with 50,000 rows, after the changes. This is the largest heap growth of any single request in each step:",[57,957,958,971],{},[60,959,960],{},[63,961,962,965,968],{},[66,963,964],{},"Step",[66,966,967],{},"Before",[66,969,970],{},"After",[82,972,973,982,991,1000],{},[63,974,975,977,979],{},[87,976,71],{},[87,978,111],{},[87,980,981],{},"+30.5 MB (10 parts)",[63,983,984,986,988],{},[87,985,74],{},[87,987,116],{},[87,989,990],{},"+17.6 MB (11 pages)",[63,992,993,995,997],{},[87,994,77],{},[87,996,119],{},[87,998,999],{},"+22.8 MB",[63,1001,1002,1004,1006],{},[87,1003,80],{},[87,1005,122],{},[87,1007,1008],{},"+0.3 MB (streamed)",[29,1010,1011],{},"The script now fails if any request grows the heap by more than 40 MB, so a change that quietly loads a whole sheet again gets caught before it ships.",[1013,1014,1017],"callout",{"title":1015,"type":1016},"The takeaway","tip",[29,1018,1019],{},"Limits are much easier to design for once you've measured them. Running the real runtime with the biggest input the product allows, and reading the heap instead of guessing, turned a vague worry into a short list of routes to fix and a number to keep them under.",[1021,1022,1023],"style",{},"html pre.shiki code .sTPum, html code.shiki .sTPum{--shiki-default:#1E754F;--shiki-dark:#4D9375}html pre.shiki code .s5TCs, html code.shiki .s5TCs{--shiki-default:#AB5959;--shiki-dark:#CB7676}html pre.shiki code .s_xSY, html code.shiki .s_xSY{--shiki-default:#59873A;--shiki-dark:#80A665}html pre.shiki code .si6no, html code.shiki .si6no{--shiki-default:#999999;--shiki-dark:#666666}html pre.shiki code .s9nN2, html code.shiki .s9nN2{--shiki-default:#B07D48;--shiki-dark:#BD976A}html pre.shiki code .s_NWU, html code.shiki .s_NWU{--shiki-default:#2E8F82;--shiki-dark:#5DA994}html pre.shiki code .sHLBJ, html code.shiki .sHLBJ{--shiki-default:#998418;--shiki-dark:#B8A965}html pre.shiki code .scnC2, html code.shiki .scnC2{--shiki-default:#B5695977;--shiki-dark:#C98A7D77}html pre.shiki code .spP0B, html code.shiki .spP0B{--shiki-default:#B56959;--shiki-dark:#C98A7D}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s8w-G, html code.shiki .s8w-G{--shiki-default:#393A34;--shiki-dark:#DBD7CAEE}html pre.shiki code .snYqZ, html code.shiki .snYqZ{--shiki-default:#A0ADA0;--shiki-dark:#758575DD}html pre.shiki code .sqbOQ, html code.shiki .sqbOQ{--shiki-default:#2F798A;--shiki-dark:#4C9A91}html pre.shiki code .sfsYZ, html code.shiki .sfsYZ{--shiki-default:#A65E2B;--shiki-dark:#C99076}",{"title":151,"searchDepth":175,"depth":197,"links":1025},[1026,1027,1028,1029,1030,1031],{"id":43,"depth":175,"text":44},{"id":134,"depth":175,"text":135},{"id":285,"depth":175,"text":286},{"id":553,"depth":175,"text":554},{"id":844,"depth":175,"text":845},{"id":951,"depth":175,"text":952},"How Highreel handles big customer sheets inside a Worker's memory limit, by measuring first, paging every route, packing rows into one JSON parameter, and adding one character to a query.","md",false,"personal",{},{},{"title":1039},"Big sheets",999,"\u002Fprojects\u002Fhighreel\u002Fbig-sheets",null,{"title":24,"description":1032},[],"projects\u002Fhighreel\u002F2.big-sheets","28bOIwrICfh0xKPhjWPAX0V04Ce_8t0nb1eGA8gtRLE",[1048,1058,1064,1066],{"path":1049,"title":1050,"stem":1051,"navigation":1052,"description":1053,"preview":1054},"\u002Fprojects\u002Fhighreel","Highreel","projects\u002Fhighreel\u002Findex",true,"Spotify Wrapped for any small business. Upload a spreadsheet of customer stats, and every customer gets their own animated year in review to tap through and share.",{"src":1055,"alt":1056,"og":1057},"\u002Fprojects\u002Fhighreel\u002Fpreview.webp","Highreel: 'Give your customers their highlight reel.' surrounded by recap stickers such as '212 days in the app' and 'Top 6% of all readers', and two messages from a business","\u002Fprojects\u002Fhighreel\u002Fog.png",{"path":541,"title":1059,"stem":1060,"navigation":1061,"description":1063,"preview":1042},"Keeping businesses apart without row-level security","projects\u002Fhighreel\u002F1.architecture",{"title":1062},"Architecture","Why Highreel runs on a single Cloudflare Worker, and how one data layer, a test that reads the SQL and a script that attacks the API keep every business inside its own data.",{"path":1041,"title":24,"stem":1045,"navigation":1065,"description":1032,"preview":1042},{"title":1039},{"path":1067,"title":1068,"stem":1069,"navigation":1070,"description":1072,"preview":1042},"\u002Fprojects\u002Fhighreel\u002Fscenes","Animations that are also images","projects\u002Fhighreel\u002F3.scenes",{"title":1071},"The recap","How Highreel's story slides animate in plain CSS, and how one rule (every element rests at its final frame) gives reduced motion, saved images and the same Highreel every time for free.",[1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086],"TypeScript","Vue 3","Nuxt","Pinia","Tailwind CSS","Python","FastAPI","SQLAlchemy","Pydantic","PostgreSQL","Supabase","GCP","Firebase",1792035553938]