(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=40788648

Triplit(、GitHub:)的创始人 Matt 和 Will 介绍了他们的创新开源数据库解决方案。 Triplit 统一了服务器端数据库、客户端缓存和同步引擎。 要开始使用 Triplet,请通过 npm、Bun 或 Yarn 命令启动新项目。 创建者的目标是提供无缝的本机应用程序用户体验,同时保持协作 Web 功能,但在实现本地缓存、确保缓存同步、处理错误和生成 TypeScript 代码方面遇到了挑战。 由于对不同库和基础设施服务中的这些问题感到沮丧,他们设想了一种简化的替代方案 - Triplet。主要优点包括通过 Typescript 定义模式、与完整 TypeScript 类型实时同步,以及在没有容器依赖的情况下独立运行。 Triplet 的独特之处在于 它能够在向客户端发送粒度更新之前获取每个查询的最低数据要求。 与完全同步或重复查询模拟的传统方法不同,此方法可确保适合 Web 应用程序的快速响应时间。Triplit 采用无冲突复制数据类型 (CRDT) 本地优先方法。 通过将实体中的每个属性视为最后一个写入者获胜寄存器,Triplet 促进了离线功能,从而在同步期间收敛到一致状态。 与更复杂的解决方案相比,它的简单性也使其速度更快。 未来的计划包括添加用于身份验证、文件上传和状态的 API,以反映 Firebase 或 Supabase 体验。 从 开始。

相关文章

原文
Hey HN, we’re Matt and Will, the co-founders of Triplit (https://www.triplit.dev). Triplit is an open-source database (https://github.com/aspen-cloud/triplit) that combines a server-side database, client-side cache, and a sync engine into one cohesive product. You can try it out with a new project by running:
  (npm|bun|yarn) create triplit-app
As a team, we’ve worked on several projects that aspired to the user experience of Linear or Superhuman, where every interaction feels instant like a native app while still having the collaborative and syncing features we expect from the web. Delivering this level of UX was incredibly challenging. In each app we built, we had to implement a local caching strategy, keep the cache up to date with optimistic writes, individually handle retries and rollbacks from failures, and do a lot of codegen to get Typescript to work properly. This was spread across multiple libraries and infrastructure providers and required constant maintenance.

We finally decided to build the system we always wanted. Triplit enables your app to work offline and sync in real-time over websockets with an enjoyable developer experience.

Triplit lets you (1) define your schema in Typescript and simply push to the server without writing migration files; (2) write queries that automatically update in real-time to both remote changes from the server and optimistic local mutations on the client—with complete Typescript types; (3) run the whole stack locally without having to run a bunch of Docker containers.

One interesting challenge of building a system like this is enabling partial replication and incremental query evaluation. In order to make loading times as fast as possible, Triplit will only fetch the minimal required data from the server to fulfill a specific query and then send granular updates to that client. This differs from other systems which either sync all of a user’s data (too slow for web apps) or repeatedly fetch the query to simulate a subscription (which bogs down your database and network bandwidth).

If you’re familiar with the complexity of cache-invalidation and syncing, you’ll know that Triplit is operating firmly in the distributed systems space. We did a lot of research and settled on a local first approach that uses a fairly simple CRDT (conflict-free replicated data type) that allows each client to work offline and guarantees that they will converge to a consistent state when syncing. It works by treating each attribute of an entity as a last writer wins register. Compared to more complex strategies, this approach ends up being faster and doesn’t require additional logic to handle conflicting edits between concurrent writers. It’s similar to the strategy Figma uses for their collaborative editor.

You can add Triplit to an existing project by installing the client NPM package. You may self-host the Triplit Server or pay us to manage an instance for you. One cool part is that whether you choose to self-host or deploy on Triplit Cloud, you can still use our Dashboard to configure your database or interactively manage your data in the Triplit Console, a spreadsheet-like GUI.

In the future, we plan to add APIs for authentication, file uploads, and presence to create a Supabase/Firebase-like experience.

You can get started by going to https://triplit.dev or find us on Github https://github.com/aspen-cloud/triplit. Thanks for checking us out and we are looking forward to your feedback in the comments!

联系我们 contact @ memedata.com