Design a Prompt Editor with Versioning and Collaboration
System DesignModel answerLast updated
Build a web app for writing, executing, and versioning LLM prompts with efficient storage for large documents and incremental edits.
You're building a web application that lets users compose prompts for large language models, execute them, and manage their work over time. Users need to create new prompts, modify them iteratively, run them against an LLM to see results, and collaborate with colleagues.
Your system must handle the full lifecycle: drafting, running, saving versions, retrieving past work, and enabling others to view or build upon existing prompts.
Begin with the fundamental architecture and database schema. The discussion will then progress through specific challenges: handling documents that may reach hundreds of kilobytes, enabling collaboration features, and optimizing storage when users make small character-level changes to large documents repeatedly.
Requirements
Work through each section in order, keeping responses focused on the current challenge:
Section 1: Foundation Design the core system components and database schema. Cover APIs for creating, modifying, saving, listing, and executing prompts. Show how you'd structure entities, relationships, and indexes.
Section 2: Scale Considerations Some documents grow quite large. Explain how your design adapts to store and retrieve them efficiently without degrading performance.
Section 3: Collaboration Add functionality for users to grant others access to their prompts. Define the semantics (snapshot vs live, read vs write permissions) and show how you'd implement access control.
Section 4: Incremental Changes When a user makes dozens of single-character edits to a 500KB document, saving after each one, naive approaches waste enormous storage. Present storage strategies—full copies versus deltas—and discuss where each lives (database vs object storage) with their trade-offs.
Clarification Points
Before diving in, consider:
- Does a prompt include just text, or also model selection and generation parameters?
- What's a realistic size range and hard limit for prompt documents?
- Should all historical versions be preserved and accessible indefinitely?
- Must every execution be perfectly reproducible with its exact input and configuration?
- When collaborating, can recipients modify the original, or do they work with copies?
State your assumptions where specifics aren't provided.
Hints
Hint 1
Think about when to use relational storage versus blob storage based on size thresholds and access patterns
Hint 2
For versioning with small edits, consider delta encoding but also when to materialize full snapshots to bound reconstruction cost
Hint 3
Separate the concept of a prompt template from individual execution runs—they have different lifecycles and access patterns
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
Part 1: Core Architecture and Schema
System Components:
The system consists of a web frontend, an API server, a relational database (PostgreSQL), object storage (S3), and the LLM service. Users interact through the web UI which calls the API for all operations. The API coordinates between the database for metadata and object storage for large content.
Key Entities:
- Users: Authentication and ownership
- Prompts: The top-level containers users create
- Versions: Immutable snapshots of a prompt's content and configuration at save time
- Executions: Records of running a specific version against the LLM with its output
Database Schema:
CREATE TABLE users (
user_id UUID PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE prompts (
prompt_id UUID PRIMARY KEY,
owner_id UUID REFERENCES users(user_id),
title VARCHAR(500),
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW(),
latest_version_id UUID
);
CREATE TABLE prompt_versions (
version_id UUID PRIMARY KEY,
prompt_id UUID REFERENCES prompts(prompt_id),
content TEXT, -- or NULL if stored externally
content_location VARCHAR(500), -- S3 key if external
content_size_bytes INT NOT NULL,
model_name VARCHAR(100),
temperature DECIMAL(3,2),
max_tokens INT,
system_message TEXT,
created_at TIMESTAMP DEFAULT NOW(),
version_number INT NOT NULL,
UNIQUE(prompt_id, version_number)
);
CREATE TABLE executions (
execution_id UUID PRIMARY KEY,
version_id UUID REFERENCES prompt_versions(version_id),
executed_by UUID REFERENCES users(user_id),
output TEXT, -- or NULL if stored externally
output_location VARCHAR(500),
output_size_bytes INT,
tokens_used INT,
latency_ms INT,
executed_at TIMESTAMP DEFAULT NOW()
);
CREATE INDEX idx_prompts_owner ON prompts(owner_id, updated_at DESC);
CREATE INDEX idx_versions_prompt ON prompt_versions(prompt_id, version_number DESC);
CREATE INDEX idx_executions_version ON executions(version_id, executed_at DESC);
Core APIs:
POST /prompts- Create a new prompt, returns prompt_idGET /prompts- List user's prompts with latest version metadataGET /prompts/{id}/versions- List all versions for a promptPUT /prompts/{id}- Update and auto-save a new versionPOST /prompts/{id}/execute- Run the current draft or specific versionGET /executions/{id}- Retrieve a past execution result
The execution flow streams responses to the client while buffering them server-side, then stores the complete output once generation finishes.
Part 2: Handling Large Prompts
Storage Strategy:
Use a size threshold (32KB) to decide placement. Content under the threshold stays in the content TEXT column for low-latency access. Larger content goes to S3 with the key stored in content_location.
Why 32KB? Keeps the common case fast (most prompts are under 10KB) while preventing database bloat and backup overhead for the minority of large documents.
Integrity and Metadata:
Always store content_size_bytes, model_name, and generation parameters in the database regardless of content location. This enables listing versions and checking reproducibility without fetching blobs. Use content hashes (SHA-256) stored in the database to verify S3 objects haven't been corrupted or tampered with.
Upload/Download Paths:
For saves exceeding the threshold, the client gets a presigned S3 upload URL, uploads directly, then confirms completion to the API which creates the version record. For loads, the API returns either inline content or a presigned download URL. This keeps large transfers off the API servers.
Compress content with gzip before storing in S3, typically achieving 3-5× reduction for text. Record both compressed and uncompressed sizes.
Latency Impact:
Database-resident content: single-digit millisecond reads. S3-resident content: 50-100ms additional latency for the HTTP round-trip, amortized over larger payload sizes. For a 500KB prompt, this is acceptable. Pre-generate download URLs during list operations to eliminate an extra API call.
Part 3: Collaboration and Sharing
Sharing Semantics:
Shares grant read-only access to a frozen snapshot of a specific version, not a live view of ongoing edits. Recipients can view and execute the shared version, and can copy it into their own workspace as a starting point, creating a new independent prompt.
This snapshot approach is simpler than live collaboration and matches typical use cases: "here's what worked for me" rather than real-time co-editing.
Data Model:
CREATE TABLE shares (
share_id UUID PRIMARY KEY,
version_id UUID REFERENCES prompt_versions(version_id),
shared_by UUID REFERENCES users(user_id),
share_token VARCHAR(64) UNIQUE NOT NULL, -- URL-safe random string
access_type VARCHAR(20) DEFAULT 'view', -- view, copy
created_at TIMESTAMP DEFAULT NOW(),
expires_at TIMESTAMP, -- NULL means never expires
revoked_at TIMESTAMP -- NULL means active
);
CREATE INDEX idx_shares_token ON shares(share_token) WHERE revoked_at IS NULL;
CREATE INDEX idx_shares_version ON shares(version_id);
Access Control:
When a user accesses /share/{token}, check that: (1) the token exists, (2) revoked_at IS NULL, (3) expires_at IS NULL OR expires_at > NOW(). If valid, return the version and show a "Copy to my workspace" button.
Revocation simply sets revoked_at. Deleting the underlying prompt doesn't cascade-delete shared versions—they remain accessible via the share link. If this is undesirable, add a check that the prompt still exists and the owner hasn't marked it deleted.
Copy-on-Write:
When copying a shared prompt, create a new prompt and version record pointing to the same content_location if content is in S3. Increment a reference count or use content-addressed storage (keying by hash) to prevent orphaning. Don't duplicate the blob until the recipient edits their copy.
Part 4: Efficient Storage for Incremental Edits
The Challenge:
A user edits a 500KB prompt 50 times, changing 1-5 characters each time. Storing 50 full copies wastes 25MB. Storing 50 deltas is space-efficient but makes reconstructing version 50 slow (50 sequential reads and patch applications).
Approach: Hybrid Strategy
Store every Nth version (e.g., every 10th) as a full snapshot, and intermediate versions as forward deltas from the most recent snapshot. To reconstruct version 47, load snapshot 40 and apply deltas 41-47.
Storage Placement:
- Snapshots: S3 for large prompts (>32KB), database TEXT for small ones
- Deltas: Always in the database as structured data
Schema Addition:
ALTER TABLE prompt_versions ADD COLUMN base_version_id UUID REFERENCES prompt_versions(version_id);
ALTER TABLE prompt_versions ADD COLUMN delta_ops JSONB; -- diff operations
If base_version_id IS NULL, this version is a full snapshot. Otherwise, delta_ops contains the diff (using a format like JSON Patch or custom ops).
Trade-offs:
| Approach | Write Cost | Read Cost | Storage Cost |
|---|---|---|---|
| Full copies | Fast (1 write) | Fast (1 read) | High (N × size) |
| Delta chain | Fast (1 write) | Slow (O(N) reads) | Low (size + N × delta) |
| Hybrid (snapshot every 10) | Fast (occasional full write) | Bounded (≤10 reads) | Medium |
Bounding Reconstruction:
With snapshots every 10 versions, reading any version requires at most 1 S3 fetch + 9 delta applications. Deltas average 50-200 bytes for small edits, so they fit in a single database query.
Concurrency:
Use optimistic locking: each save increments version_number atomically. If two saves race, the second gets version_number = N+1 correctly. Deltas reference base_version_id which is immutable, so no corruption occurs.
Compaction:
If a delta chain grows long (>20 versions without a snapshot), background jobs can materialize a new snapshot and rewrite subsequent deltas, then archive old intermediates to cold storage.
When to Read Old Versions:
If users rarely access versions older than the most recent 3-5, keep only recent deltas hot and archive the rest. If reproducibility requires accessing arbitrary old versions (e.g., "re-run execution from 3 months ago"), all versions must remain quickly accessible.
Common Mistake: Storing deltas in S3 creates latency problems—fetching 10 tiny S3 objects serially can take 500ms+. Keep deltas in the database where batch fetching is fast.
Summary
A robust design separates concerns: prompts own identity and ownership, versions capture immutable state, executions record results. Size-based storage routing (database vs S3) optimizes for the common case while handling outliers. Snapshot-based sharing provides clear semantics. Hybrid versioning with periodic full snapshots bounds reconstruction cost while avoiding redundant storage. The key is making trade-offs explicit and matching storage strategy to access patterns.