docs(d1): add rules of D1 best practices guide#31814
Conversation
Review
Code ReviewThis code review is in beta and may not always be helpful — use your judgment. No code review issues found. ConventionsChecks PR title, description, and redirect checklist. No convention issues found. Style Guide ReviewWarnings (3)
Suggestions (4)
RedirectsNo missing redirect entries found. CommandsOnly codeowners can run commands. Post a comment with the command to trigger it.
|
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
PR Review: docs(d1): add rules of D1 best practices guideLabels
Summary What looks good
Issues to address before merging
Bottom line |
|
|
||
| A location hint is a preference, not a guarantee, and write latency is always dominated by the primary's location even when read replicas exist. Refer to [Data location](/d1/configuration/data-location/) for the full list of hints and for jurisdiction constraints. | ||
|
|
||
| ### Use the Sessions API so you can add replicas later |
There was a problem hiding this comment.
Getting started doesn't use the sessions API:
https://developers.cloudflare.com/d1/get-started/#write-queries-within-your-worker
|
Hey there, we've marked this pull request as stale because there's no recent activity on it. This label helps us identify PRs that might need updates (or to be closed out by our team if no longer relevant). |
…igration guidance
…cronym spelling, number words, WITH clarification
Reworks the Rules of D1 best practices page around the prioritized D1 guidance: when to use D1, one consistent sample schema, indexed querying, batched writes, parameter binding, retry/idempotency patterns, migration safety, location hints, sessions for read replication, and single-database scaling limits.
8590586 to
9cb31a5
Compare
Moves the opening flow to overview, When to use D1, limits, and scale-out guidance. Expands the When to use D1 section with guidance on when to choose D1 versus KV, Durable Objects, R2, and Hyperdrive. Moves database limits and horizontal scale-out guidance near the top before the detailed rules.
Refines public-doc wording for migration tooling, switches dynamic SQL terminology from whitelist to allowlist, clarifies sharding trade-offs across D1 databases, and explains the boundary between automatic D1 retries and application-level retry handling for idempotent writes.
Summary
Rebased this PR onto the current
productionbranch and revised the new Rules of D1 best-practices guide undersrc/content/docs/d1/best-practices/rules-of-d1.mdx.The guide now prioritizes the D1 product guidance from the latest notes and centralizes rules currently spread across D1 docs:
JOINoperations and no ACID transactions across database boundaries.PRAGMA optimize,EXPLAIN QUERY PLAN, and D1 Insights.db.batch()instead of sequential.run()calls..bind()and allowlisted dynamic SQL identifiers.d1_migrationsrisk.Validation
origin/productioncompleted successfully.git diff --checksuccessfully after the latest edits.pnpm exec prettier --check src/content/docs/d1/best-practices/rules-of-d1.mdxunder Node 24 successfully.pnpm exec astro checkunder Node 24; result: 0 errors, 0 warnings, existing repository hints only.Notes
A follow-up PR can add a dedicated Drizzle-specific D1 page as discussed.