Design a Ticket Booking Site Like Ticketmaster¶
- Design a Ticket Booking Site Like Ticketmaster | Hello Interview
- System Design for Ticketmaster | System Design School
Requirements¶
Core Entities & APIs¶
System Design¶
Questions¶
What is Dual-write Problem?
Answer
The dual-write problem occurs when a system writes to two separate systems (e.g., a database and a message queue) in a non-atomic way. If one write succeeds and the other fails, the two systems become inconsistent, leading to data loss or duplication.
For example, if a service writes to a database and then publishes a Kafka message, and the Kafka write fails, consumers might never know about the database change. Solving this requires atomicity across systems, often via distributed transactions or outbox patterns.
How to Handle Dual-write Problem?
Answer
A common way to handle the dual-write problem is using the outbox pattern. Instead of writing to the database and message queue separately, the service writes both the main data and an event to the same database in a single transaction. A separate process (or CDC tool) then reads the outbox table and publishes the event to the message queue.
Another approach is using transactional message queues that support atomic writes with the database, like using Kafka with transactional producers or a distributed transaction coordinator (e.g., XA). However, these are complex and often less preferred due to performance and operational overhead.