How ably-labs/realtime-ticket-booking-solution works
Project Type and Purpose
• This project is a real-time ticket booking solution that ties together event booking with streaming data pipelines. The README clearly states that it relies on a Confluent Platform running Kafka, ksqlDB, and Schema Registry. It further uses modern frameworks such as FastAPI for the web API and Ably for real-time client communications. Ngrok is used to expose services externally.
Analyzing the File Structure
• Top-level files:
• app.py: Likely the entry point for the FastAPI application handling API requests.
• models.py: Contains domain and data models, representing business logic.
• requirements.txt: Lists Python dependencies (like FastAPI, other libraries).
• LICENSE, .gitignore, README.md: Contain meta and guidance information.
• Directories:
• queries: Contains ksqlDB SQL queries (ksqldb-queries.sql) that interact with Kafka streams.
• schemas: Holds Avro schema definitions (booking-schema.avsc, conference-schema.avsc) and documentation (schemas.md). This directory indicates the use of a Schema Registry and structured message formats.
• test-scripts: Contains scripts for testing booking and event creation functionality.
• The layout shows a focused backend service that integrates with streaming infrastructure and schema validation.
Key Components
a. API Layer (Backend):
• FastAPI service (from app.py) that processes incoming HTTP requests related to ticket booking.
• Connection from the API to the underlying business logic defined in models.py.
b. Messaging and Streaming Infrastructure:
• Kafka Broker: Indicate the Kafka clusters responsible for handling messages.
• ksqlDB: Highlight the use of ksqlDB for querying streaming data using the SQL queries found in the 'queries' directory.
• Schema Registry: Include the external service that validates the Avro schemas stored in the 'schemas' folder (booking and conference schemas).
c. Real-Time Communication and External Services:
• Ably: Represent Ably as the component handling real-time WebSocket communications or messaging to end clients.
• Ngrok: Note Ngrok’s role as a tunneling service providing external access to the otherwise local API endpoints.
d. Test Components:
• Test-scripts: Reference these as part of quality assurance and simulation for booking events.
Relationships and Interactions
• User requests arrive at the FastAPI service.
• The API processes ticket bookings and communicates with Kafka to publish booking events.
• Kafka, configured with the Schema Registry, validates messages against Avro schemas.
• ksqlDB uses the queries from the queries folder for real-time stream processing.
• Ably serves as the external edge, pushing processed updates to clients, possibly via WebSockets.
Architectural Patterns and Technologies
• Separation between the API layer (FastAPI and business logic) and the streaming platform (Kafka ecosystem).
• Integration points where external tooling (Ably, Ngrok) connects to the internal services.
• Mention the use of Avro schemas and Schema Registry, which help maintain consistent messaging formats across systems.
• That the solution follows principles such as decoupled architecture via messaging and enables real-time communication via websocket-based services (Ably).