返回提示词目录第 1315 页

实时协同编辑系统架构设计

根据文档类型与并发需求选择合并机制,设计同步、持久化、权限校验及在线状态通道。

完整提示词

<context>
Most "collaborative" features do not need a CRDT. If people rarely edit the same field at once, field-level last-writer-wins with conflict detection, or soft locks ("Anna is editing"), is cheaper and easier to reason about. True simultaneous editing of rich text or structured documents needs either operational transform (a central server transforms concurrent operations; mature for text, hard to build correctly) or CRDTs (replicas converge without a central order; good for offline and peer sync, at the cost of metadata growth and tombstones). Mature libraries exist for both, and writing a merge algorithm from scratch is rarely justified. The data model decides what merges well: a list of blocks with stable ids merges better than one big string, and moving items needs explicit support. The server still matters with CRDTs: it authenticates, checks permissions per update, persists updates and periodic snapshots, and rejects edits to parts a user may not change. Presence (cursors, selections) is ephemeral and should travel on a separate channel, never stored in the document. Undo must be per-user, not global.
</context>

<task>
<document>
{{document}}
</document>
{{#requirements}}
Requirements: {{requirements}}
{{/requirements}}
{{#stack}}
Stack: {{stack}}
{{/stack}}

1. If a repository is available, read the current document model, save path and editor integration before proposing changes.
2. Decide whether real concurrent editing is required. If conflicts are rare or per-field, recommend locking or field-level merge with conflict detection and explain the threshold for moving to CRDT or OT.
3. If concurrent editing is required, choose CRDT or OT for this document type and requirements (offline need tips toward CRDT; a central server and text-only tip toward either), and recommend using an established library over a custom algorithm, naming the property to look for rather than inventing library features.
4. Design the document representation: stable ids for blocks, rows or shapes, what is a register versus a list versus a map, and how moves and deletes behave.
5. Describe sync: local apply, send updates, server relay and persist, peers apply, awareness channel for presence, and reconnect with state vector or version exchange.
6. Describe persistence: append updates, periodic snapshots, compaction of history, named versions, and per-user undo.
7. Describe server-side permission checks per update, validation of document schema, and how schema migrations apply to live documents.
</task>

<constraints>
- Do not recommend writing a custom CRDT or OT algorithm unless the user has a stated reason; point to proven libraries and the properties to check.
- Do not claim a library supports a feature unless you are sure; say what to verify.
- Never trust the client for permissions; every update is checked on the server.
- Keep presence out of the persisted document.
{{> output/uncertainty}}
</constraints>

<output_format>
## Recommendation
CRDT, operational transform, or simpler locking or last-writer-wins, and why, in at most five lines.
## Data model
How the document is represented for merging and what granularity conflicts resolve at.
## Sync architecture
A Mermaid diagram plus steps from local edit to every peer, including reconnect.
## Persistence and history
Snapshots, update logs, compaction, versions and undo.
## Permissions and validation
How the server enforces who may change what.
## Presence
Cursors, selections and awareness, kept out of the document.
## Risks
Bullets: performance, document growth, schema changes, test strategy.
</output_format>

可替换内容

  • {{document}}
  • {{#requirements}}
  • {{requirements}}
  • {{/requirements}}
  • {{#stack}}
  • {{stack}}
  • {{/stack}}
  • {{> output/uncertainty}}

分类与标签

编程开发、协同编辑、冲突合并、实时同步、文档持久化、权限校验

前往 AI 图片创作