Tagged articles
pessimistic lock
65 articles · Page 1 of 1
This article presents five case analysis questions from the May 2026 System Architecture Designer exam, covering time-series databases, MQTT QoS levels, concurrency control strategies, knowledge graph construction, and pipe-filter architecture for intrusion detection, with detailed reference answers for each scenario.
Case AnalysisMQTTOptimistic Lock
0 likes · 21 min read

The article walks through a real production incident where a Redis‑based distributed lock silently failed, causing duplicate point awards, and details the step‑by‑step investigation, root‑cause analysis of transaction‑lock ordering, and three concrete remediation strategies.
Distributed LockRedissonSpring @Transactional
0 likes · 9 min read

After encountering potential data overwrite when updating configuration via an API, the author implements an optimistic lock using version numbers and revisits the fundamentals, comparing pessimistic and optimistic locking mechanisms, their implementations in SQL and Java, performance traits, pitfalls, and guidelines for choosing the appropriate strategy.
JavaOptimistic Lockconcurrency control
0 likes · 8 min read

This article explains why MySQL needs locks beyond MVCC snapshot reads, categorizes lock granularity, mode and design, details global, table and row‑level locks—including intention, gap, next‑key, and implicit locks—then compares pessimistic and optimistic locking, shows how to choose the right lock, and covers deadlock causes, detection, and best‑practice avoidance.
InnoDBLocksMVCC
0 likes · 21 min read

High‑concurrency systems must go beyond simple locking; the article breaks down four progressive strategies—optimistic locking, database pessimistic locking, Redis distributed locks, and finally message‑queue serialization—explaining their trade‑offs, implementation details, pitfalls, and how to combine them into a layered architecture that sustains million‑QPS workloads with consistency, throughput, and recoverability.
Message QueueOptimistic LockRedis Lock
0 likes · 32 min read

This article explains how Spring Boot 3.5.0 leverages the @Lock annotation and JPA LockModeType to apply pessimistic read or write locks, shows custom repository implementations, provides concrete code snippets and generated SQL, and emphasizes that all lock operations must run inside a transaction.
JPAcustom-repositorylockmode
0 likes · 7 min read

The article dissects how the default JpaRepository findById method can trigger unnecessary SELECT queries, create foreign‑key violations under concurrency, and degrade performance, then demonstrates three concrete workarounds—including getReferenceById, manual entity construction, and pessimistic read locking—to eliminate these issues.
ConcurrencyJPAfindbyid
0 likes · 8 min read

The article shows why a simple @Transactional approach fails under 300,000 concurrent users, explains MVCC behavior, demonstrates how to use row‑level pessimistic locks, sorting, FOR NO KEY UPDATE, short transactions, optimistic locking, and proper isolation levels, and outlines a production‑ready architecture with read/write splitting, Redis rate limiting and connection‑pool tuning.
Isolation LevelJavaOptimistic Lock
0 likes · 10 min read

When half a million users simultaneously try to buy 5,000 concert tickets, naive ordering logic leads to race conditions and double bookings, so the article walks through the root causes, compares pessimistic, optimistic, and Redis distributed locks, and presents an industrial‑grade microservice design with a three‑stage state machine to ensure strong consistency and high availability.
ConcurrencyDistributed LockOptimistic Lock
0 likes · 8 min read

This article explains the fundamental ideas behind pessimistic, optimistic, and distributed locking, compares their strengths and weaknesses, outlines typical application scenarios such as inventory deduction, banking transfers, and cache protection, and provides concrete implementation examples using SQL row locks, version fields, CAS, Redis WATCH, and Lua scripts.
ConcurrencyOptimistic Locklocking
0 likes · 8 min read

This article explains common problems of concurrent database updates in Spring Boot 3 and demonstrates five practical solutions—including database locks, optimistic and pessimistic locking, transaction isolation levels, and application‑level locks—accompanied by complete code examples and test results.
ConcurrencyOptimistic Lockpessimistic lock
0 likes · 10 min read

Learn how Spring Boot 3 handles database deadlocks by exploring transaction isolation levels, optimistic and pessimistic locking, and practical code examples that show prevention, detection, and retry strategies to keep your applications reliable under high concurrency.
Database DeadlockOptimistic Lockpessimistic lock
0 likes · 12 min read

This article explains why optimistic locking can fail under high concurrency, demonstrates how to apply database‑level pessimistic locks with Spring Data JPA, configure lock timeouts for MySQL and Oracle, and gracefully handle lock exceptions using Spring Retry.
JPAMySQLOracle
0 likes · 10 min read

This article explores five practical lock-based approaches—including database primary keys, pessimistic and optimistic locks, state machines, and distributed locks—to achieve reliable API idempotency in distributed systems, highlighting implementation details, trade‑offs, and code examples.
API idempotencyDistributed LockOptimistic Lock
0 likes · 7 min read

The article examines a seemingly harmless Java update snippet that hides a concurrency race condition, discusses why a team might decide not to change it in low‑frequency scenarios, and then presents safer alternatives such as selective updates, optimistic and pessimistic locks, and strict guidelines for financial‑critical code.
Optimistic Lockcode reviewpessimistic lock
0 likes · 11 min read

This article explains MySQL's three concurrency types—read‑read, read‑write, and write‑write—describes how InnoDB uses MVCC, shared and exclusive locks, and provides practical examples and code for handling update‑loss and write‑write conflicts with optimistic and pessimistic locking.
ConcurrencyMVCCMySQL
0 likes · 8 min read

This article explains how MySQL transactions and locking mechanisms ensure data consistency and handle high concurrency, covering basic transaction commands, isolation levels, practical lock implementations, deadlock simulation, and best‑practice recommendations for avoiding common concurrency problems.
LocksMySQLOptimistic Lock
0 likes · 7 min read

This article explains the principles of optimistic and pessimistic locking in Java, shows how atomic classes and synchronized constructs implement them, provides runnable code examples, and compares their strategies, scenarios, performance, and typical implementations.
CASJava ConcurrencyOptimistic Lock
0 likes · 4 min read

Idempotency ensures that repeated API calls produce the same result without side effects, and this guide explains its principles, common scenarios like payments and messaging, root causes of idempotency failures, and multiple implementation strategies—including unique constraints, optimistic and pessimistic locks, distributed locks, token mechanisms, state machines, and deduplication tables—with practical code examples.
API DesignBackendIdempotency
0 likes · 14 min read

This article explains the concept of idempotency, outlines scenarios where it is essential, analyzes common causes of idempotency issues, and presents multiple practical solutions—including unique constraints, optimistic and pessimistic locks, distributed locks, token mechanisms, state machines, deduplication tables, and global request IDs—accompanied by concrete code examples.
IdempotencyOptimistic Lockdistributed systems
0 likes · 14 min read

The article outlines the three‑step inventory deduction workflow—select, verify, update—and explains how concurrent requests can cause overselling, then compares mitigation strategies such as pessimistic SELECT FOR UPDATE locks, optimistic CAS version retries, atomic decrement SQL statements, and Redis transactions, highlighting their trade‑offs in consistency and throughput.
ConcurrencyInventoryOptimistic Lock
0 likes · 5 min read

This article explains the purpose of locks in concurrent environments, compares optimistic (CAS) and pessimistic locking mechanisms, outlines their advantages, disadvantages, suitable scenarios, and provides PHP/PDO code examples demonstrating implementation and performance testing under high concurrency.
MySQLOptimistic LockPHP
0 likes · 11 min read

This article explains the concepts of pessimistic and optimistic locking, compares their use cases, demonstrates version‑based and CAS implementations, and shows a complete Spring Boot example with retry‑enabled optimistic lock handling using AOP and custom annotations.
JPAJava ConcurrencyOptimistic Lock
0 likes · 12 min read

This guide explains MySQL's lock mechanisms—including shared and exclusive locks, row‑level locking requirements, pessimistic versus optimistic strategies, and practical implementations with InnoDB, transaction handling, and JMeter concurrency testing—to prevent overselling in high‑traffic scenarios.
InnoDBJMeterMySQL
0 likes · 12 min read

The article explains the concept of idempotency, outlines common duplicate‑submission scenarios such as form resubmission, malicious voting, client retries, and message re‑consumption, and details three practical implementation methods—database constraints, token‑based middleware, and state‑machine logic—complete with code examples and trade‑off considerations.
IdempotencyOptimistic Lockbackend development
0 likes · 13 min read


政采云技术Mar 23, 2023 · Backend Development
This article explains the need for distributed locks in multi‑node systems, describes their core characteristics, and compares popular implementation approaches such as database‑based optimistic and pessimistic locks, Redis atomic locks, and ZooKeeper sequential node locks, highlighting their principles and trade‑offs.
Optimistic Lockpessimistic lockredis
0 likes · 8 min read

This article explains the concepts of optimistic and pessimistic locking, the CAS mechanism and its ABA issue, and demonstrates Java implementations such as AtomicInteger, AtomicStampedReference, ReentrantReadWriteLock, and various lock types with practical code examples.
CASJavaLocks
0 likes · 16 min read

This article explains various lock strategies—including optimistic and pessimistic locks, read‑write locks, heavyweight vs. lightweight locks, spin locks, fair vs. unfair locks, and reentrant locks—detailing their definitions, use‑cases, underlying mechanisms, and illustrative examples for concurrent programming in Java and other languages.
JavaOptimistic Locklocking
0 likes · 10 min read


ITPUBFeb 17, 2023 · Databases
This article explains why MySQL needs locking, details every InnoDB lock type—including shared, exclusive, intention, record, gap, next‑key, insert‑intention and auto‑increment locks—shows how they interact, and provides practical guidance for avoiding deadlocks and safely updating rows.
InnoDBIsolation LevelMySQL
0 likes · 22 min read

Optimistic and pessimistic locks are conceptual concurrency control strategies used across databases and caching systems; the article explains their principles, MySQL implementations with SELECT ... FOR UPDATE and version checks, compares their trade‑offs, and advises preferring optimistic locking in high‑concurrency scenarios.
MySQLOptimistic Lockconcurrency control
0 likes · 6 min read

This article analyzes the business scenario of flash‑sale (秒杀) systems, outlines their technical characteristics, dissects the request chain, compares optimistic and pessimistic locking mechanisms with code examples, and presents a comparative table of concurrency‑control outcomes.
Optimistic Lockbackend architectureconcurrency control
0 likes · 8 min read

This article examines flash‑sale business scenarios, outlines their high‑concurrency characteristics, dissects the request‑flow architecture from client to database, and compares optimistic, retry‑optimistic, and pessimistic locking techniques with practical examples and performance considerations.
Optimistic Lockflash salehigh concurrency
0 likes · 8 min read

This article examines flash‑sale systems by outlining typical business scenarios, analyzing read‑heavy and high‑concurrency technical traits, detailing the end‑to‑end request flow, and comparing optimistic, retry‑optimistic, and pessimistic locking mechanisms with practical SQL examples and performance tables.
Optimistic Lockbackend architecturedatabase locking
0 likes · 9 min read

The article explains how concurrent updates can cause data loss in high‑traffic scenarios and demonstrates using optimistic and pessimistic locking in PostgreSQL with Python, including EFCore‑style token checks and a retry mechanism via the tenacity library.
Optimistic LockPostgreSQLPython
0 likes · 7 min read

The article compares Java's pessimistic locking mechanisms such as synchronized blocks and ReentrantLock with optimistic approaches like version checks, CAS‑based AtomicInteger and custom spin locks, illustrating each method through counter examples and discussing their performance trade‑offs and limitations.
CASConcurrencyJava
0 likes · 11 min read

After repeatedly encountering account balance discrepancies in a financial system, I traced the issue to improper use of pessimistic locks and Hibernate caching, then resolved it by correcting lock placement, optimizing SQL queries, and switching to native SQL, sharing the detailed debugging steps and lessons learned.
ConcurrencyHibernateMySQL
0 likes · 13 min read

This article explains how the MySQL SELECT … FOR UPDATE statement adds a pessimistic lock, why the lock type (row or table) depends on the presence of an index or primary key, and demonstrates the behavior with practical examples and SQL scripts.
IndexMySQLRow Lock
0 likes · 5 min read

The article explains the concept of idempotency, illustrates everyday examples of its importance, defines it mathematically and in software, and presents a comprehensive set of practical solutions—including database constraints, frontend controls, locking mechanisms, token‑based forms, message queues, and RPC safeguards—to achieve reliable idempotent behavior in distributed backend systems.
IdempotencyOptimistic Lockpessimistic lock
0 likes · 11 min read

This article explains the various Java lock mechanisms—including optimistic and pessimistic locks, exclusive and shared locks, reentrant, read‑write, fair/unfair, spin, segment locks, and lock‑escalation techniques—detailing their principles, Java implementations, usage scenarios, and optimization strategies.
ConcurrencyOptimistic LockReentrant Lock
0 likes · 13 min read

This article explains the concepts, mechanisms, and practical code examples of optimistic and pessimistic locking in MySQL/InnoDB, including version‑based optimistic locks, shared (read) locks, exclusive (write) locks, and how to apply them with Laravel's query builder.
Database ConcurrencyLaravelMySQL
0 likes · 6 min read

This article explains the concepts, usage scenarios, and differences of various database locks—including shared (S) lock, exclusive (X) lock, mutex, pessimistic and optimistic locks—as well as row‑level, table‑level, and page‑level locks, and it discusses common concurrency problems such as lost updates, non‑repeatable reads, dirty reads, and deadlocks.
Database LocksMySQLOptimistic Lock
0 likes · 8 min read

This article walks through the design of a flash‑sale system, starting with a simple SpringBoot‑MyBatis implementation, then addressing overselling with pessimistic and optimistic locks, applying rate‑limiting algorithms, time‑window controls, interface hiding, frequency limits, and a suite of production‑grade optimizations such as CDN, Nginx load balancing, Redis caching, message queues, and short‑URL handling.
Optimistic LockSpringBootflash sale
0 likes · 14 min read

The article explains the concept of idempotency, distinguishes it from duplicate submissions, outlines typical use cases such as network retries and form resubmissions, and presents various backend solutions—including unique indexes, deduplication tables, pessimistic and optimistic locks, distributed locks, and token‑based approaches—complete with SQL examples.
IdempotencyOptimistic Lockpessimistic lock
0 likes · 11 min read

This article explains the different lock types—pessimistic, optimistic, and distributed—covers their use cases, compares their advantages and drawbacks, and provides concrete code examples and four practical solutions for handling high‑concurrency deduction scenarios such as inventory or balance reduction.
Distributed LockJavaOptimistic Lock
0 likes · 13 min read

This article explores various techniques to achieve API idempotency in high‑concurrency environments, including token mechanisms, deduplication tables, Redis SETNX keys, state‑machine checks, and both optimistic and pessimistic locking, highlighting their workflows, advantages, and trade‑offs.
APIOptimistic Lockpessimistic lock
0 likes · 9 min read

The article explains why idempotent operations are essential in backend and financial systems, describes the mathematical concept, and presents practical techniques such as unique indexes, token validation, pessimistic and optimistic locking, distributed locks, state‑machine design, and API patterns with concrete SQL examples.
IdempotencyOptimistic Lockdatabase
0 likes · 8 min read

This article explains MySQL's lock mechanisms—including row‑level, page‑level and table‑level locks, their shared and exclusive modes, the differences between optimistic and pessimistic concurrency control, and practical tips for avoiding deadlocks in InnoDB.
LocksMySQLOptimistic Lock
0 likes · 12 min read

This article explains the concepts, advantages, and drawbacks of MySQL pessimistic and optimistic locks, shows how to implement each with SQL and PHP code, compares their suitability for different traffic patterns, and demonstrates a Redis‑based optimistic lock for high‑concurrency flash‑sale scenarios.
ConcurrencyMySQLOptimistic Lock
0 likes · 10 min read

This article explains database concurrency problems, describes how pessimistic and optimistic locking work, provides practical MySQL examples with transaction control, and compares their suitability for different read‑write scenarios to help developers prevent dirty data and improve throughput.
MySQLOptimistic Lockpessimistic lock
0 likes · 8 min read

This article explains how to implement token‑bucket rate limiting with Guava's RateLimiter, compare it to leaky‑bucket algorithms, and combine it with optimistic and pessimistic locking techniques to prevent overselling in high‑concurrency flash‑sale applications.
JavaOptimistic LockSpring
0 likes · 15 min read

This tutorial explains how to enable and configure transaction locks—including pessimistic and optimistic modes—in Spring Data JPA repositories, demonstrates the use of @Lock and @QueryHints annotations, and shows how to set lock timeouts to ensure data integrity under high concurrency.
JavaLockModeTypeOptimistic Lock
0 likes · 6 min read

This article explains why thread safety concerns memory rather than threads, compares stack‑local and heap‑shared data, introduces ThreadLocal for per‑thread isolation, and covers mutual‑exclusion locks, optimistic CAS, and their appropriate use cases in concurrent programming.
CASJava ConcurrencyLocks
0 likes · 15 min read


ITPUBApr 25, 2019 · Databases
This article explains the concepts of concurrency control, detailing pessimistic and optimistic locking mechanisms, their implementation in MySQL, practical SQL examples, advantages, drawbacks such as deadlocks and ABA problems, and guidance on selecting the appropriate lock strategy for high‑concurrency applications.
CASMySQLOptimistic Lock
0 likes · 11 min read

The article explains the concepts, advantages, and drawbacks of optimistic and pessimistic locking, provides real‑world examples such as lost updates and inconsistent reads, and offers practical guidelines and implementation techniques for selecting the appropriate concurrency control strategy in database‑driven applications.
Optimistic Lockconcurrency controldatabase
0 likes · 10 min read

This article examines a distributed system concurrency problem, compares lock‑based transactions with multiversion concurrency control (MVCC), and explains why MVCC often outperforms pessimistic locking in scenarios demanding high read responsiveness and low contention.
MVCCconcurrency controldistributed systems
0 likes · 10 min read

Learn why inventory over‑selling occurs under high concurrency, and explore three practical solutions—pessimistic locking, optimistic locking with version control, and Redis‑Lua scripting—detailing their implementation steps, advantages, and drawbacks to help you choose the best approach for reliable stock management.
InventoryLuapessimistic lock
0 likes · 7 min read

This article explains the mathematical and programming concept of idempotency, provides real‑world examples such as duplicate form submissions and payment requests, and details practical techniques—including query/select operations, unique indexes, token mechanisms, pessimistic and optimistic locks, distributed locks, and API design—to ensure idempotent behavior in backend systems.
IdempotencyOptimistic Lockdatabase
0 likes · 9 min read

This article explains how to use pessimistic (FOR UPDATE) and optimistic (version field) database locks in a Java SSM red‑packet application to prevent over‑issuance, details implementation steps, code changes, performance testing, and the trade‑offs between lock types.
Database ConcurrencyJavaMyBatis
0 likes · 11 min read

The article explains the concepts of pessimistic and optimistic locking, details how CAS (Compare‑And‑Swap) implements optimistic locks in Java, discusses their advantages, drawbacks such as the ABA problem and high spin costs, and compares CAS usage with synchronized blocks in concurrent programming.
CASJava ConcurrencyOptimistic Lock
0 likes · 14 min read

This article explains MySQL's lock mechanisms, covering table‑level, row‑level, and page locks, the differences between pessimistic and optimistic locking, shared locks, and provides guidance on when to choose table locks versus row locks in various application scenarios.
Database ConcurrencyLocksMySQL
0 likes · 7 min read

This article uses a humorous story of two threads battling over inventory updates to illustrate the principles, advantages, and drawbacks of pessimistic and optimistic locking in distributed systems, helping readers understand when to apply each concurrency control method.
Optimistic Lockconcurrency controldatabase
0 likes · 8 min read

The article examines how a train ticket ordering system can encounter duplicate bookings when multiple users concurrently request the same seat and evaluates four different locking strategies—including flag fields, pessimistic locks, synchronized blocks, and a hybrid optimistic‑pessimistic approach—to ensure data consistency and avoid over‑booking.
Backendlockingoptimistic-lock
0 likes · 5 min read


ITPUBOct 26, 2016 · Databases
This guide explains Oracle's lock mechanisms—including shared, exclusive, row‑level, pessimistic, and optimistic locks—through step‑by‑step SQL sessions that illustrate update‑lost problems, lock contention, and deadlock detection, helping developers choose the right strategy for concurrency control.
Optimistic LockOracleSQL
0 likes · 10 min read

This article explains why locks are needed in multi‑user environments, describes common conflict types such as lost updates and dirty reads, compares pessimistic and optimistic locking mechanisms, shows practical implementations with version numbers and SQL Server locks, and presents a classic financial‑system case study.
Optimistic Lockpessimistic locktransaction
0 likes · 8 min read

The article explains why overselling occurs in flash‑sale systems under high concurrency, analyzes the drawbacks of pessimistic locking and FIFO queues, and presents optimistic locking with version control as a more efficient solution for ensuring thread‑safe inventory updates.
BackendFIFO QueueOptimistic Lock
0 likes · 5 min read
