Skip to content
Vibhrav Jha.Let’s talk
All projectsDistributed Systems

HDFS & SQL Pipeline

Queryable distributed data with storage recovery

My contributionData movement, query service and storage-recovery implementation within the course project.

FieldDistributed Systems / Data Engineering

View repository

Academic project

Architecture diagram connecting MySQL, a gRPC service and HDFS storage

The work
behind the interface.

Made MySQL data queryable as partitioned Parquet in HDFS, with caching, selective column reads and a recovery path for DataNode loss.

  • Python
  • MySQL
  • HDFS
  • gRPC
  • Parquet
  • Docker

The result

A queryable distributed dataset with cached results and explicit storage-recovery behavior.

The problem

Implemented a MySQL-to-HDFS pipeline with gRPC access, Parquet storage and query caching.

A decision worth examining

Partition by county code and read selected columns, with a recovery path for DataNode loss.

Read the README.

View original README
READMEArchitecture, setup and usage

Distributed Data Pipeline with HDFS & SQL Integration

A fault-tolerant data processing system that integrates MySQL databases with Hadoop Distributed File System (HDFS). Features intelligent data partitioning, automated failover mechanisms, and performance optimization through strategic replication and caching strategies.

Architecture

System Architecture

Data Flow

The system consists of six containerized services:

  • MySQL Server: Source database for loan application data
  • HDFS NameNode: Metadata management and coordination
  • HDFS DataNodes (3 replicas): Distributed block storage
  • gRPC Server: API layer with intelligent caching and failover logic
  • Client: Command-line interface for system operations

Key Features

🗄️ Hybrid Data Storage

  • SQL database integration for structured data access
  • HDFS for large-scale distributed file storage
  • Parquet format for efficient columnar storage
  • Multi-level replication strategies (1x and 2x)

⚡ Performance Optimization

  • Intelligent data partitioning by county code
  • Query result caching with automatic partition creation
  • Selective column reading for reduced I/O
  • 40%+ performance improvement on repeated queries

🛡️ Fault Tolerance

  • Automatic failover on DataNode failures
  • Graceful degradation with 1x replication recovery
  • Smart retry mechanisms for transient failures
  • Data integrity maintained through replication

🔌 gRPC API

  • Protocol Buffers for efficient serialization
  • RESTful WebHDFS integration
  • Block location tracking and monitoring
  • Comprehensive error handling

Technical Stack

  • Database: MySQL 8.0
  • Distributed Storage: Apache Hadoop HDFS 3.x
  • Data Format: Apache Parquet, Apache Arrow
  • RPC Framework: gRPC, Protocol Buffers
  • Backend: Python 3.x
  • Containerization: Docker, Docker Compose
  • Analysis: pandas, matplotlib

API Operations

1. Database to HDFS Migration

python3 client.py DbToHdfs
  • Connects to MySQL database
  • Filters loan applications ($30K-$800K range)
  • Exports filtered dataset to HDFS as Parquet
  • Configures 2x replication and 1MB block size

2. Block Location Analysis

python3 client.py BlockLocations -f /hdma-wi-2021.parquet
  • Queries WebHDFS API for file metadata
  • Returns block distribution across DataNodes
  • Useful for understanding data locality

Sample Output:

{
  "7eb74ce67e75": 15,
  "f7747b42d254": 7,
  "39750756065d": 8
}

3. County-Level Loan Analysis

python3 client.py CalcAvgLoan -c 55001
  • Calculates average loan amount for specified county
  • Creates optimized county-specific partitions on first access
  • Reuses partitions for 40%+ faster subsequent queries
  • Returns data source indicator (create/reuse/recreate)

Performance Analysis

Partitioning Strategy Benefits

Performance Analysis

The system demonstrates significant performance gains through intelligent partitioning:

  • First Query (create): ~850ms - Scans full dataset, creates partition
  • Subsequent Queries (reuse): ~620ms - Uses pre-filtered partition (27% faster)
  • Recovery (recreate): Falls back to full scan when partitions unavailable

Benchmark Results

OperationTime (ms)Data Source
create850Full dataset
reuse620County partition
recreate870Full dataset (post-recovery)

Performance Script (performance_analyzer.py):

  • Automated benchmarking across multiple counties
  • Measures create vs. reuse performance
  • Generates comparative visualizations
  • Validates partitioning effectiveness

Fault Tolerance Design

Replication Strategy

Full Dataset (hdma-wi-2021.parquet):

  • 2x replication across DataNodes
  • Survives single DataNode failure automatically
  • HDFS handles block recovery transparently

County Partitions (partitions/<county>.parquet):

  • 1x replication for storage efficiency
  • Custom recovery logic on DataNode failure
  • Automatic recreation from source dataset

Failure Recovery Flow

  1. Detection: OSError exception on partition read
  2. Fallback: Query full dataset with county filter
  3. Recreation: Write new partition to available DataNodes
  4. Response: Return results with "recreate" source indicator

Failure Detection & Recovery

The NameNode monitors DataNode health through:

  • Heartbeat protocol (default 3-second intervals)
  • 10-minute timeout for marking nodes as dead
  • Automatic block replication to maintain redundancy
  • Under-replication detection and recovery scheduling

Data Flow

  1. Extraction: SQL query filters loan applications by amount
  2. Transformation: Convert to Parquet columnar format
  3. Loading: Upload to HDFS with configured replication
  4. Partitioning: Create county-specific subsets on demand
  5. Caching: Reuse partitions for performance gains
  6. Recovery: Recreate partitions after failures

Deployment

Build Images

docker build -f Dockerfile.hdfs -t loan-data-hdfs .
docker build -f Dockerfile.namenode -t loan-data-nn .
docker build -f Dockerfile.datanode -t loan-data-dn .
docker build -f Dockerfile.mysql -t loan-data-mysql .
docker build -f Dockerfile.server -t loan-data-server .

Start Cluster

export PROJECT=loan-data
docker compose up -d

Run Performance Analysis

docker build -f Dockerfile.analyzer -t loan-data-analyzer .
docker run --rm \
  --network=loan-data_default \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$(pwd)/outputs:/app/outputs" \
  loan-data-analyzer

System Monitoring

Check HDFS Status

docker exec -it loan-data-server-1 hdfs dfs -ls /
docker exec -it loan-data-server-1 hdfs dfsadmin -report

Simulate DataNode Failure

docker kill loan-data-datanode-1
# Wait for NameNode to detect failure (~10 minutes)
# System continues operating with reduced capacity

Implementation Highlights

SQL Integration

  • Connection pooling with retry logic
  • Complex JOIN operations across loan tables
  • Efficient result set streaming to HDFS

HDFS Operations

  • PyArrow HadoopFileSystem for native integration
  • WebHDFS REST API for metadata queries
  • Custom environment configuration for Hadoop client

Error Handling

  • Graceful degradation on DataNode failures
  • Exception-based recovery strategies
  • Comprehensive logging for debugging

Performance Optimization

  • Columnar storage format (Parquet)
  • Selective column reading
  • Smart caching with automatic partition management

Skills Demonstrated

  • Distributed Systems: HDFS architecture, replication, fault tolerance
  • Database Engineering: SQL optimization, data migration, ETL pipelines
  • Data Formats: Parquet, Arrow, columnar storage
  • RPC Communication: gRPC, Protocol Buffers
  • Containerization: Docker multi-container orchestration
  • Performance Engineering: Benchmarking, optimization, caching strategies
  • Fault Tolerance: Recovery mechanisms, graceful degradation
  • System Monitoring: Log analysis, health checking

Dataset

Loan application data from Wisconsin housing market (2021), including:

  • Loan amounts, property values, applicant demographics
  • County-level geographic information
  • 426,716 filtered records ($30K-$800K range)

A production-ready demonstration of distributed data processing with enterprise-grade fault tolerance.

Spark Analytics

  1. Aranyaka wildlife-image application interface

    Fullstack

    Aranyaka

  2. DermaNet hackathon prototype showing classification output and a generated explanation

    ML & AI

    DermaNet

  3. AI-generated concept illustration of source documents connected to retrieved evidence and an answer

    ML & AI

    Private-Data RAG

  4. Before It Breaks dashboard separating real weather from synthetic equipment telemetry and estimated costs

    ML & AI

    Before It Breaks

  5. Architecture diagram of simulated stock records flowing through Kafka to HDFS

    Distributed Systems

    Stock Streaming Engine

  6. Vyaya dashboard with clearly labeled synthetic demonstration data

    Fullstack

    Vyaya

  7. Study assistant interface with retrieved source context

    ML & AI

    Fine-Tuning vs. RAG

  8. Architecture diagram of NOAA data, a Cassandra cluster and a query service

    Distributed Systems

    Distributed Weather Data System

  9. Distributed Property Lookup Service project image

    Distributed Systems

    Distributed Property Lookup Service

  10. Architecture diagram connecting MySQL, a gRPC service and HDFS storage

    Distributed SystemsViewing

    HDFS & SQL Pipeline

  11. Architecture diagram of Spark processing, SQL and analysis

    Distributed Systems

    Spark Analytics

  12. Multi-Source ELT Pipeline project image

    Data Engineering

    Multi-Source ELT Pipeline

  13. Wisconsin schools in their geographic context — explanatory architecture diagram

    Data Engineering

    GCP Geospatial Pipeline

  14. Chinook Music Store SQL Analytics project image

    Data Engineering

    Chinook Music Store SQL Analytics

  15. Yelp Geospatial Analytics project image

    Data Engineering

    Yelp Geospatial Analytics

  16. E-Commerce Semantic Search Engine project image

    Data Engineering

    E-Commerce Semantic Search Engine

  17. Retail Sales Forecasting project image

    ML & AI

    Retail Sales Forecasting

  18. Making tool dependencies inspectable — explanatory architecture diagram

    ML & AI

    AI Agent Tool Dependency Graph

  19. From public records to operational questions — explanatory architecture diagram

    Data Engineering

    Palantir Foundry and AIP Build Challenge

  20. StudyFlow study-session dashboard

    Fullstack

    StudyFlow

  21. Habit Command Center planning dashboard

    Fullstack

    Habit Command Center

  22. Interfaces across web and mobile — explanatory architecture diagram

    Fullstack

    React Web & Mobile

  23. Startup Scout project image

    Fullstack

    Startup Scout

  24. Inventory-Based Recipe Planner project image

    Fullstack

    Inventory-Based Recipe Planner

  25. Concurrent Word Count and Performance Benchmarking project image

    Data Engineering

    Concurrent Word Count

  26. Data structures matched to their assumptions — explanatory architecture diagram

    Computing Foundations

    Algorithm Design

  27. Campus Navigator project image

    Fullstack

    Campus Navigator

  28. i-Songly: Song Management Engine project image

    Fullstack

    i-Songly

  29. An experiment that can resume — explanatory architecture diagram

    ML & AI

    CIFAR-100 with LeNet

  30. Fashion-MNIST Neural Network Classifier project image

    ML & AI

    Fashion-MNIST Classifier

  31. PCA Eigenfaces and Image Reconstruction project image

    ML & AI

    PCA Eigenfaces

  32. Two routes to the same regression objective — explanatory architecture diagram

    ML & AI

    Lake Mendota Ice Regression

  33. Bayesian Language Detection project image

    ML & AI

    Bayesian Language Detection

  34. Explanatory diagram of the video-fingerprint benchmark: 25 sources, 75 transformed variants and 1,875 comparisons.

    ML & AI

    Video-Fingerprint Benchmark

All projects