Building the Data Ingestion Service
Implement batch data ingestion with transactions into Apache Ignite
This module implements a data ingestion service that continuously fetches vehicle position data from GTFS feeds and stores it in Apache Ignite using batch transactions.
Understanding Data Ingestion Requirements
Real-time transit monitoring demands a reliable data pipeline with specific characteristics:
Periodic data collection: Regularly fetching the latest data to maintain freshness
Efficient data storage: Minimizing database overhead during insertion
Fault tolerance: Handling errors without service disruption
Resource management: Properly managing connections and threads
Configurable behavior: Adjusting parameters like frequency based on requirements
The Data Ingestion Workflow
The data ingestion workflow follows these steps:
Scheduled execution: A timer triggers data collection at regular intervals
Data fetching: The GTFS client retrieves vehicle positions from the transit feed
Data transformation: Vehicle data is converted to the domain model format
Batch processing: Records are grouped into batches for efficient storage
Transactional storage: Each batch is stored atomically in the database
Statistics tracking: Metrics are collected to monitor ingestion performance
Ingest Service Implementation
Open the DataIngestionService class:
The core functionality is in the fetchAndStoreData() method, which the scheduler calls periodically:
This method records the start time for performance measurement, calls the GTFS service to fetch vehicle positions, updates statistics counters, delegates to storeVehiclePositions() for persistence, and captures timing statistics.
The actual storage happens in storeVehiclePositions():
This method obtains a reference to the vehicle positions table, creates a RecordView for type-safe operations, processes records in configurable batches, and uses runInTransaction to ensure each batch is stored atomically. If any upsert within a batch fails, the entire batch rolls back.
Statistics Tracking
The service tracks performance metrics using atomic variables:
These statistics are exposed through the IngestStats class, an immutable data container:
Service Lifecycle Management
The DataIngestionService includes methods to start and stop the service:
The start() method resets statistics and schedules fetchAndStoreData at fixed intervals. The stop() method performs a graceful shutdown with a 5-second timeout, falling back to forced shutdown if necessary.
Running the Ingest Example
Run the ingestion service example:
This runs the IngestExample class:
The example verifies database connectivity, sets up the schema if needed, starts the ingestion service with a 15-second interval, runs for 45 seconds while showing a progress indicator, displays statistics, and stops the service.
The core part:
Expected output:
Next Steps
This module implemented a data ingestion service that periodically fetches vehicle position data from GTFS-realtime feeds, stores it efficiently using batch transactions, handles errors gracefully, and provides performance statistics.
The next module builds on this foundation by implementing a monitoring service that detects service disruptions in real-time.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

