https://codefarm0.medium.com/building-a-ticketing-...

Creato il: 27 gennaio 2026

Risposto usando GPT-5.2 Thinking da Chat01

Pensiero

Summarizing user-provided link

The user provided a URL, likely wanting a summary. I found that the article is behind a paywall, but there's a friend link available. Since I can’t access the full content, I'll summarize the visible sections and offer key points. I'll provide a quick summary and suggest focusing on specific areas if relevant.

Safely summarizing available content

I’ll summarize the visible sections of the article and base my explanation on general knowledge. Instead of suggesting bypassing the paywall, I’ll mention that I couldn’t access the full text due to restrictions. I’ll include core design patterns like booking flow, race conditions, schema, locking approaches, edge cases, architecture, and trade-offs.

Incorporating citations and elements

I’ll reference the appropriate sections: For the article metadata and ToC, I’ll cite Medium lines 22-63. PoC details will be cited from the README. References for Postgres row locks, Redis distributed locks, and Redlock will be pulled from their respective websites. I’ll cite sources without providing raw URLs. I won’t include unnecessary UI elements.

Thought for 2m 31s

Risposta

Here’s the gist of that Medium post (Arvind Kumar, Oct 30, 2025) and the concrete concurrency approaches it walks through. (Medium)

What it’s trying to solve

When a ton of people hit “Book” at the same time, the core failure mode is the classic read → decide → write race: multiple requests can read “seat is available” before any of them writes “seat is booked,” causing double-booking. (Medium)

The 3 main concurrency strategies (plus “naive” as the baseline)

A PoC repo based on the article lays these out very clearly (schema + sample queries + load-test behavior): (GitHub)

  1. Naive (what not to do)
    Read is_booked, then later UPDATE it—easy to break under concurrency. (GitHub)

  2. Pessimistic locking (DB row lock) Use a transaction + SELECT ... FOR UPDATE so only one transaction can “own” that seat row while deciding. (GitHub)

  • Upside: strongest safety, simplest mental model
  • Downside: contention under hot seats, plus deadlock/latency risks (GitHub)
  1. Optimistic locking (version / compare-and-swap) Add a version column; update only if the version you read is still current (UPDATE ... WHERE id=? AND version=?). If 0 rows updated → conflict → retry/return failure. (GitHub)
  • Upside: high throughput when conflicts are rare
  • Downside: you need solid retry/backoff behavior when conflicts spike (GitHub)
  1. Distributed locking (Redis) Acquire a short TTL lock (e.g., SET key value NX PX ...) before you touch the DB, so multiple app instances coordinate. (GitHub)
  • Upside: works across many stateless service replicas; can be fast
  • Downside: adds network dependency + correctness details (TTL, unlock token, etc.). The article also calls out Redlock as an “advanced” version. (Medium)

A sane end-to-end booking flow (what teams actually do)

The article’s ToC includes a “complete booking flow” + edge cases. (Medium) In practice, you usually combine one of the above with:

  • Hold/reserve with an expiration (seat is “held” for N minutes), then confirm on payment success, else release.
  • For multi-service systems, model it as a Saga (reserve → pay → confirm, with compensations like “release hold”). (temporal.io)

TL;DR decision guide

  • Few seats, lots of contention (flash sale): pessimistic DB locks or a distributed lock in front (carefully) (GitHub)
  • Many seats, low conflict rate: optimistic locking scales nicely (GitHub)
  • Many app instances + you need a cross-node mutex: Redis locks / Redlock pattern (Redis)

If you tell me what stack you’re using (Postgres/MySQL, Redis yes/no, monolith vs microservices), I can translate this into a concrete “do this, not that” implementation checklist.

Condividi questa Q&A