News for hackers. Stuff that matters.
Re:D1: Our SQL database by vlovich123 on Wednesday May 11, 2022 @10:19AM (#31340331)
D1 does not throw away consistency. It’s built on top of Durable Objects which is globally strongly consistent.
Re:D1: Our SQL database by smarx007 on Wednesday May 11, 2022 @10:50AM (#31340774)
"D1 will create read-only clones of your data, close to where your users are, and constantly keep them up-to-date with changes."

Sounds like there will be no synchronous replication and instead there will be a background process to "constantly keep [read-only clones] up-to-date". This means that a stale read from an older read replica can occur even after a write transaction has successfully committed on the "primary" used for writes.

So, while the consistency is not "thrown away", it's no longer a strong consistency? Anyway, Kyle from Jepsen will figure it out soon, I guess :)

Re:D1: Our SQL database by geelen on Wednesday May 11, 2022 @11:29AM (#31341439)
Yeah, so you can always opt-in to strong consistency by transferring execution to the primary (see the "Embedded Compute" section of the blog). Then it's pretty much exactly the same as a DO.
Re:D1: Our SQL database by greg-m on Wednesday May 11, 2022 @10:59AM (#31340942)
Just clarifying - D1 without read replicas is strongly consistent. If you add read replicas, those can have replication lag and will not be strongly consistent.

Disclaimer: I work at Cloudflare :)

Re:D1: Our SQL database by infogulch on Wednesday May 11, 2022 @11:13AM (#31341151)
Thanks for the clarification, that is what I would expect.

Does SQLite support some kind of monotonic transaction id that can be used as a cache coherency key? Say a client writes a new record to the database which returns `{"result": "ok", "transaction_id": 123}`, then to ensure that subsequent read requests are coherent they provide a header that checks that the read replica has transaction_id >= 123 and either waits for replication before serving or fails the request. (Perhaps a good use for the embedded worker?)

Re:D1: Our SQL database by discodave on Wednesday May 11, 2022 @04:41PM (#31345480)
Since it's a relational DB, and supports transactions, you can have a journal table right?

I know of a very important system at AWS that did this with MySQL :D

Re:D1: Our SQL database by infogulch on Thursday May 12, 2022 @10:28AM (#31354737)
Yes you could do it manually, but it would be nice if the solution didn't require carefully managing update queries so the journal addition isn't missed and increasing write amplification to manually update a journal table when that information probably already exists somewhere in the WAL implementation.
Re:D1: Our SQL database by vlovich123 on Wednesday May 11, 2022 @11:41AM (#31341585)
Yup sorry about that. I missed the entire "read replica" bit when reading that blog post.
Re:D1: Our SQL database by mwcampbell on Wednesday May 11, 2022 @10:25AM (#31340410)
Interesting that D1 is built on top of Durable Objects. Does this mean that it would be practical for a single worker to access multiple D1 databases, so it could use, for example, a separate database for each tenant in a B2B SaaS application? Edit: And could each database be in a different primary region?
Re:D1: Our SQL database by a-robinson on Wednesday May 11, 2022 @10:38AM (#31340593)
Yes, exactly!
Re:D1: Our SQL database by hn_ei_ser_23 on Wednesday May 11, 2022 @10:30AM (#31340491)
That is interesting. I wish CF would give us some more information as I've assumed that there must be a lack of strong consistency which would be a major drawback.

Edit: But that would mean that durable objects can't be replicated asynchronously? That would mean a big latency hit. Then what's the difference to a central DB in one datacenter?

Re:D1: Our SQL database by kwizzt on Wednesday May 11, 2022 @10:28AM (#31340448)
I’m not familiar with Durable Objects. When D1 does replication to read replicas, if it’s not doing synchronous replication, then it’s not strongly consistent, is that correct?
Re:D1: Our SQL database by the_duke on Wednesday May 11, 2022 @10:32AM (#31340507)
I wish the post had provided some more technical details.

It's more of a "quickstart" than a peek under the hood.

Re:D1: Our SQL database by unraveller on Wednesday May 11, 2022 @01:39PM (#31343280)
I'd like to see some up front D1 & R2 benchmarks (read/write/iops). I can't judge invocation cost value until I can judge my use case performance. Here's hoping its -gt NVMe raid 10 under the hood of D1 as some big SQLite reads suffer under slow storage.
Re:D1: Our SQL database by jpcapdevila on Wednesday May 11, 2022 @10:59AM (#31340941)
Are you guys using litestream or a similar approach? E.g storing WAL frames in a durable object.