Ticketing And Reservation Holds
Asked of: Software Engineer
Last updated

What's being tested
These designs test distributed-systems correctness under concurrent requests: preventing double-booking while seats transition through available, held, paid, cancelled, and expired states. The interviewer is probing whether you can define clear consistency guarantees, model expiration and retries, and choose a storage strategy that remains correct during failures and high contention. Meta cares because reservation systems concentrate traffic on a small set of hot resources, making race conditions, idempotency, and graceful degradation more important than simply drawing a scalable architecture.
Core knowledge
-
Model booking as an explicit state machine:
AVAILABLE → HELD → CONFIRMED, withHELD → AVAILABLEon expiry or cancellation. Reject illegal transitions such asCONFIRMED → AVAILABLE; enforce transitions in one authoritative service. -
Use optimistic concurrency control with a version or conditional update:
UPDATE seats SET status='HELD', version=version+1 WHERE event_id=? AND seat_id=? AND status='AVAILABLE'. Success means one writer won; zero rows means conflict. -
For a small, fixed seat map, store one row per seat in
PostgresorMySQLand update selected rows transactionally.SELECT ... FOR UPDATEis straightforward but can reduce throughput; conditional writes usually hold locks for less time. -
A hold needs
hold_id,user_id, selected inventory,created_at,expires_at, and an idempotency key. Treatexpires_atas authoritative rather than trusting a background worker to release inventory exactly on time. -
Implement expiration with both lazy expiration and asynchronous cleanup. Reads and booking attempts treat
expires_at <= nowas expired; aKafka-backed worker or delayed queue later changes rows toAVAILABLEfor storage hygiene. -
Make every mutating API idempotent: persist
(user_id, idempotency_key) → responseand return the original result on retry. Includehold_idorpayment_idin downstream commands so retries cannot create duplicate reservations. -
Keep payment outside the inventory transaction, because payment providers are slow and can fail independently. The usual flow is
AVAILABLE → HELD → payment authorization → CONFIRMED; reconciliation handles payment success arriving after a client timeout. -
Choose inventory granularity based on contention. Assigned seats require per-seat ownership; general admission can use an atomic counter where
available_count >= quantity, but counters must not drift from orders and need reconciliation. -
A single-writer partition per event or venue can serialize conflicting seat operations and simplify correctness. It improves reasoning but creates hot partitions; shard large events by section or seat range while preserving a clear ownership rule.
-
Define failure semantics explicitly: if the hold response is lost, the client retries with the same key; if the database commits but the event is not published, an outbox pattern publishes the durable state change later.
-
Avoid treating
Redisalone as the source of truth unless its durability and failover semantics meet the requirement. Redis locks can reduce duplicate work, but correctness should come from a transactional or conditionally consistent inventory store. -
Size the system from peak contention, not average traffic. If an event has seats and peak arrival rate , the useful booking throughput is bounded by inventory mutations and hot-partition capacity, not merely by stateless API replicas.
Worked example: Design a ticket or hotel reservation system
For Design a ticket or hotel reservation system, I would first clarify whether seats are assigned, whether users may hold multiple seats, the hold duration, oversell tolerance, payment timing, and whether correctness or availability dominates during a partition. I would declare an assumption such as assigned seats, a five-minute hold, no overselling, and eventual notifications but strongly consistent inventory. I would organize the answer around the inventory data model, the hold/confirmation state machine, concurrency control, and expiration plus payment failure handling. The core write would conditionally transition each requested seat from AVAILABLE to HELD in a transaction, recording a durable hold_id and expires_at. I would explicitly choose a relational database for the authoritative seat rows because transactional conditional updates are easier to prove correct than a cache-based lock. I would then add stateless APIs, read replicas or cached availability for browsing, and idempotency records for retries. I would call out the tradeoff that locking all requested seats prevents partial holds but increases contention and deadlock risk, so rows should be acquired in deterministic seat order. If I had more time, I would discuss payment reconciliation, multi-region ownership, load testing hot events, and operational metrics such as hold conflicts and expiration lag.
A second angle
For Design Ticket Booking Auto Release, the central challenge shifts from initial allocation to reliable expiration without depending on a perfectly timed scheduler. The design should combine request-time validation of expires_at with an asynchronous release worker, making cleanup delay harmless to correctness. I would discuss duplicate release messages, worker crashes, clock skew, and idempotent state transitions. A useful guarantee is that expired inventory is never sold twice, while temporary database residue is acceptable until cleanup catches up.
Common pitfalls
Pitfall: Treating a
Redislock or a periodic cleanup job as the correctness mechanism is analytically weak. A stronger answer makes the inventory database enforce the invariant and treats locks and cleanup as performance or hygiene tools.
A common communication mistake is jumping directly into Kafka, sharding, and multi-region replication without stating the booking invariant. Say first, “No seat may be confirmed for two customers,” then explain which operation atomically protects that invariant.
Pitfall: Saying “the hold expires after five minutes” without defining who observes expiration misses the hard case. Explain client retries, worker delay, clock differences, payment callbacks, and the exact legal state transitions.
Connections
The interviewer may pivot to idempotency, outbox and saga patterns, leader election, partition tolerance, or multi-region data ownership. They may also ask how to test race conditions with concurrent clients, fault injection, and invariant-based assertions.
Further reading
- Designing Data-Intensive Applications — strong treatment of consistency, transactions, replication, partitioning, and distributed-system failure modes.
- Stripe: Idempotent Requests — practical treatment of safe retries for payment-like APIs.
- Martin Kleppmann, “Please stop calling databases CP or AP” — useful context for discussing consistency and availability tradeoffs precisely.
Practice questions
- Design a ticket or hotel reservation systemMeta · Software Engineer · Onsite · medium
- Design ticketing system with seat holdMeta · Software Engineer · Onsite · medium
- Implement held transfers with accept/cancelMeta · Software Engineer · Online Assessment · hard
- Design Ticket Booking Auto ReleaseMeta · Software Engineer · Technical Screen · medium
Related concepts
- Auctions, Ticketing, And Real-Time MessagingSystem Design
- Pricing, Demand, And Capacity OptimizationAnalytics & Experimentation
- Split Stay Availability And Interval PairingSystem Design
- Interval Scheduling And Calendar SystemsCoding & Algorithms
- Rate Limiters, Quotas, And Resource GovernanceSystem Design
- Distributed Job Scheduler SystemsSystem Design