LobeChat Synchronization: an exploration and practice of Local First | LobeChat 云同步: Local First 的一次探索与实践 #1681
Replies: 4 comments 8 replies
-
LobeChat 云同步: Local First 的一次探索与实践在数字化时代,云服务几乎成为了每个网络应用的标配。它们为用户提供了便捷、可靠且灵活的数据存储和访问方式。然而,随着数据安全和隐私问题日益受到重视,“Local First”这一概念从去年开始变逐渐变得流行起来。 Local First 的启蒙2022年,我读到《Local-first software》这篇文章,该文倡导将本地作为数据处理和存储的首选位置,并通过精巧设计使得远程同步成为可能但非必需品。这种思维模式对于保护用户隐私、提升应用性能等方面有着不小的好处。《Local First》这篇文章为我开启了新的视角,引发了对于构建以本地为中心,再辅以云同步的产品的深度思考,也为这次实践埋下了种子。 LobeChat 作为开源生态中的一个新兴 AI Chat 应用有着非常活跃的社区,我们收集到了众多关于云端同步功能的诉求。我们的用户期望在不同设备间享受连贯的聊天体验,同时不牺牲数据的私密性和安全性。从用户体验角度出发,如果能够将 Local First 精神与无缝远程同步结合起来,那么所带来的产品体验会是怎样一番景象呢? 这促使我尝试在 LobeChat 中开始探索 Local First 中一种无缝同步到远程的解决方案。 探索与实践决定行动之后,我们选择了基于 YJS 和 WebRTC 技术构建点对点(P2P)同步方案进行尝试。(如果你感兴趣,可以查看:#368 了解详情) 经过2周左右的实践,我初步完成了整个功能的实现,这个方案具有如下的优势:
遭遇挑战:SoT (Source of Truth)困境当然,在具体执行过程中我们也遇到了挑战:如何处理离线期间产生操作?比如 PC 端删除某条消息,而手机端未做更新情形下再次联网时如何处理? “Local First”理念背后隐藏着一个更深层次问题:“真相源头(SoT, Source of Truth)”究竟位于哪里?当涉及多个独立运行且平权节点之间信息不一致时该如何确定唯一真相来源? 目前我们的实现策略相对简单,只要节点重新上线就尽力达成最新状态—确保各设备间内容尽量保持一致;新增或修改操作都会被广播至所有节点上。这意味着只有在所有设备均在线且可通信状态下才能完美解决此类问题。这在用户体验上不够理想,因此我们也认为该功能目前仅处于「实验」状态。同时我们非常希望获得社区的反馈,共同探讨 Local First 这个方向的下一步。 总结总结而言,“Local First”的探索给 LobeChat 带来了诸多启示和改变。从技术选型到架构设计再至特定场景下问题处理方法学都经历重塑。随着第一版的云同步方案上线,我想 LobeChat 的 Local First 之旅也正式拉开帷幕。 |
Beta Was this translation helpful? Give feedback.
-
为了便利性,牺牲一些隐私在服务端似乎也没有太多不妥,反而因为本地,带来了使用上的不便利,这种取舍不一定能给用户带来真实便利,况且,保护用户隐私也有很多手段,例如next-chat采用的upstash的Redis也同样实现了这一策略 |
Beta Was this translation helpful? Give feedback.
-
请问 Could you tell me if the |
Beta Was this translation helpful? Give feedback.
-
LobeChat Synchronization: an exploration and practice of Local First
in the digital age, cloud services have become the standard for almost every network application. They provide users with convenient, reliable and flexible data storage and access methods. However, with the increasing attention paid to data security and privacy issues, the concept of "Local First" has gradually become popular since last year.
Enlightenment of Local First
in 2022, I read Local-first software This article advocates local as the preferred location for data processing and storage, and makes remote synchronization possible but not necessary through exquisite design. This mode of thinking has great benefits in protecting user privacy and improving application performance. The article "Local First" opened a new perspective for me, triggered deep thinking about building Local-centered products, supplemented by cloud synchronization, and also planted seeds for this practice.
LobeChat, as an emerging application in AI Chat open source ecosystem, has a very active community. We have collected many demands for cloud synchronization. Our users expect to enjoy a coherent chat experience between different devices without sacrificing data privacy and security. From the perspective of user experience, if the spirit of Local First can be combined with seamless remote synchronization, what kind of product experience will it bring?
This prompted me to start exploring a seamless synchronization to remote solutions in LobeChat in Local First.
Exploration and practice
After deciding the action, we chose to build a peer-to-peer (P2P) synchronization scheme based on YJS and WebRTC technologies to try. (If you are interested, you can view: #368 for more information)
After about 2 weeks of practice, I have preliminarily completed the implementation of the whole function. This scheme has the following advantages:
Challenge: SoT (Source of Truth) dilemma
of course, we also encountered challenges in the specific implementation process: how to handle operations generated during offline operations? For example, if a message is deleted from a PC and the mobile phone is not updated, what should I do if I connect to the Internet again?
Behind the concept of "Local First" lies a deeper question: where on earth is "the Source of Truth (SoT, Source of Truth)? How to determine the unique truth source when multiple independent nodes are involved and the information between the privileged nodes is inconsistent?
At present, our implementation strategy is relatively simple. As long as the node goes online again, we try our best to achieve the latest status-to ensure that the content of each device is consistent as much as possible; New or modified operations will be broadcast to all nodes. This means that such problems can be perfectly solved only when all devices are online and can communicate. This is not ideal for the user experience, so we also believe that this function is currently only in the "experimental" state. At the same time, we very much hope to get feedback from the community and jointly discuss Local First next step in this direction.
Summary
To sum up, the exploration of "Local First" has brought many inspirations and changes to LobeChat. From technology selection to architecture design to problem handling methodology in specific scenarios, it has undergone reshaping. With the launch of the First version of cloud synchronization, the road to LobeChat Local First has officially begun.
Beta Was this translation helpful? Give feedback.
All reactions