Optimistic Locking for Race Condition Mitigation in Datastore Migration
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
During data migration from one datastore (DS1) to another (DS2), race conditions occur due to simultaneous updates in both systems, leading to data inconsistencies and performance issues with existing solutions like two-phase commit and centralized event streams, especially when migrating existing applications to a new infrastructure.
Innovation Solution
The use of optimistic locking and timestamps allows independent and asynchronous changes in both systems, with conflict resolution by comparing pre-update values and timestamps to determine the winning change, ensuring consistency without the performance penalties of two-phase commit.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If two-phase commit is used to coordinate edits across multiple remote datastores, then data consistency is maintained, but system performance deteriorates significantly and database resources are exhausted
Solution Approach 1:
The patent uses lightweight version identifiers (version IDs or timestamps) instead of heavy transaction locking mechanisms. These version identifiers are simple, disposable metadata that can be easily created, compared, and discarded, avoiding the resource-intensive two-phase commit protocol while maintaining consistency through optimistic validation.
Solution Approach 2:
The patent replaces the mechanical two-phase commit locking system with an optimistic locking mechanism using version identifiers. Instead of holding actual locks on database resources, the system uses software-based version tracking and comparison, substituting a heavy mechanical coordination system with a lighter computational approach.
2Reliability
If two-phase commit is used to coordinate edits across multiple remote datastores, then data consistency is maintained, but database resources are tied up and easily exhausted
Solution Approach 1:
The patent uses lightweight version identifiers (version IDs or timestamps) instead of heavy transaction locking mechanisms. These version identifiers are simple, disposable metadata that can be easily created, compared, and discarded, avoiding the resource-intensive two-phase commit protocol while maintaining consistency through optimistic validation.
Solution Approach 2:
The patent extracts the essential consistency-checking function from the heavy two-phase commit protocol, isolating only the necessary version comparison logic. This separates the critical consistency validation from the resource-intensive coordination overhead, allowing the system to maintain data integrity without tying up database resources.
3Reliability
If a centralized stream is used to propagate events to all relevant systems, then event ordering is maintained and error handling is centralized, but migration of existing applications to the master stream is difficult
Solution Approach 1:
The patent introduces version identifiers as an intermediary mechanism that enables gradual migration. Existing applications can continue to use their current datastores while incorporating version checking, serving as intermediaries between the old and new systems. This allows incremental adoption without requiring all applications to migrate simultaneously to a centralized stream.
Solution Approach 2:
The patent implements partial migration where applications can adopt the version-controlled optimistic locking mechanism incrementally. Applications don't need to fully migrate to a centralized stream immediately; they can partially implement version tracking and conflict resolution while continuing to operate with their existing architectures, enabling gradual transition.
4Reliability
If all applications write to a central stream, then data consistency is maintained, but the infrastructure complexity increases for organizations with existing applications
Solution Approach 1:
The patent segments the consistency-maintenance function into distributed version tracking at each application and datastore, rather than requiring a monolithic centralized stream infrastructure. Each system independently tracks versions and detects conflicts, eliminating the need for complex centralized event streaming infrastructure while maintaining data consistency across distributed systems.
Data Source
AI summary
Techniques are described herein to handle situations in which multiple systems can change different copies of the same data item. Optimistic locking and time stamps are used to ensure consistency between the systems without incurring the performance penalties associated with two-phase commit. Specifically, when propagating a change to a data item from a first system to a second system, the second system compares the first system's “pre-update” value of the data item with its current value of the data item. If the pre-update value from the first system does not match the current value in the second system, then a conflict has occurred. Upon detecting a conflict, both systems use timestamps associated with the respective conflicting changes to determine which conflicting change “wins”. The winning change is applied by all systems whose changes did not win.


