A $500 D1 bill? Check rows written first
Layerbase walks through the D1 write meter using a public $513.20 invoice: writes cost 1,000× reads per row, indexes add written rows, and common causes include reprocessing jobs, upsert loops and writes on the read path.
- Products
- D1Workers
- Source
- Community resourceLayerbase blog
- Author
- Layerbase
Key points
- The article states that its author builds Layerbase Cloud, a flat-priced libSQL host, and therefore has an interest in the topic; it closes by promoting that service as an alternative.
- From the public invoice (452,256,462 rows written, $453; 60,197,421,138 rows read, $60.20) it works out that the billable writes alone average about 175 rows per second over 30 days, and that each insert into a table with two secondary indexes writes three rows. These are the article's calculations, not an analysis of that user's code.
- Causes it lists: jobs that reprocess what they already did, inserts without conflict handling, INSERT … ON CONFLICT DO UPDATE in loops (it suggests a WHERE clause so unchanged rows are skipped), writes on the read path such as last_seen updates and counters, non-idempotent retries, and logging into D1 instead of Analytics Engine.
- Audit steps: read invoice quantities in Billable Usage, query d1AnalyticsAdaptiveGroups rowsWritten per database per day, run wrangler d1 insights sorted by writes, log meta.rows_written per query, and compare rows_written with meta.changes to spot index costs and rewrites. It notes budget alerts and D1 usage notifications send email only.
- Official D1 pricing (rechecked 2026-10-20): Workers Paid includes 50 million rows written per month, then $1.00 per million; reads 25 billion included, then $0.001 per million; indexes add a written row when writes include the indexed column.
Original sources
Published
A $500 D1 bill? Check rows written first
Open original sourceLayerbase walks through the D1 write meter using a public $513.20 invoice: writes cost 1,000× reads per row, indexes add written rows, and common causes include reprocessing jobs, upsert loops and writes on the read path.
More to read
Feng Yi: AI cost weekly|11/20; watching the model unit price is not enough—first split costs across requests, CPU, tokens, writes, and retries
On 2026-11-20, X user @Michael_liyang (Feng Yi) published "AI cost weekly|11/20". The conclusion is that watching the model unit price is not enough—first split costs across requests, CPU, tokens, writes, and retries. Figures the author checked this week: creating a D1 table is rows_written=2, and inserting 1 row is rows_written=1; the Workers free tier is 100,000 requests/day; the D1 free tier is 5,000,000 row reads/100,000 row writes per day; R2 egress is 0 美元. Suggested ledger fields: requests / rows_written / cpu_ms / input_tokens / output_tokens / retry_rate / cost_per_success. The author cautions: a free quota is not 0 cost.
hiromsaeden: an unindexed D1 query loop billed $2,129.00; a $953.74 courtesy credit left $645.38 due.
Cloudflare Community user hiromsaeden, in a post-mortem of a personal hobby project on Workers and D1, says an unindexed GROUP BY aggregate query scanned about 877,000 rows to return 30 rows, and an unintended loop triggered about 315,000 runs across two billing cycles. In the Oct 15 – Nov 15 cycle alone, 1,447,580,203,670 rows (1.44 trillion rows) were read, on top of the previous cycle’s usage. The author says the October invoice IN-83890481 was $529.88 USD, paid in full out of pocket; the November invoice IN-89082487 was $1,599.12 USD ($1,447.58 D1 Rows Read + $6.16 Workers CPU + $145.38 tax); and the total billed was $2,129.00 USD against an expected budget of about $20/month. After noticing the issue on Nov 2–3, the author deleted the Worker and the D1 database; Support confirmed all reads had stopped. In case #02408621, Support offered a $275.00 courtesy credit for October and advised holding it until the November invoice was issued on Nov 15. In case #02434399, Support applied a one-time courtesy credit of $953.74 (which included the held $275.00), leaving a final balance of $645.38 USD, and said the review was complete and no further adjustments can be made. The author, having already paid $529.88, says the remaining $645.38 cannot be afforded and the account will be downgraded on Nov 22. The author also says a budget alert fired once at the $37 mark but did not stop the charges, and that D1 currently has no hard spending cap. There is no Cloudflare staff reply on the public thread; the Support actions are reported by the author.
sean1093/purse-strings: in-process LLM spend budgets, with optional Durable Objects or KV stores
The MIT-licensed TypeScript library purse-strings (sean1093/purse-strings) is described as a denial-of-wallet guard for apps that call LLM APIs: per-user, per-session and global token, cost and request budgets, plus step, tool-call and time limits for agent loops. It has zero runtime dependencies and can keep counters in memory, Firestore, or Cloudflare Durable Objects or Workers KV. The README warns that with multiple process replicas, each replica enforces the limit, so the effective limit is N times the configured value unless a shared store is used, and that a Durable Objects or KV store is what a hard limit needs. Reviewed from the public README on 2026-11-19. Example figures in the docs include a user-daily cap of costUsd: 1 and a fleet-daily cap of costUsd: 200.