Timestamp-Based vs Lock-Based Concurrency Control
Rollback Frequency in Timestamp Protocols
Read aloud is unavailable in this browser.
Quantifying the Restart Cost
In timestamp-based protocols, transaction rollback (abort and restart) is the mechanism for handling conflicts. Unlike lock-based systems where conflicts cause blocking, timestamp conflicts cause work to be discarded and redone. The frequency of these rollbacks is therefore a critical performance determinant.
This page provides a rigorous, quantitative analysis of rollback frequency—moving beyond intuition to mathematical modeling and empirical characterization. We examine the factors that influence rollback rates, derive analytical formulas for predicting rollback probability, and explore how to measure and optimize rollback behavior in real systems.
Understanding rollback frequency is not optional for serious database engineering. It determines whether a timestamp-based protocol will thrive or collapse under your specific workload. Let's develop the analytical tools to answer this question decisively.
By the end of this page, you will understand the theoretical models for rollback probability, the factors that influence rollback frequency, how to measure and analyze rollback behavior, the relationship between rollback frequency and system throughput, and strategies for reducing rollback rates in practice.
Theoretical Framework for Rollback Analysis
To analyze rollback frequency, we need a mathematical model of transaction execution and conflict. The key insight is that rollback probability depends on the temporal overlap of conflicting transactions and the probability that they access common data items.
Model Parameters
Let's define the key variables:
System Parameters:
- n: Number of concurrent transactions in the system
- D: Total number of data items in the database
- λ: Transaction arrival rate (transactions per second)
Transaction Characteristics:
- d: Number of data items accessed per transaction
- T: Average transaction duration (execution time)
- r: Fraction of operations that are reads (0 ≤ r ≤ 1)
- w = 1 - r: Fraction of operations that are writes
Conflict Probability:
- p_item: Probability that two transactions access the same item
- p_overlap: Probability that two transactions temporally overlap
- p_conflict: Probability that overlapping transactions have a conflict
Basic Conflict Model
For a transaction accessing d items out of D total items uniformly at random, the probability that its access set intersects with another transaction's access set is:
P(item overlap) ≈ d² / D (for d << D)
This comes from the hypergeometric distribution approximation. If two transactions each select d items from D items, the expected intersection size is d²/D, and the probability of any intersection is approximately the same when d << D.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
// ROLLBACK PROBABILITY DERIVATION// ================================ // Assumptions:// - n concurrent transactions// - Each transaction accesses d items from D total items (uniform random)// - Transaction duration T// - Transactions arrive according to Poisson process with rate λ // Step 1: Probability two transactions access same item// ----------------------------------------------------// Transaction 1 accesses d items// Transaction 2 accesses d items// Probability of overlap (for d << D): P(item_overlap) ≈ 1 - (1 - d/D)^d ≈ d²/D // Step 2: Probability of temporal overlap// ----------------------------------------------------// For two transactions with duration T arriving randomly:// They overlap if their execution intervals intersect // If transaction T₂ arrives within 2T of T₁'s start:P(time_overlap) = 2T × λ_effective // Where λ_effective is arrival rate of potentially conflicting transactions // Step 3: Probability of actual conflict (not just overlap)// ----------------------------------------------------// Even if items overlap, conflict requires:// - Read-Write or Write-Write on same item// - Timestamp ordering violation // For two overlapping transactions accessing same item X:// - T₁ (older) writes X, T₂ (younger) reads X → T₂ may abort// - T₁ (older) reads X, T₂ (younger) writes X → T₂ aborts if T₁ read already// - Both write X → older's write may be ignored (Thomas) or abort younger P(conflict | item_overlap ∧ time_overlap) = f(access_pattern) // Simplified: with fraction w writes, r reads:// Conflict if: (W₁,R₂), (R₁,W₂), (W₁,W₂)// = w×r + r×w + w×w = 2wr + w² = w(2r + w) = w(2 - w) // Step 4: Combined rollback probability per transaction// ---------------------------------------------------- P(rollback) = Σ P(conflict with Tᵢ) for all concurrent transactions Tᵢ // With n concurrent transactions:P(rollback) ≈ n × P(item_overlap) × P(conflict|overlap) ≈ n × (d²/D) × w(2-w) // More precise with Poisson arrivals:P(rollback) ≈ 1 - exp(-2λT × (d²/D) × w(2-w))Key Observations from the Model
Quadratic Dependence on Access Set Size (d²): Doubling the number of items accessed by each transaction quadruples the conflict probability. This is why short, focused transactions have dramatically lower rollback rates than long, wide-ranging transactions.
Linear Dependence on Concurrency (n or λT): More concurrent transactions mean more opportunities for conflict. High-throughput systems naturally have higher rollback rates unless they also increase database size (D).
Inverse Dependence on Database Size (1/D): Larger databases dilute conflict probability. This is why timestamp protocols scale well with data volume—more data means proportionally fewer conflicts.
Write Fraction Impact (w(2-w)): Conflicts require writes. Read-only workloads have near-zero conflict probability. The maximum conflict factor w(2-w) = 1 occurs at w = 1 (all writes).
The d²/D term reveals why timestamp protocols often outperform at scale: if you double both transactions (n×2) and data (D×2), the conflict rate stays constant. Horizontal scaling naturally maintains rollback rates. This is why distributed databases favor timestamp-based approaches.
Factors Affecting Rollback Frequency
Building on the theoretical model, let's examine each factor that influences rollback frequency in more practical terms. Understanding these factors enables workload optimization.
Factor 1: Transaction Length and Duration
Impact: Longer transactions have:
- More operations → More items accessed (higher d)
- Longer execution time → More temporal overlap
- Higher probability of accumulating conflicts
Quantitative Relationship:
- Doubling transaction length approximately doubles rollback probability (superlinear in some models)
- Long transactions (seconds) may have 10-100x higher rollback rates than short transactions (milliseconds)
Practical Implication:
- Break long transactions into shorter ones where possible
- Batch-processing workloads are poorly suited to pure timestamp ordering
Factor 2: Hot Spot Concentration
The uniform random model assumes equal access probability for all items. Real workloads are typically skewed (Zipfian distribution):
| Distribution | Top 20% Data Gets | Rollback Rate Impact |
|---|---|---|
| Uniform Random | 20% of accesses | Baseline |
| Zipfian (s=0.5) | 35% of accesses | 1.5-2x baseline |
| Zipfian (s=1.0) | ~50% of accesses | 3-4x baseline |
| Zipfian (s=1.5) | ~75% of accesses | 5-10x baseline |
| Single Hot Spot | ~100% of some accesses | Approaches 100% rollback |
Factor 3: Read/Write Ratio
The nature of operations profoundly affects conflict probability:
Read-Only Transactions (w = 0):
- No write-write or read-write conflicts from their perspective
- But can be aborted if they try to read an item with W-timestamp > TS(T)
- Generally very low rollback rates in MVCC systems
Write-Heavy Transactions (w → 1):
- Every write can conflict with both reads and writes from other transactions
- Write-write conflicts are common
- High rollback rates unless contention is very low
Mixed Workloads (w ≈ 0.1 - 0.3):
- Typical of OLTP applications
- Moderate rollback rates
- Usually acceptable for timestamp protocols
Factor 4: Concurrency Level
More concurrent transactions mean more conflict opportunities:
Low Concurrency (n < 10):
- Minimal temporal overlap
- Rollback rate typically < 5%
- Timestamp protocols highly efficient
Medium Concurrency (10 < n < 100):
- Significant overlap probability
- Rollback rate typically 5-20%
- Performance depends on access patterns
High Concurrency (n > 100):
- Heavy overlap
- Rollback rate can exceed 50% on hot spots
- May need protocol optimization or switching
- •Transaction Length: Superlinear impact—longer transactions have disproportionately higher rollback rates.
- •Access Skew: Zipfian/hot-spot distributions multiply conflict probability by 2-10x over uniform access.
- •Write Ratio: Pure reads ≈ 0% rollback; high writes ≈ proportional to w(2-w).
- •Concurrency Level: Linear impact—doubling concurrent transactions approximately doubles rollback probability.
- •Database Size: Inverse impact—larger databases dilute conflict probability.
These factors multiply, not add. A workload with 2x normal concurrency, 3x access skew, and 1.5x transaction length might have 2 × 3 × 1.5 = 9x higher rollback rate than baseline. Small changes in multiple factors can cause dramatic rollback increase.
Measuring Rollback Frequency
Theoretical models provide insight, but real-world systems require empirical measurement of rollback frequency. Let's examine how to instrument, measure, and interpret rollback metrics.
Key Metrics to Track
Primary Metrics:
-
Rollback Rate: Percentage of transactions that abort
- Formula: (Aborted Transactions / Total Transactions) × 100
- Target: < 10% for healthy systems, < 1% for optimal
-
Rollback Frequency: Rollbacks per second
- Useful for capacity planning
- Correlates with wasted CPU
-
Average Restarts per Transaction: How many attempts until success
- Formula: Total Attempts / Successful Completions
- 1.0 = no restarts (ideal); 2.0 = one restart average; 10.0 = critical
Secondary Metrics:
-
Rollback Cause Distribution: Why transactions abort
- Read violation (TS < W-timestamp)
- Write violation (TS < R-timestamp)
- Write-write conflict
- Helps identify optimization opportunities
-
Rollback Latency Impact: Time added by restarts
- Formula: (Total Execution Time - Minimum Possible Time) / Minimum Time
- Measures efficiency loss
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
// ROLLBACK INSTRUMENTATION FRAMEWORK// =================================== class RollbackMetrics { // Counters AtomicLong totalTransactions = 0; AtomicLong successfulTransactions = 0; AtomicLong rollbacks = 0; AtomicLong totalAttempts = 0; // Includes retries // Cause tracking AtomicLong readViolations = 0; // TS < W-timestamp AtomicLong writeViolations = 0; // TS < R-timestamp AtomicLong writeWriteConflicts = 0; // Latency tracking Histogram transactionLatency; // Total time per logical transaction Histogram workPerAttempt; // Work done per attempt // Per-resource tracking (for hot spot detection) Map<ResourceId, AtomicLong> conflictsPerResource;} // Instrumentation points: function beginTransaction(Txn t): metrics.totalTransactions.increment(); metrics.totalAttempts.increment(); t.startTime = now(); t.attemptCount = 1; function onRollback(Txn t, RollbackCause cause): metrics.rollbacks.increment(); metrics.totalAttempts.increment(); t.attemptCount++; switch(cause): case READ_VIOLATION: metrics.readViolations.increment(); case WRITE_VIOLATION: metrics.writeViolations.increment(); case WRITE_WRITE: metrics.writeWriteConflicts.increment(); metrics.conflictsPerResource.get(cause.resourceId).increment(); // Track work wasted metrics.workPerAttempt.record(t.workDoneSinceLastAttempt); t.workDoneSinceLastAttempt = 0; function onCommit(Txn t): metrics.successfulTransactions.increment(); metrics.transactionLatency.record(now() - t.startTime); // Derived metrics (calculated periodically): function calculateMetrics(): rollbackRate = rollbacks / totalAttempts * 100; avgRestarts = totalAttempts / successfulTransactions; // Hot spot detection: resources with disproportionate conflicts hotSpots = conflictsPerResource .entries() .filter(e => e.value > avgConflictsPerResource * 5) .sortByValueDesc(); return MetricsReport(rollbackRate, avgRestarts, hotSpots);Interpreting Rollback Metrics
Healthy System Indicators:
- Rollback rate < 5%
- Average restarts per transaction < 1.1
- No single resource accounts for > 20% of conflicts
- Rollback cause distribution is balanced
Warning Signs:
- Rollback rate 10-20%: Concerning, optimization needed
- Rollback rate climbing over time: Workload or data change
- One resource dominates conflicts: Hot spot problem
- Read violations dominate: Old transactions reading new data
- Write violations dominate: New transactions blocked by old readers
Critical Problems:
- Rollback rate > 50%: System instability, consider protocol change
- Average restarts > 3: Livelock conditions developing
- Rollback rate oscillates wildly: Unstable feedback dynamics
Diagnosis Workflow
When rollback rates are high:
- Check Cause Distribution: Which conflict type dominates?
- Identify Hot Spots: Which resources have most conflicts?
- Analyze Transaction Mix: Are long transactions conflicting with short ones?
- Examine Concurrency: Has load increased beyond capacity?
- Review Access Patterns: Has workload skew changed?
Rollback metrics should be monitored continuously, not just when problems occur. Gradual increases in rollback rate often precede performance crises. Set up alerts for rollback rate thresholds (e.g., warn at 10%, critical at 25%).
Rollback Frequency and System Throughput
Rollback frequency directly impacts system throughput. Understanding this relationship is essential for capacity planning and performance optimization.
The Throughput Equation
Effective throughput depends on useful work versus wasted work:
Definitions:
- Nominal Throughput (T_nom): Transactions started per second
- Effective Throughput (T_eff): Transactions successfully completed per second
- Rollback Rate (R): Fraction of transactions that abort
- Average Restarts (A): Average attempts until success = 1/(1-R)
Relationship:
T_eff = T_nom / A = T_nom × (1 - R)
However, this assumes the system can absorb the extra load from restarts. In reality, rollbacks consume resources, reducing capacity for new transactions:
Resource-Constrained Model:
If the system has capacity for C operations/second:
- Each successful transaction requires W_success = d operations (data accesses)
- Each restart adds W_restart = d × R operations
- Total work per successful transaction: W_total = d × A = d / (1-R)
Effective throughput: T_eff = C / W_total = C × (1-R) / d
| Rollback Rate | Avg Restarts | Effective Throughput | Capacity Utilization |
|---|---|---|---|
| 0% | 1.00 | 100% of nominal | 100% useful |
| 10% | 1.11 | 90% of nominal | 90% useful, 10% wasted |
| 25% | 1.33 | 75% of nominal | 75% useful, 25% wasted |
| 50% | 2.00 | 50% of nominal | 50% useful, 50% wasted |
| 75% | 4.00 | 25% of nominal | 25% useful, 75% wasted |
| 90% | 10.00 | 10% of nominal | 10% useful, 90% wasted |
| 99% | 100.00 | 1% of nominal | 1% useful, 99% wasted |
The Throughput Collapse Threshold
Timestamp protocols exhibit a phase transition in throughput behavior:
Below Threshold (Low Contention):
- Rollback rate is low and stable
- Throughput scales linearly with offered load
- System is healthy
At Threshold (Critical Point):
- Rollback rate begins to climb
- Restarts consume increasing capacity
- Throughput growth slows
Above Threshold (Collapse):
- Rollback rate climbs rapidly
- More work is wasted than completed
- Throughput decreases despite increasing load
- System enters unstable "thrashing" regime
The threshold depends on workload characteristics, but typically occurs when:
- Rollback rate exceeds 30-40%
- Average restarts exceed 1.5-2.0
- Rollback rate is correlated with load (positive feedback)
The throughput collapse region is dangerous because it's self-reinforcing. Higher load → more contention → more rollbacks → more wasted work → less completed work → backlog grows → more concurrent transactions → higher load. Admission control and load shedding are essential to avoid this spiral.
Comparative Analysis: Rollback vs Blocking
To contextualize timestamp rollback frequency, let's compare it with lock-based blocking behavior. The comparison reveals when each approach is preferable.
Lock-Based Blocking Characteristics
In lock-based protocols, conflicts cause waiting, not rollbacks:
Blocking Model:
- Transaction requests lock on conflicting resource
- If incompatible lock held, transaction waits
- Wait time = remaining duration of lock holder(s)
- No work is wasted; progress resumes after wait
Expected Wait Time:
- W_block = (conflict probability) × (average remaining lock hold time)
- With many conflicts, wait time accumulates
- Deadlocks cause some transactions to abort (but targeted, not repeated)
Comparison by Workload Type
| Workload Characteristic | Timestamp Rollback | Lock Blocking | Better Choice |
|---|---|---|---|
| Low contention, short txns | ~2% rollback, minimal waste | ~50µs lock overhead | Timestamp (lower overhead) |
| Low contention, long txns | ~5% rollback, some waste | ~100µs lock overhead | Either (marginal difference) |
| Medium contention, short txns | ~15% rollback, noticeable waste | ~5ms avg wait | Depends on txn work cost |
| Medium contention, long txns | ~25% rollback, significant waste | ~50ms avg wait | Lock (waste is expensive) |
| High contention, short txns | ~50% rollback, severe waste | ~20ms avg wait (convoy risk) | Lock with careful design |
| High contention, long txns | ~80% rollback, system failure | ~200ms avg wait (deadlock risk) | Neither ideal; redesign needed |
| Known hot spots | May not function | Serialized access | Lock for hot spots |
| Distributed system | Lower coordination cost | High coordination cost | Timestamp |
The Break-Even Analysis
We can analytically determine when timestamp rollback is preferable to lock blocking:
Timestamp Cost: C_ts = W × A = W / (1-R)
- W = work per transaction
- R = rollback rate
- A = average attempts
Lock Cost: C_lock = W + B × P
- W = work per transaction
- B = average block time per conflict
- P = probability of blocking (≈ conflict probability)
Break-Even Point: C_ts = C_lock
W / (1-R) = W + B × P
Solving for R: R = (B × P) / (W + B × P)
Interpretation: If rollback rate exceeds R_breakeven, timestamps are worse than locks.
- R_breakeven depends on B/W: ratio of block time to work time
- If blocking is short and work is substantial, even low rollback rates make timestamps worse
- If blocking is long and work is cheap, higher rollback rates are acceptable
Example:
- W = 10ms, B = 5ms, P = 0.3
- R_breakeven = (5 × 0.3) / (10 + 5 × 0.3) = 1.5 / 11.5 ≈ 13%
- If rollback rate > 13%, locks are better for this workload
The choice between timestamp and lock protocols isn't about which is "better"—it's about which matches your workload. Measure your actual rollback rate under realistic conditions. If it exceeds the break-even point, consider locks or hybrid approaches.
Strategies for Reducing Rollback Frequency
When rollback frequency is higher than acceptable, several strategies can reduce it without abandoning timestamp-based protocols entirely.
Strategy 1: Transaction Redesign
The most effective approach is often redesigning transactions to reduce conflict surface:
Shorten Transactions:
- Break long transactions into multiple shorter ones
- Each shorter transaction has smaller conflict window
- Trade-off: May require application logic changes for atomicity
Reduce Access Footprint:
- Access only necessary data items
- Avoid "SELECT *" which may touch unnecessary columns
- Use covering indexes to reduce row accesses
Order Operations Consistently:
- If all transactions access resources in the same order, conflicts become predictable
- For hot spots: first transaction to reach the spot wins, others abort quickly
Strategy 2: Data Model Optimization
- •Partition Hot Spots: Replace global counters with per-region counters; aggregate when needed.
- •Denormalize to Reduce Joins: Fewer tables accessed = fewer conflict opportunities.
- •Separate Read and Write Paths: CQRS pattern: read from replicas, write to primary.
- •Temporal Sharding: Route transactions to different data based on time slots.
- •Application-Level Batching: Combine multiple small updates into one transaction.
Strategy 3: Protocol Enhancements
Thomas Write Rule:
- Already discussed: ignore obsolete writes instead of aborting
- Reduces rollback for write-write conflicts
- Slight semantic change (eventual consistency flavor)
Multi-Version Concurrency Control:
- Readers see consistent snapshot, never abort for read violations
- Writers still may conflict
- Major reduction in read-heavy workload rollbacks
Wound-Wait or Wait-Die:
- Add priority-based resolution
- Ensures older transactions complete
- May increase rollback for younger transactions but guarantees progress
Strategy 4: Backoff and Retry Optimization
1234567891011121314151617181920212223242526272829303132333435363738394041
// EXPONENTIAL BACKOFF WITH JITTER FOR ROLLBACK RETRY// ================================================= function executeWithRetry(Transaction txn, maxRetries: int = 10): baseDelay = 10ms; // Starting delay maxDelay = 1000ms; // Maximum delay cap for attempt in 1..maxRetries: try: txn.execute(); return SUCCESS; catch ConflictException as e: if attempt == maxRetries: throw TooManyRetriesException(txn, attempts); // Exponential backoff: delay doubles each attempt delay = min(baseDelay * (2 ^ attempt), maxDelay); // Add jitter to prevent thundering herd // Random value between 0.5x and 1.5x of delay jitter = delay * (0.5 + random() * 1.0); sleep(jitter); // Get new timestamp for retry txn.resetWithNewTimestamp(); return FAILURE; // Why this works:// - Exponential backoff reduces collision probability// - Jitter prevents multiple transactions from backing off // to the same moment (thundering herd)// - Capped delay prevents excessive latency for any single retry// - Limited retries prevent infinite loops // Advanced: Adaptive backoff based on system loadfunction adaptiveDelay(baseDelay, currentRollbackRate): // Increase delay when system is under stress loadFactor = 1 + (currentRollbackRate / 0.1); // 10% rollback = 2x delay return baseDelay * loadFactor;Strategy 5: Hybrid Protocols
When specific hot spots are identified, use locks for those resources while using timestamps for the rest:
Implementation:
- Identify resources with > X% of conflicts (hot spots)
- Require lock acquisition before timestamp access for hot spots
- Use pure timestamp ordering for cold data
Benefits:
- Hot spots get ordered access (no contention collapse)
- Cold data gets lightweight timestamp handling
- Best of both worlds for mixed workloads
Challenges:
- More complex implementation
- Must handle lock-timestamp interactions carefully
- Deadlock possible on locked resources (need detection)
Start with transaction redesign and data model changes—these often provide 10x rollback reduction at no protocol cost. Only move to protocol enhancements or hybrid approaches if simpler solutions are insufficient.
Real-World Rollback Analysis
Let's examine how rollback frequency manifests in real-world database systems and how practitioners manage it.
Case Study 1: PostgreSQL MVCC
PostgreSQL uses MVCC (built on timestamp concepts) with an interesting conflict model:
Conflict Handling:
- Readers never block and never abort (snapshot isolation)
- Write-write conflicts are serialization failures
- Applications must handle and retry serialization failures
Observed Rollback Rates:
- OLTP workloads: Typically 0.1-2% serialization failures
- High-contention update workloads: Can reach 10-30%
- Batch updates to same rows: May exceed 50%
Mitigation Deployed:
- Serializable isolation (SSI) reduces anomalies but increases rollbacks
- Advisory locks for known contentious operations
- Connection pool retry logic at application layer
Case Study 2: Google Spanner
- •TrueTime timestamps: GPS + atomic clocks provide globally synchronized timestamps with bounded uncertainty.
- •Commit-wait protocol: Waits out timestamp uncertainty before committing, trading latency for consistency.
- •Lock-based writes: Writes acquire locks; timestamps used for read consistency.
- •Rollback sources: Mostly deadlock (from locks) plus some serialization conflicts.
- •Observed rates: Typically < 1% in production due to careful workload design.
Case Study 3: CockroachDB
CockroachDB is an open-source distributed SQL database using serializable snapshot isolation:
Conflict Model:
- Optimistic concurrency with timestamp-based ordering
- Read refreshing: avoid rollback by refreshing read timestamps if possible
- Transaction contention visible in observability dashboards
Rollback Patterns:
- Contention on secondary index keys is common source
- Foreign key constraint checks can cause conflicts
- Explicit
SELECT FOR UPDATEconverts to pessimistic mode
Production Advice (from CockroachDB docs):
- "Keep transactions short and simple"
- "Avoid hotspots through schema design"
- "Use explicit retry loops in application code"
- "Monitor the Transactions dashboard for contention"
Key Lessons from Practice
-
Rollback Is Expected: All real systems have some rollback. Design for it.
-
Metrics Are Essential: You can't optimize what you don't measure.
-
Application Partnership: Database rollback handling requires application retry logic.
-
Workload-Specific Tuning: No universal configuration; tune for your access patterns.
-
Hot Spot Vigilance: Identify and address hot spots proactively; they cause most problems.
Production database systems rarely use pure timestamp ordering in isolation. MVCC, hybrid locking, and application-level retry logic are all standard practice. The theoretical models inform but don't replace practical engineering for specific workloads.
KEEP LEARNING
There’s more to understand.
You’re reading the introduction. Create a free account to read the complete lesson, save notes and keep track of your progress.