{
  "id": 23800771,
  "title": "How to Prevent Overselling & Double Charges in High-Load Ticket Booking (Java 21 & Spring Boot 3.4)",
  "url": "https://urgent.news/2026/12/06/how-to-prevent-overselling-double-charges-in-high-load-ticket-booking",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-06T09:30:19.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/alex5205/how-to-prevent-overselling-double-charges-in-high-load-ticket-booking-java-21-spring-boot-34-g9p"
  },
  "original_language": null,
  "account": "During a flash sale, thousands of users attempt to book concert tickets simultaneously. Using a standard SELECT - CHECK - UPDATE flow to check seat availability and update status can cause overselling - two different buyers paying for the same seat. To prevent this, the article recommends using PESSIMISTIC_WRITE with SKIP LOCKED in PostgreSQL. This means selecting rows for update with a \"SELECT * FROM seats WHERE id = :seatId AND status = 'AVAILABLE' FOR UPDATE;\" query. This serializes access cleanly at the database level. For background workers scanning for available seats, adding SKIP LOCKED ensures threads don't block each other waiting on locked rows. To prevent double charges from retried requests that could create duplicate orders, the article suggests requiring a unique Idempotency-Key header from the client. This key is atomically checked and stored in Redis with a TTL (time-to-live). If the key is new, it's locked as \"IN_PROGRESS\" and the booking proceeds. Duplicate requests with the same key return the cached response without touching the database. For guaranteed event delivery, the article advises against publishing directly to Kafka or RabbitMQ inside the booking transaction. Instead, it recommends writing the event into an outbox_events table inside the same PostgreSQL transaction as the seat reservation. A background relay worker then polls the outbox_events table using FOR UPDATE SKIP LOCKED and reliably publishes the events. The full architecture, request flow diagram, and a production-ready Java 21 + Spring Boot 3.4 starter kit are available on GitHub. The starter kit includes Docker Compose, Swagger UI, multi-threaded test cases for race conditions, and a guide for senior Java / system design interviews.",
  "summary": "Selling concert tickets during a flash sale is one of the toughest concurrency problems in backend engineering. Thousands of users hit the \"Book Seat\" endpoint at the exact same millisecond. If you rely on a standard SELECT -> CHECK -> UPDATE flow, two threads will read the seat as AVAILABLE at the exact same time—resulting in overselling (two different buyers paying for the exact same seat).…",
  "summary_source": "publisher",
  "key_points": [
    "Use PESSIMISTICWRITE with SKIP LOCKED in PostgreSQL to prevent overselling during flash sales.",
    "Require unique Idempotency-Key header from client to avoid double charges from retried requests."
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}