Document overwriting issues are common in enterprise applications where multiple users interact with the same document at the same time. When there is no controlled concurrency, users may overwrite each other’s changes, delete active versions, or corrupt file metadata.
This is especially problematic in systems like:
Document Management Systems
Work Order or Job Card modules
ERP systems
HR document review
Financial approval workflows
Ticketing or case management systems
To solve this problem, modern platforms rely on document locking, leases, expiry, and safe conflict resolution.
This article explains how to build a Document Overwriting Protection System using Angular (front-end) and .NET 8 (back-end).
The solution is metadata-driven, resilient, and suitable for enterprise-scale multi-user environments.
What This System Provides
The final system supports:
Soft locks and hard locks
Lease-based editing (time-bound exclusive access)
Auto-expiry and auto-renewable locks
Distributed-safe locking (SQL-based or Redis-based)
Optimistic concurrency using version tokens
Conflict detection
Force-release and admin override
Real-time lock status indicators in Angular
Lock viewer to see who is editing what
Clean fallback behaviour for offline or crashed clients
This article goes step-by-step from the architecture to Angular UI interactions and .NET implementation.
System Architecture Overview
A Document Protection System uses three layers:
Client (Angular)
Requests lock, renews lock, checks status, and saves changes only if lock is valid.Server (ASP.NET Core)
Manages lock creation, validation, expiry, release, and conflict detection.Database (SQL Server / Redis / Hybrid)
Stores lock metadata and ensures atomicity.
Workflow Diagram (High-Level Architecture)
+---------------------+
| Angular Application |
+----------+----------+
|
Lock/Status API Calls
|
v
+----------------------------+
| ASP.NET Core Lock Manager |
+-----+----------+-----------+
| |
Metadata Store |
(SQL Server / Redis)| Save/Validate
| |
v v
+-----------------------------+
| Document Locking Repository |
+-----------------------------+
Flowchart: Document Editing with Protection
+------------------------+
| User opens document |
+-----------+------------+
|
v
+-----------+------------+
| Request lock from API |
+-----------+------------+
|
+-----------+------------+
| Lock granted? |
+------+----------------+
|Yes
v
+---------+----------+
| Enter edit mode |
+---------+----------+
|
v
+-----------+-------------+
| User edits & saves doc |
+-----------+-------------+
|
v
+-----------+-------------+
| Validate lock still live|
+------+------------------+
|Yes
v
+---------+-----------+
| Save document |
+---------+-----------+
|
v
+---------+-----------+
| Release lock |
+---------------------+
If No (lock not granted), the UI shows who is editing and until when.
Understanding Lock Types
There are three commonly used lock models:
1. Hard Lock
Only the locking user can edit. Others can only read.
2. Soft Lock
Other users can edit but will be warned.
3. Lease Lock
Exclusive access for a fixed duration (e.g., 5 minutes).
Auto-renewal possible.
Our system uses Lease Lock with controlled renewal.
Designing the Lock Metadata (Database Table)
A simple SQL Server table structure:
CREATE TABLE DocumentLocks (
DocumentId UNIQUEIDENTIFIER NOT NULL,
LockedBy NVARCHAR(200) NOT NULL,
LockedAt DATETIME2 NOT NULL,
LeaseExpiry DATETIME2 NOT NULL,
VersionToken ROWVERSION,
PRIMARY KEY (DocumentId)
);
Fields
DocumentId: Unique ID of the document
LockedBy: Email or UserId
LockedAt: Time lock was acquired
LeaseExpiry: Auto-expiry time
VersionToken: Used for optimistic concurrency
Backend Implementation (.NET 8)
ASP.NET Core Controller Structure
POST /api/lock/acquire
POST /api/lock/renew
POST /api/lock/release
GET /api/lock/status/{documentId}

Join the conversation! Your thoughts help the community grow.