Editors accidentally overwriting content? Recovering lost edits is a common headache in CMS work. Without versioning, every edit can be irreversible, and auditing changes becomes impossible. We develop content versioning systems that preserve every version of your content, allow comparison, and enable instant rollback to any point.
The stakes without versioning are high: restoring accidentally deleted content can cost $500–$2,000 per incident depending on volume and uniqueness. For editorial teams with 10+ authors, incidents happen every few months. A content versioning system pays for itself after the first 1–2 incidents, typically saving $5,000–$10,000 annually, and completely eliminates irretrievable losses.
In one project with 50 editors, the system saved up to 200 versions per day. After a year, zero data loss. This reliability comes from a sound architecture: full snapshots instead of diff chains, well-considered storage limits, and automatic autosave every 30 seconds. Versioning also provides an audit trail, compliance support, and the ability to A/B test content.
What problem does versioning solve?
In commercial projects, content is modified by dozens of editors. Simultaneous edits, accidental deletions, failed experiments — without a change history, you risk losing hours of work. The content versioning system addresses three key issues:
- Rollback to a previous version — if a new edit doesn't work, restore the old one in one click.
- Version comparison — see which fields changed and who made the edit.
- Audit trail — a log of editor actions for compliance.
Why full snapshots are faster than Event Sourcing
| Approach | Storage | Recovery | Complexity |
|---|---|---|---|
| Event Sourcing | Diffs chain | Slow (replay O(n)) | High |
| Full snapshots | Full copies | Instant (O(1)) | Low |
| Hybrid | Snapshots + diffs | Medium | Medium |
Full snapshots are 10x faster than Event Sourcing for recovery: no need to replay an event chain. For typical content (articles, pages), snapshot size is small (2–10 KB), and simplicity and reliability outweigh space savings. Hybrid approaches are only warranted for extremely large data volumes (>100 MB per entity).
Comparison: storage and performance
| Parameter | Event Sourcing | Full snapshots | Hybrid |
|---|---|---|---|
| Storage volume | Low (10 MB over 1000 versions) | High (100 MB over 1000 versions) | Medium |
| Recovery speed | Low (O(n)) | High (O(1)) | Medium |
| Implementation complexity | High | Low | Medium |
| Audit | Full | Partial | Full |
How we implement the content versioning system
Data model
content_versions (
id, content_type, content_id,
version_number,
content (jsonb), -- full snapshot of data
title, excerpt, -- for quick display in version list
changed_fields (jsonb), -- ['title', 'body'] — what exactly changed
change_summary, -- 'Fixed typo in title'
is_autosave, -- autosave vs manual save
created_by, created_at
);
Autosave
// Autosave every 30 seconds on changes
const { isDirty, formData } = useFormState();
useEffect(() => {
if (!isDirty) return;
const timer = setTimeout(async () => {
await saveDraft(formData);
setLastSaved(new Date());
}, 30000);
return () => clearTimeout(timer);
}, [formData, isDirty]);
Creating a version on save
class ContentObserver
{
public function updating(Content $content): void
{
$dirty = $content->getDirty();
$versionableFields = ['title', 'body', 'excerpt', 'meta_title', 'meta_description'];
$changedVersionable = array_intersect(array_keys($dirty), $versionableFields);
if (empty($changedVersionable)) return;
// Version limit: keep at most 50, delete old autosaves
ContentVersion::where('content_type', get_class($content))
->where('content_id', $content->id)
->where('is_autosave', true)
->orderBy('created_at', 'desc')
->skip(10) // keep last 10 autosaves
->get()
->each->delete();
ContentVersion::create([
'content_type' => get_class($content),
'content_id' => $content->id,
'version_number' => $this->getNextVersionNumber($content),
'content' => $content->only($versionableFields),
'title' => $content->title,
'changed_fields' => $changedVersionable,
'is_autosave' => request()->header('X-Autosave') === 'true',
'created_by' => auth()->id()
]);
}
}
Diff between versions
use cogpowered\FineDiff\Diff;
use cogpowered\FineDiff\Granularity\Word;
class ContentVersionDiff
{
public function diff(ContentVersion $v1, ContentVersion $v2): array
{
$result = [];
$fields = array_unique(array_merge(
array_keys($v1->content),
array_keys($v2->content)
));
foreach ($fields as $field) {
$old = $v1->content[$field] ?? '';
$new = $v2->content[$field] ?? '';
if ($old !== $new) {
$diff = new Diff(new Word());
$result[$field] = [
'old' => $old,
'new' => $new,
'diff' => $diff->render($old, $new)
];
}
}
return $result;
}
}
Restoring a version
public function restore(Content $content, ContentVersion $version): void
{
DB::transaction(function () use ($content, $version) {
// Save current state as a version before restoring
event(new ContentBeforeRestore($content));
$content->update($version->content);
$content->recordActivity('version_restored', [
'restored_version' => $version->version_number
]);
});
}
Which fields should be versioned?
Typically text and HTML fields: title, body (including markup), excerpt, meta_title, meta_description. Media files (images, videos) don't need versioning — just store links. If content includes nested blocks (e.g., a page builder), additional normalization is required — we add a content_version_components table with versions of each component, allowing rollback of individual blocks without affecting the rest.
Process of work
- Analysis — identify fields to version, storage limits, autosave settings.
- Design — data model, API, history interface.
- Implementation — write code in PHP + JavaScript, integrate the FineDiff library.
- Testing — verify version creation, rollback, comparison.
- Deployment — deploy to staging, then to production.
What's included
- API and data model documentation
- Source code of the versioning module
- Repository access
- Autosave configuration (every 30 seconds)
- Version comparison interface with color highlighting
- Notifications to editor on rollback to previous version
- Editor training (2 hours)
- One month of technical support after launch
- Estimated cost: $5,000–$15,000 depending on scope
Estimated timeline
Basic system (autosave + rollback) — 1 to 2 weeks ($5K–$10K). Full system with diff and comparison interface — 2 to 4 weeks ($10K–$15K). Cost is calculated individually — contact us for an estimate.
Our team has over 5 years of experience in CMS development. We guarantee support and refinements after implementation. A ready-to-use module easily integrates into existing Laravel projects without changing core business logic — just attach the Observer and run the database migration. Reach out for a consultation — we'll discuss your project, assess data volume, and propose the optimal solution within a day.







