Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

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:

  1. Periodic data collection: Regularly fetching the latest data to maintain freshness

  2. Efficient data storage: Minimizing database overhead during insertion

  3. Fault tolerance: Handling errors without service disruption

  4. Resource management: Properly managing connections and threads

  5. Configurable behavior: Adjusting parameters like frequency based on requirements

The Data Ingestion Workflow

The data ingestion workflow follows these steps:

  1. Scheduled execution: A timer triggers data collection at regular intervals

  2. Data fetching: The GTFS client retrieves vehicle positions from the transit feed

  3. Data transformation: Vehicle data is converted to the domain model format

  4. Batch processing: Records are grouped into batches for efficient storage

  5. Transactional storage: Each batch is stored atomically in the database

  6. 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?