October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Optimistic vs. Pessimistic Locking for Client Status Changes

Optimistic locking rejects stale status writes with a version precondition; pessimistic locking serializes a short change with a database row lock. Learn how each works and what clients should do after a conflict.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To prevent lost status updates, make each change conditional on the state the client actually read—or serialize the change inside a short database transaction. Optimistic locking checks a version when the client writes; pessimistic locking holds a database lock while the server validates and commits a transition. Neither is universally faster: choose based on how often changes overlap, the cost of a conflict, and how long protection must last.

How lost updates happen

A lost update occurs when two clients read the same status, then each submits a change based on that older value. If the server accepts both writes without checking whether the record changed in between, the later write can replace the earlier one. The result depends on which write arrives last, and one client’s change disappears. MDN’s guide to conditional requests describes this overwrite problem.

For example, two staff members read a request as pending. One approves it while the other rejects it. A blind assignment can leave the record with whichever status was written last, without telling either person that their view was stale.

Optimistic locking vs. pessimistic locking

Decision point Optimistic version check Pessimistic row lock
Where protection happens At write time: compare the submitted version token with the current resource. During the database transaction: hold a lock that blocks conflicting writers or lockers.
What the other client experiences A stale update is rejected, typically with HTTP 412 Precondition Failed; the client must refresh or reconcile. A competing operation may wait until the lock-holding transaction ends.
How long protection lasts No database lock is held while a person edits. Only for the lock-holding transaction; commit or rollback releases the row lock.
Typical concerns Conflict response and a clear recovery path for the client. Waiting, timeouts, deadlocks, retries, and transaction isolation behavior.
Often suits Edits that may take time, where collisions are manageable and can be explained. Short atomic transitions that need serialization and can tolerate waiting.

This comparison describes the mechanisms, not a performance benchmark. The right choice depends on expected overlap, conflict cost, transaction duration, and the experience you want to provide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

How to prevent lost updates with an ETag and If-Match

HTTP If-Match lets a client submit the entity tag (ETag) it received when reading a representation. The server applies the requested change only if that tag still strongly matches the current representation. RFC 9110 identifies this state-changing precondition as a way to prevent lost updates when user agents act in parallel. See RFC 9110, Section 13.1.1.

  1. Read the resource. Return its current representation and a strong ETag, such as "v17". The example token is illustrative; the format is defined by the API.
  2. Submit the intended change with its validator. Include the exact ETag from that read in the request’s If-Match header. For example: If-Match: "v17".
  3. Check and mutate atomically. The server must compare the submitted validator with current state as part of the write path. A client-side read-then-compare followed by an unguarded update still leaves a race between the comparison and mutation.
  4. Reject a failed precondition. If the representation no longer matches, do not perform the requested method. RFC 9110 permits a 412 Precondition Failed response for this case; it is the usual response for an If-Match mismatch.
  5. Refresh or reconcile. Return enough information for the client to fetch current state and recover according to the policy described below.

If-Match requires strong entity-tag comparison. A weak ETag, prefixed with W/, is not suitable as the validator for this precondition. The API should issue and compare tokens that represent the version relevant to the requested update.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

What should a client do when an update returns 412?

Treat 412 as evidence that the client’s version is no longer current—not as a transient error to replay blindly. The application should make the conflict visible and give the person a route to a valid decision.

  • Reload and retry: fetch the latest representation, show the updated status, and ask the person to make or confirm a new choice.
  • Show both values: present the current status alongside the attempted status so the person can decide how to proceed.
  • Reconcile only when rules allow it: the server may accept a new request after checking whether the intended transition remains valid against current state.

Automatically resending the same stale status intent with a fresh ETag is not conflict resolution: it can simply overwrite the change that caused the first request to fail. An ETag mismatch is a version conflict; a separate domain-rule violation can use an API-defined response such as 409 Conflict. Keep those meanings distinct in the contract.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

How to serialize a status transition with a PostgreSQL row lock

When a short operation must inspect the current row and change it as one serialized unit, PostgreSQL can lock the selected row with SELECT ... FOR UPDATE. Conflicting writers or lockers wait until the transaction ends. The PostgreSQL 17 explicit-locking documentation describes row-lock behavior and deadlocks.

  1. Begin a transaction.
  2. Select and lock the target row. Use SELECT ... FOR UPDATE for the row whose status is changing.
  3. Validate the transition against the locked current state. For example, verify that pending may transition to approved.
  4. Update the status and commit. The lock is released when the transaction ends.

Keep the transaction short. Do not call external services or wait for user input while holding the lock. PostgreSQL warns that waiting with transactions open for long periods is a bad idea. If a transaction must lock multiple records, acquire them in a consistent order where practical; PostgreSQL identifies consistent ordering as an important deadlock defense. A deadlock can still occur, and PostgreSQL aborts one participant, so the application needs a bounded, operation-appropriate retry policy.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

PostgreSQL isolation-level caveat

With PostgreSQL Repeatable Read, snapshot timing matters: a transaction’s snapshot may predate a lock acquired after its first query or data-modification command. PostgreSQL’s application-level consistency guidance advises using Read Committed or obtaining needed locks before queries when relying on explicit locks for consistency. This is PostgreSQL-specific guidance; check the relevant database’s locking and isolation documentation before applying the same assumptions elsewhere.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make status transitions explicit and atomic

Prefer an operation that expresses a domain transition—such as “approve this pending request”—over a blind instruction to assign approved. The server can then verify that the current state permits the transition, rather than treating every status value as interchangeable.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Whichever strategy you choose, the version check or row lock, the validation, and the mutation must meet at the server/database boundary as one atomic operation. Otherwise another writer can change the row between checking it and saving the new status.

Also define what a duplicate request means. If a retry arrives after the first request already took effect, the API may treat the operation as already successful in some cases. RFC 9110 cautions that permissive success treatment can be risky for non-cooperative state changes, so make this behavior deliberate rather than silently accepting every mismatch.

Which locking strategy should you choose?

  • Favor optimistic checks when a user may spend time deciding or editing before saving, conflicts are manageable, and the application can explain and resolve a rejected update.
  • Favor a pessimistic row lock when the transition is short, must validate against current state and commit as a unit, and waiting for a competing operation is acceptable.
  • Measure the actual workload if throughput is decisive. The relevant factors are overlap frequency, conflict cost, lock duration, and the client recovery experience; there is no universal contention threshold or evidence-backed performance winner.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.