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).

Here is how to design a rock-solid high-load booking flow using Java 21, Spring Boot 3.4, PostgreSQL, and Redis.

1. Eliminating Overselling with PESSIMISTIC_WRITE + SKIP LOCKED

Optimistic locking (@Version) works well when conflicts are rare. During a flash sale, hundreds of requests collide on the same front-row seats simultaneously, causing massive OptimisticLockException rollback storms and wasted database connections.

Instead, row-level pessimistic locking serializes access cleanly at the PostgreSQL level:

SELECT * FROM seats WHERE id = :seatId AND status = 'AVAILABLE' FOR UPDATE; 

And when background workers scan for available seats or process queued events, adding SKIP LOCKED ensures threads never block each other waiting on locked rows.

2. Preventing Double Charges with Redis Idempotency

Mobile networks drop packets, and impatient users double-click the "Pay" button. Without idempotency, a retried request can create duplicate orders.

By requiring a unique Idempotency-Key (UUID) header from the client and atomically checking/storing its state in Redis with a TTL:

  • If the key is new, we lock it as IN_PROGRESS and execute the booking.
  • If a duplicate request arrives with the same key, we immediately return the cached response without touching PostgreSQL.

3. Guaranteed Event Delivery via Transactional Outbox

Never publish directly to Kafka or RabbitMQ inside your @Transactional booking method—if the broker succeeds and the DB commit fails (or vice versa), your system falls out of sync.

Instead, write the TicketBookedEvent into an outbox_events table inside the exact same local PostgreSQL transaction as the seat reservation. A background relay worker then polls outbox_events using FOR UPDATE SKIP LOCKED and publishes reliably.

Architecture Overview & Full Starter Kit

I put together a complete architecture overview, request flow diagram, and a production-ready Java 21 + Spring Boot 3.4 Starter Kit (including Docker Compose, Swagger UI, multi-threaded Testcontainers race-condition tests, and a Senior Java / System Design Interview Q&A guide):

How do you usually handle flash-sale concurrency in your Spring Boot services—pessimistic locking, Redis distributed locks, or queue-based serialization?