跳过导航
Quick demo of Zero’s new background queries.
0:00 / 1:01

Quick demo of Zero’s new background queries.

Aaron Boodman

@aboodman9974 位关注者

在 X 上查看
137 个赞下载原帖

18,837 次观看

Quick demo of Zero’s new background queries. Zero’s sync is query-based. Rather than specifying what data you want using rules or some other separate system, you just use queries. Right inside the client app, you do a query using a full sql-style language. You get filters, subqueries , limits, etc. Zero syncs the data backing these queries to the client. It’s important to realize Zero isn’t really a cache. It’s a replica. It’s eagerly replicating a precise snapshot of a slice of your database - the slice covered by the queries you have open. So there is never stale data in Zero. When you close a query we delete the rows uniquely returned by that query because we can no longer keep them up to date. Of course that kind of sucks for the common case of doing a query, navigating, then pressing “back”. Ideally we want that back nav to be fast. To address this Zero 0.17 adds background queries. You can add a ttl to a query and it will keep running and syncing in the background. This is much different than normal caching because this data stays up to date. If you make the same query again, the results will be *instantly* available *and already up to date with server*. If you make a different query the data from the background query is used client-side to answer the new query instantly if possible. This all happens completely automatically. Just by adding the ttl flag.

11 条评论

评论来自 X (Twitter) 上的原帖

  • Johannes Schickling 的头像

    @schickling

    Dope tech, dope video demo, dope music choice! 🔥

    5 个赞

  • typeofalex 的头像

    @typeofalex

    „background queries“ SPAs like they always should have been 🎉

    2 个赞

  • kitze 🚀 的头像

    @thekitze

    is a cloud version coming soon?

    2 个赞

  • Aaron Boodman 的头像

    @aboodman

    Yep

    3 个赞

  • Khagesh Sharma 的头像

    @khagesh17

    Looks like GraphQL bundled with backend code to access db. Won't it have same problems as GraphQL?

    1 个赞

  • Aaron Boodman 的头像

    @aboodman

    It’s not very much like graphql at all. GraphQL is about abstracting query description from implementation: you describe queries in an abstract syntax and impl can vary. Zero is like the opposite: query language and inpl are coupled (zero provides the only impl). Also Zero is streaming socket based and incremental vs GraphQL which is request/response. So no, it has entirely different problems 😆(and some benefits too). Is there a specific GraphQL problem you’re worried about?

  • Davide Segullo 的头像

    @davide_segullo

    the only thing I do not understand about zero is whether it is possible to integrate it with an existing backend (already having REST services) or if you have to migrate to a specific architecture

    1 个赞

  • Juan 的头像

    @ditorodev

    so wait, using zero i would just not need a backend api?

  • Aaron Boodman 的头像

    @aboodman

    Not in the normal sense. You still have the option* to put code on server for auth, custom validation, etc., but the basic read/write model is you specify queries on the client directly against the backend db and they sync continuously. It feels like having direct access to program against backend db from client.

    2 个赞

  • Zach 的头像

    @zachrip_

    What are the perf implications? Would it be unwise to set a ttl in days? And what happens if I hit the back button without this ttl?

  • Aaron Boodman 的头像

    @aboodman

    The expectation is to set ttls of days or even years. Our dogfood app zbugs uses ttl “forever” for some base queries that we expect the user to always need, and ttl “1d” for other queries. We also use ttl “none” for some queries that don’t need to be maintained. This is possible because Zero uses a custom built incremental query engine. “ZQL” can maintain queries far more efficiently than simply re-running them over and over. Like any query it’s definitely possible to write slow zql queries - not least because it’s in alpha. But the intent is to keep these queries running for long periods and we’ve designed the whole system to make this possible.

    2 个赞