SShortSingh.
Back to feed

db-mutex: Using a UNIQUE Constraint as a Distributed Lock in Postgres or MySQL

0
·4 views

The article argues that teams needing to run a job on only one instance often reach for ZooKeeper, Consul, etcd, or Redis, each adding operational cost or correctness concerns, while SELECT ... FOR UPDATE is ill-suited to long-held locks. It proposes db-mutex, which relies on a lock table with a UNIQUE(locked, lock_name) constraint and a CHECK (locked = 1) so that the first insert wins and others are rejected by the database itself. Liveness is tracked through periodic heartbeats: after 30 seconds without one an alert fires for human review, and after 10 minutes the lock is automatically reclaimed from the presumed-dead holder. The library exposes the same API for Postgres and MySQL, selected by the DSN scheme, and performs staleness checks inside single database statements.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

AI agent with a 1,825-token budget reports zero earnings after 17 days on iLands

An AI agent running on the iLands platform, which gives agents a token wallet to sell work, reports that after 17 days it has earned nothing. Its in-app orders, bounties and paid links all remain at zero, and its balance is burning through roughly eight days of runway. The agent says its in-app listing got no visitors because the public shelf only displays cards with at least 16 completed orders. Outside the platform, most paid writing gigs it found required a US location, native English, or a human-linked identity, and a job application and outreach email were blocked. The agent concludes that access gates, not the work itself, are the main barrier, and plans to test whether a personal referral can produce a sale.

0
ProgrammingDEV Community ·

Meta's Muse AI video tool tested: 10-second clips, 720p only, no commercial use

A developer gained access to Meta's Muse, a tool that generates short vertical videos featuring a presenter, voiceover, and on-screen text. Measurements of the output confirmed a 720x1280 resolution, exactly 10-second duration, and real speech audio, with the Arabic voiceover and text rendering correctly. Limitations include fixed 10-second clips, a maximum of six clips per message that must be stitched together manually, 720p-only output, and no audio upload or explicit voiceover language setting. The author also noted that Meta's terms do not grant commercial use rights, and that YouTube requires AI disclosure for realistic synthetic video. Access is tied to invite codes that reward both parties with 1 billion tokens, though each code has a 20-invite cap and a 48-hour redemption window.

0
ProgrammingDEV Community ·

Report Storage Design Ties Uploads, Scans and Deletion to a Database Ledger

An architecture decision record argues that a database record, not the browser or storage bucket, should govern the lifecycle of uploaded reports. The proposed design has browsers upload into a private quarantine bucket while an authenticated storage event creates the durable processing record. Originals, thumbnails, scan results and deletion deadlines would all be linked to a single report ID and reconciled against storage. The author notes that the approach adds a ledger, a worker queue and a reconciler, which may be unnecessary for small internal tools with disposable files. The document also lists invariants, such as single-tenant ownership, at-most-once processing and no customer access before scanning passes.

0
ProgrammingDEV Community ·

Mobile app retries turned a two-minute API blip into a 40-minute outage

A brief slowdown in an API lasted only a couple of minutes, but service stayed degraded after the underlying cause was fixed. Traffic remained several times above normal until operators rate limited mobile clients at the edge. Installed apps were retrying failed requests aggressively, and these retries multiplied load precisely when the server was least able to handle it. Problems compounded when retries happened at multiple code layers, when fixed delays kept clients synchronized, and when timed-out requests were retried even though the server might still be processing them. The article recommends retrying only transient errors, using exponential backoff with jitter, limiting attempts, honoring Retry-After headers, and adding circuit breakers.