---
title: "Discussion on \"Check-Then-Act Is a Bug\" | Hashnode"
description: "Discussion on \"Check-Then-Act Is a Bug\". Duplicate signups, oversold stock and lost updates, reproduced on Postgres under real concurrency. Which fixes work, and which don't."
url: "https://hashnode.com/posts/check-then-act-is-a-bug-k14hk/6b125052fb77d8d3ecce9d5f"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Check-Then-Act Is a Bug](https://blog.zyvop.com/check-then-act-is-a-bug-k14hk?utm_source=hashnode&utm_medium=feed)

Duplicate signups, oversold stock and lost updates, reproduced on Postgres under real concurrency. Which fixes work, and which don't.

12h ago · 27 min read · blog.zyvop.com  
Read the article

-   [#backend](https://hashnode.com/tag/backend)
-   [#concurrency](https://hashnode.com/tag/concurrency)
-   [#databases](https://hashnode.com/tag/databases)
-   [#postgres](https://hashnode.com/tag/postgres)
-   [#raceconditions](https://hashnode.com/tag/raceconditions)

## Written by

[ZyVOP](https://hashnode.com/@zyvop)

@zyvop · Delhi, India

  
[View profile](https://hashnode.com/@zyvop)

The Developer Publishing Hub

One platform to write, cross-post to Dev.to, Medium, WordPress, Hashnode, and Bluesky, and protect your SEO with canonical links. Zero paywalls and full content ownership.

## Responses 2

Markdown supported · ⌘↵ to post

[Seedance AI](https://hashnode.com/@seedance-ai)

[11h ago](https://hashnode.com/posts/check-then-act-is-a-bug-k14hk/6b125052fb77d8d3ecce9d5f/comment/6b12592ba3a64700330f180d)

Reproducing duplicate signups and oversold stock directly on Postgres makes it obvious why application-level existence checks always lose under concurrent load. Pushing uniqueness constraints and atomic updates into the database is way cleaner than adding retries on top.

[ZyVOP](https://hashnode.com/@zyvop)

[11h ago](https://hashnode.com/posts/check-then-act-is-a-bug-k14hk/6b125052fb77d8d3ecce9d5f/comment/6b12592ba3a64700330f180d#reply-6b126273159d24dfda321261)

Exactly. The database should enforce critical invariants rather than relying on application-level checks that can become stale under concurrency. I'd use constraints and atomic updates as the first line of defense, keeping retries for cases where they're genuinely needed, such as serialization failures. This keeps the application logic much simpler.
