Spring Boot and Apache Kafka Integration : Ticketing System Study Case
The Role of Kafka in Tikceting System
Apache Kafka is widely used in ticket booking systems to support asynchronous and real-time processing, which is essential for large-scale systems with numerous users. Kafka helps ensure smooth operations, scalability, and reliability in handling ticket transactions.
Challenges in Ticketing System
Implementing a ticket booking system comes with several challenges, including:
- High Transaction Volume : Multiple users may attempt to book tickets simultaneously, leading to a surge in transaction requests.
- Data Consistency: The system must ensure that tickets are not overbooked and that availability is accurately reflected.
- Service Integration: A ticket booking system typically involves multiple services, such as payment processing, ticket inventory management, and user notifications. Kafka helps in integrating these services efficiently.
Kafka Role in Tikceting System
Kafka facilitates communication between various services by using topics to organize and manage event-driven data. The key Kafka topics used in the system are:
- orders-topic: Contains ticket order details (e.g., Order ID).
- payment-settlement-topic: Contains requests to process payments (e.g., Payment ID).
- notification-topic: Contains transaction status for both orders and payments (e.g., PENDING, CONFIRMED, CANCELED, COMPLETED).
Ticketing System Flow
The ticket booking process follows these key steps:
- Client Request: The user submits a ticket booking request.
- Producing Message: The frontend sends a Kafka message to the
orders-topic
. - Processing Orders: The backend reads messages from the
orders-topic
to process ticket orders, verify ticket availability, temporarily block tickets, and send confirmation to the user. - Webhook from Payment Gateway: The backend handles response from Payment Gateway. Is it payment success or failed.
- Payment Handling: Once the payment is successfully created, Kafka sends a message to the
payment-settlement-topic
for the payment service. - Updating Status: The payment service reads messages from the
payment-settlement-topic
and, once payment is completed, sends a message to thenotification-topic
topic to update the order status.
Architectural Components
The system consists of several key components that work together to ensure seamless ticket booking:
- Frontend: Sends ticket booking requests.
- Kafka: Manages message flow between services.
- Order Service: Processes ticket orders.
- Webhook Service: Process response from Payment Gateway
- Inventory Service: Verifies and blocks tickets.
- Payment Service: Processes payments.
- Notification Service: Sends notifications to users
Key Components and Listeners
Order Controller
Handles incoming booking requests and sends messages to Kafka.
WebhookController
Handles incoming response from payment gateway and send messege to kafka.
ProducerOrder
Produces messages to Kafka topics, specifically handling order requests.
OrderListener
Consumes messages from the orders-topic
and processes ticket bookings.
PaymentListener
Listens for payment-related messages from the payment-topic
and initiates transactions.
Notification Listener
Listens for status updates from the notification-topic
and triggers user notifications.
Testing
Order Ticket API Request
{
"header": {
"requestId": "123456",
"requestDS": "2025-02-03T12:00:00Z",
"uName": "USER_TESTING"
},
"payload": {
"ticketId": 1,
"eventId": 1,
"quantity": 2,
"paymentMethod": "QRIS"
}
}
Order Ticket API Response
{
"header": {
"responseCode": "00",
"responseMessage": "SUCCESS"
},
"payload": {
"orderId": "ORDER-20250205-338aa78d"
}
}
Webhook API
{
"header": {
"requestId": "123456",
"requestDS": "2025-02-03T12:00:00Z",
"uName": "USER_TESTING"
},
"payload": {
"paymentId": "ORDER-20250205-338aa78d",
"status": "SUCCESS"
}
}
Result
Conclusion
By leveraging Kafka’s capabilities, the ticket booking system can efficiently manage high volumes of transactions, maintain data consistency, and integrate various services seamlessly. Kafka’s event-driven architecture ensures scalability and responsiveness, making it an ideal solution for modern ticketing applications.
Repository : https://github.com/izzatarramsyah/tikceting-system