TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

D1: Our SQL database

592 点作者 elithrar大约 3 年前

43 条评论

slashdev大约 3 年前
For a Cloudflare article, this one is surprisingly light on technical details. And for the product where it most matters.<p>I&#x27;m guessing this is a single master database with multiple read replicas. That means it&#x27;s not consistent anymore (the C in ACID). Obviously reads after a write will see stale data until the write propogates.<p>I&#x27;m a bit curious how that replication works. Ship the whole db? Binary diffs of the master? Ship the SQL statements that did the write and reapply them? Lots of performance and other tradeoffs here.<p>What&#x27;s the latency like? This likely doesn&#x27;t run in every edge location. Does the database ship out on the first request. Get cached with an expiry? Does the request itself move to the database instead of running at the edge - like maybe this runs on a select subset of locations?<p>So many questions, but no details yet.
评论 #31342530 未加载
评论 #31341831 未加载
评论 #31341661 未加载
评论 #31343847 未加载
评论 #31357560 未加载
kurinikku大约 3 年前
wow SQLite getting a lot of love these days<p><a href="https:&#x2F;&#x2F;tailscale.com&#x2F;blog&#x2F;database-for-2022" rel="nofollow">https:&#x2F;&#x2F;tailscale.com&#x2F;blog&#x2F;database-for-2022</a><p><a href="https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;all-in-on-sqlite-litestream" rel="nofollow">https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;all-in-on-sqlite-litestream</a><p><a href="https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;introducing-d1" rel="nofollow">https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;introducing-d1</a>
评论 #31342984 未加载
评论 #31339990 未加载
评论 #31339935 未加载
评论 #31340008 未加载
评论 #31340772 未加载
评论 #31340135 未加载
评论 #31340525 未加载
jgrahamc大约 3 年前
BTW R2 is open beta now: <a href="https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;r2-open-beta&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;r2-open-beta&#x2F;</a>
评论 #31341385 未加载
losvedir大约 3 年前
Wow, this looks potentially very interesting. Since this is sort of fresh in my mind from the recent Fly post about it:<p>* How exactly is the read replication implemented? Is it using litestream behind the scenes to stream the WAL somewhere? How do the readers keep up? Last I saw you just had to poll it, but that could be computationally expensive depending on the size of the data (since I thought you had to download the whole DB), and could potentially introduce a bit of latency in propagation. Any idea what the metrics are for latency in propagation?<p>* How are writes handled? Does it do the Fly thing about sending all requests to one worker?<p>I don&#x27;t quite know what a &quot;worker&quot; is but I&#x27;m assuming it&#x27;s kind of like a Lambda? If you have it replicated around the world, is that one worker all running the same code, and Cloudflare somehow manages the SQL replicating and write forwarding? Or would those all be separate workers?
hn_ei_ser_23大约 3 年前
First, I&#x27;m very excited. Sure, SQLite has some limitations compared to Postgres, esp. regarding the type system and concurrency. But we get ACID compliance and SQL.<p>But it is really hard getting some useful information from this article. I can&#x27;t even tell if it is not there or just buried in all this marketing hot air.<p>So, what is it really? Is there one Write-Master that is asynchronously replicated to all other locations? Will writes be forwarded to this master and then replicated back?<p>I&#x27;m very curious about how it performs in real life. Especially considering the locking behavior (SQLite has always the isolation level &#x27;serializable&#x27; iirc). The more you put in a transaction or the longer you have to wait for another process to finish their writes, the more likely you have to deal with stale data.<p>But overall I&#x27;m very excited. Also by the fly.io announcement, of course. Lots of innovation and competition. Good times for customers.
评论 #31340675 未加载
infogulch大约 3 年前
Very cool! Glad to see all the love for SQLite recently.<p>One thing I&#x27;ve noticed that many commenters miss about read-replicated SQLite is assuming that the only valid model is having <i>one</i>, giant, centralized database with all the data. Lets be honest with ourselves, the vast majority of applications hold personal or B2B data and don&#x27;t need centralized transactions, and at scale will use multi-tenant primary keys or manual sharding anyways. For private data, a single SQLite database per user &#x2F; business will <i>easily</i> satisfy the write load of all but the most gigantic corporations. With this model you have unbounded compute scaling for new users because they very likely don&#x27;t need online transactions across multiple databases at once.<p>Some questions:<p>Will D1 be able to deliver this design of having many thousands of separate databases for a single application? Will this be problematic from a cost perspective?<p>&gt; since we&#x27;re building on the redundant storage of Durable Objects, your database can physically move locations as needed<p>Will D1 be able to easily migrate the &quot;primary&quot; at will? CockroachDB described this as &quot;follow the sun&quot; primary.
评论 #31342974 未加载
fzaninotto大约 3 年前
Love the Northwind Traders reference! However, for a demo, I suggest a slightly larger and more complex data set, [data-generator-retail](<a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;data-generator-retail" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;data-generator-retail</a>).<p>The demo is also a bit buggy: orders are duplicated as many times as there are products, but clicking on the various lines of the same order leads to the same record, where the user can only see the first product...<p>I also think the demo would have more impact if it wasn&#x27;t read-only (although I understand that this could lead to broken pages if visitors mess up with the data).<p>Anyway, kudos to the CloudFlare team!
评论 #31340531 未加载
评论 #31342355 未加载
ranguna大约 3 年前
This looks amazing!<p>I see cloudflare people are on this post, any chance to compar D1 vs postgres in terms of DB features?<p>Insert ... Returning<p>Stored procedures and triggers<p>Etc etc<p>Would be really helpful to get a comparison like cockroachDB did here <a href="https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;docs&#x2F;stable&#x2F;postgresql-compatibility.html" rel="nofollow">https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;docs&#x2F;stable&#x2F;postgresql-compati...</a><p>Or even better, a general sql compatibility matrix like this <a href="https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;docs&#x2F;stable&#x2F;sql-feature-support.html" rel="nofollow">https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;docs&#x2F;stable&#x2F;sql-feature-suppor...</a><p>Kudos to the cloudflare team!
评论 #31340089 未加载
评论 #31340740 未加载
评论 #31340137 未加载
the_duke大约 3 年前
All this recent hype around sqlite...<p>sqlite is a great embedded database and thanks to use by browsers and on mobile the most used database in the world by orders of magnitude.<p>But it also comes with lots of limitations.<p>* there is no type safety, unless you run with the new strict mode, which comes with some significant drawbacks (eg limited to the handful of primitive types)<p>* very narrow set of column types and overall functionality in general<p>* the big one for me: limited migration support, requiring quite a lot of ceremony for common tasks (eg rewriting a whole table and swapping it out)<p>These approaches (like fly.io s) with read replication also (apparently?) seem to throw away read after write consistency. Which might be fine for certain use cases and even desirable for resilience, but can impact application design quite a lot.<p>With sqlite you have do to a lot more in your own code because the database gives you fewer tools. Which is usually fine because most usage is &quot;single writer, single or a few local readers&quot;. Moving that to a distributed setting with multiple deployed versions of code is not without difficulty.<p>This seems to be mitigated&#x2F;solved here though by the ability to run worker code &quot;next to the database&quot;.<p>I&#x27;m somewhat surprised they went this route. It probably makes sense given the constraints of Cloudflares architecture and the complexity of running a more advanced globally distributed database.<p>On the upside: hopefully this usage in domains that are somewhat unusual can lead to funding for more upstream sqlite features.
评论 #31340893 未加载
评论 #31341339 未加载
评论 #31340331 未加载
评论 #31340761 未加载
评论 #31340409 未加载
评论 #31341699 未加载
ngrilly大约 3 年前
Not clear from reading the post if the SQLite C library is embedded and linked in the Worker runtime (which would mean no network roundtrip) or if each query or batch of queries is converted to a network request to a server embedding the SQLite C library.<p>That&#x27;s important to understand because that&#x27;s one of the key advantages of SQLite compared to the usual client-server architecture of databases like PostgreSQL or MySQL: <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;np1queryprob.html" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;np1queryprob.html</a>
samwillis大约 3 年前
This is really interesting, it&#x27;s (basing it on SQLite) exactly what I was expecting CloudFlare to do for their first DB.<p>Its perfect for content type sites that want search and querying.<p>Anyone from CF here, is it using Litestream (<a href="https:&#x2F;&#x2F;litestream.io" rel="nofollow">https:&#x2F;&#x2F;litestream.io</a>) for its replication or have you built your own replication system?<p>I assume this first version is somewhat limited on write performance having a single &quot;main&quot; instance and SQLite laking concurrent writes? It seems to me that using SQLite sessions[0] would be a good way to build an eventually consistent replication system for SQLite, would be perfect for an edge first sql database, maybe D2?<p>0: <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;sessionintro.html" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;sessionintro.html</a>
评论 #31339466 未加载
endisneigh大约 3 年前
Have any of the problems that led people to use Postgres instead of SQLite actually been solved? Are we doomed to repeat the same mistakes?<p>Also, any plans to support PATCH x-update-range so SQLite can be used entirely in the browser via SQLite.js?<p>Can someone enlighten me with the types of use cases this would be better for vs say Postgres?
评论 #31340958 未加载
评论 #31340256 未加载
评论 #31340356 未加载
评论 #31340216 未加载
lucasyvas大约 3 年前
To the person from Cloudflare I complained to in last year&#x27;s thread about putting your money where your mouth is on serverless databases:<p>You weren&#x27;t lying, and this is super cool - the SQLite hype train also seems to be in full force.
评论 #31340905 未加载
评论 #31340898 未加载
rmbyrro大约 3 年前
I&#x27;m buying Cloudflare stocks right now.<p>In 2-3 years from now, these services will be so mature and strong they will be crushing the cloud market.<p>They&#x27;re turning dreams into reality, one after another.
评论 #31340545 未加载
jpcapdevila大约 3 年前
If SQLite gets you excited, I&#x27;m building a firebase alternative based on sqlite. I&#x27;m betting hard on sqlite so this get&#x27;s me super excited!!<p><a href="https:&#x2F;&#x2F;javascriptdb.com" rel="nofollow">https:&#x2F;&#x2F;javascriptdb.com</a><p>CF people around, I would love to chat, if anyone is interested please reach out at: jp@javascriptdb.com<p>I&#x27;ll be applying to this beta for sure!
评论 #31343991 未加载
mwcampbell大约 3 年前
Any current or planned support for existing ORMs, such as Prisma or TypeOrm?<p>Also, I wonder how hard it will be to migrate existing PostgreSQL databases and SQL statements. Of course, I understand if Cloudflare is focused on greenfield applications.
评论 #31341513 未加载
评论 #31340223 未加载
评论 #31339775 未加载
评论 #31340236 未加载
ryanto大约 3 年前
This is so cool!<p>From the blog post it says read-only replicas are created close to users and kept up to date with the latest data.<p>- How should I think about this in terms of CAP? If there&#x27;s a write and I query a replica what happens?<p>- How are writes handled? Do they go to a single location or are they handled by various locations?<p>I&#x27;m excited to try this. It&#x27;s so cool to see databases being distributed &quot;on CDNs&quot; for lack of a better term.
评论 #31340352 未加载
tyingq大约 3 年前
<i>&quot;With D1, it will be possible to define a chunk of your Worker code that runs directly next to the database...each request first hits your Worker near your users, but depending on the operation, can hand off to another Worker deployed alongside a replica or your primary D1 instance to complete its work.&quot;</i><p>That&#x27;s interesting to me. It opens the door for Cloudflare to offer something more like a &quot;normal&quot; serverless offering. One that can run containers, or least natively run Python&#x2F;Golang&#x2F;Java&#x2F;etc, like AWS Lambda does. And with this ecosystem described above that can conditionally route between the lighter edge Workers and the heavier central serverless functions. To me, that&#x27;s the tipping point where they start to threaten larger portions of AWS.
SheinhardtWigCo大约 3 年前
Big fan of Cloudflare but I wish they would stick to descriptive product names.<p>Good: Workers, KV, Durable Objects, Cron Triggers<p>Bad: Spectrum, Zaraz, R2, D1
评论 #31342369 未加载
lucasyvas大约 3 年前
The API for this is currently the only thing I wish I could grok a bit better. It seems like it would be hard to make it work with existing libraries that can access SQLite, which is kind of a shame.<p>I&#x27;m thinking of sqlx in Rust (or any other language binding &#x2F; ORM for that matter), which has compile time schema safety. This is a nice capability, and because this interface seems non-standard (possibly for good reason), I guess we are being asked to give some of those things up.<p>I am getting a bit ahead of myself on the Rust part (presumably that will eventually be supported as part of workers-rs), but I think the feelings still stand if you consider the JS ecosystem.<p>Edit: I may actually be wrong, but presumably the entire surface isn&#x27;t covered because there&#x27;s no file opening, etc.
评论 #31341228 未加载
irq-1大约 3 年前
Best Effort Writes[1] are an opportunity here. Non-transactional, write to the local replica (ensure foreign keys, constrains, valid data, etc...) and then <i>try</i> to write to the main write-enabled DB. Caching should work without changes since the local replica is updated. This could be cheaper (send binary diffs) and more resilient to brief network issues.<p>The key is to let the user decide what really needs ACID and what doesn&#x27;t. If someone wants to make the next Facebook or Reddit they&#x27;ll need huge write throughput and if some votes or updates are lost, that may be a good trade-off.<p>[1] You could add a BEW file (like WAL file) to sqlite for Best Effort Writes.
didip大约 3 年前
All these hype around SQLite recently and I am still confused.<p>* How do you replicate it consistently?<p>* Who has the master privilege (or masters if sharded)? What&#x27;s the failover story?<p>I am guessing a blob store is involved, but I have gaps in my understanding here.
评论 #31345552 未加载
frogger8大约 3 年前
Not a expert on DOM or JavaScript so be kind ;)<p>One thing I hope to see in the future is a better product filtering experience. When I worked on a jquery product filter I realized the DOM bloat was the main problem.<p>I wonder if D1 can help devs build instant product filtering pages that don’t require the reload like microcenter or Newegg does.<p>IE <a href="https:&#x2F;&#x2F;www.newegg.com&#x2F;p&#x2F;pl?d=hdmi+cable&amp;N=-1&amp;SortType=8" rel="nofollow">https:&#x2F;&#x2F;www.newegg.com&#x2F;p&#x2F;pl?d=hdmi+cable&amp;N=-1&amp;SortType=8</a>
评论 #31339739 未加载
评论 #31340206 未加载
_kyran大约 3 年前
So can we assume that D2 will be postgres&#x2F;mysql ?
评论 #31340325 未加载
greenie_beans大约 3 年前
dang i was hoping for postgres so i can use postgis<p>edit: maybe one day! this looks cool regardless
评论 #31340418 未加载
评论 #31346872 未加载
aeyes大约 3 年前
What write throughput and latency can we expect from this database?<p>Are there any limitations, for example on the number of tables or size of the database?
xwdv大约 3 年前
With this we can probably switch our infrastructure off AWS and entirely onto Cloudflare.
pier25大约 3 年前
So where are the databases running? In the same regions as workers?<p>Is the data replicated to all regions?
dinkleberg大约 3 年前
This is convenient, I’ve been building an app which is using SQLite but am wanting to deploy it to Cloudflare pages. I expected I was going to have to switch to a hosted Postgres instance somewhere, but this could be perfect.
jcuenod大约 3 年前
So I assume we&#x27;ll see a nice big donation to the sqlite coffers, then?
ralusek大约 3 年前
Unless I missed it by skimming, where are the deets? Is this strongly or eventually consistent? What are max table sizes, and do they become partitioned? Are there cross partition joins?
robertlagrant大约 3 年前
This looks awesome. I was thinking about creating a custom version of this to live behind a CF Worker. Much better to have an official version!
estensen大约 3 年前
Too bad you probably can&#x27;t use this to store data about EU citizens. Phone numbers like they show in the demo are considered PII, right?
评论 #31341829 未加载
whitepaint大约 3 年前
Will they seriously challenge Azure, AWS and GCP eventually? Cloudflare is very innovative and what they are doing is really exciting.
评论 #31341418 未加载
philholden大约 3 年前
Glad to hear was considering moving to Deno Deploy + Supabase because KV was not good for relationships.
jzer0cool大约 3 年前
How does this work when developing locally. Is it SQLite for local development?
benjiweber大约 3 年前
I was expecting this to be using <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;D_(data_language_specification)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;D_(data_language_specification...</a> given the name.
polskibus大约 3 年前
Is this going to be open sourced? Seems to be building on the shoulder of a particular giant that could use a bit wider ecosystem.
deanc大约 3 年前
Any word on pricing =)?
oxff大约 3 年前
Its a bold strategy, Cotton, sounding a bit like they want to compete with AWS.
onphonenow大约 3 年前
Our first database … I like it. I wonder what’s next
alberth大约 3 年前
First, super excited by having Cloudflare offer a RDMS (can SQLite be called that?)<p>This enables entirely new classes of applications where everything can now be hosted by Cloudflare.<p>Questions:<p>a. To help with concurrent writes, will Cloudflare be using WAL2 and BEGIN CONCURRENT branches of SQLite?<p>b. How is Cloudflare replicating the data cross region? Will it be Litestream.io behind the scenes?<p>c. Will our Worker code need to be written differently to ensure only a single-writer is writing to SQLite database?<p>d. How does data persistency and database file size get factored in? I have to imagine their is a limit to how much storage can be used, whether or not that storage is local to the Worker machine, and if its persistent.
rvz大约 3 年前
Now is <i>this</i> a Cloudflare ($NET) buy signal? I think you know the answer.<p>Maybe they will announce a Hashicorp competitor in their next reveal. Who knows.