Skip to content

toamitrawat/transaction-batch-process

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Transaction Batch Process

Spring Boot application that automatically processes transaction files from AWS S3 and loads them into Oracle Database

Spring Boot Java AWS Oracle


🎯 Overview

This is a production-ready, event-driven batch processing system that:

  1. πŸ“₯ Listens to AWS SQS for S3 file upload notifications
  2. πŸ“ Streams transaction files directly from S3 (memory efficient)
  3. βš™οΈ Processes records in configurable chunks using Spring Batch
  4. πŸ’Ύ Loads data into Oracle Database with full transaction management
  5. πŸ”„ Idempotent - DB-backed file log prevents duplicate processing
  6. πŸ“Š Monitors job execution with comprehensive logging

Key Benefits

  • βœ… Zero manual intervention - fully automated processing
  • βœ… Scalable - handles files of any size with streaming
  • βœ… Resilient - late-ack SQS strategy, skip policy, visibility heartbeat, and retry with backoff
  • βœ… Idempotent - transaction_file_log table prevents duplicate file processing
  • βœ… Production-ready - rolling log files, comprehensive monitoring

πŸ—οΈ Architecture

AWS S3 Upload β†’ S3 Event β†’ SQS Message β†’ Spring App β†’ Stream File β†’ Process Batch β†’ Oracle DB

Detailed Flow:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ File Upload β”‚ User uploads transaction file
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  S3 Bucket  β”‚ ObjectCreated event triggered
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  SQS Queue  β”‚ Event notification queued
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Spring Boot β”‚ @SqsListener receives message
β”‚ Application β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  S3 Stream  β”‚ Download as InputStream (no temp files)
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Spring Batch β”‚ Reader β†’ Processor β†’ Writer (chunks)
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Oracle DB  β”‚ Persisted with transaction management
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ‘‰ See ARCHITECTURE.md for detailed technical design


πŸ“‹ Prerequisites

Component Version Required
Java JDK 21+ βœ…
Maven 3.6+ βœ…
Oracle Database 12c+ βœ…
AWS Account - βœ…
AWS CLI (optional) 2.x β­•

πŸš€ Quick Start

1️⃣ Clone or Navigate to Project

cd d:\Java_Projects\transaction-batch-process

2️⃣ Configure Application

Edit src/main/resources/application.yml with your Oracle and AWS details.

AWS credentials are resolved via the AWS Default Credential Provider Chain β€” configure ~/.aws/credentials, environment variables (AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY), or an IAM role. No credential properties are read from application.yml.

3️⃣ Build

mvn clean package

4️⃣ Run

java -jar target/transaction-batch-process-1.0.0.jar

5️⃣ Test

# Upload sample file
aws s3 cp sample-data/transactions.txt s3://your-bucket/test.txt

Watch the logs for automatic processing! πŸŽ‰

πŸ‘‰ Need help? See QUICKSTART.md for 10-minute setup guide


πŸ“ File Format

The application processes # delimited flat files:

673440#245894#MGEIQ3RW9Q#2021-12-23#4459.12#3011.44#CREDIT#70945.54
673441#245895#MGEIQ3RW9R#2021-12-24#0.00#5000.00#DEPOSIT#75945.54

No header row β€” data starts at line 1.

Field Descriptions

Field Type Description
customerId String Customer identifier
trans_num String Transaction number
transaction_id String Unique transaction ID
transaction_date Date Format: YYYY-MM-DD
withdrawal_amount Decimal Withdrawal amount (use 0.00 if none)
deposit_amount Decimal Deposit amount (use 0.00 if none)
transaction_type String CREDIT/DEBIT/WITHDRAWAL/DEPOSIT
balance Decimal Account balance after transaction

βš™οΈ Configuration

Application Properties (application.yml)

# Database Configuration
spring:
  datasource:
    url: jdbc:oracle:thin:@localhost:1521/XEPDB1   # service name format, not SID
    username: your_oracle_user
    password: your_oracle_password

# AWS Configuration (credentials via Default Credential Provider Chain, not here)
aws:
  region: ap-south-1
  s3:
    bucket-name: your-transaction-bucket
  sqs:
    queue-url: https://sqs.ap-south-1.amazonaws.com/account-id/your-queue

# Batch Configuration
batch:
  chunk-size: 1000                    # Records per chunk
  skip-limit: 2147483647              # Integer.MAX_VALUE β€” individual failures never abort the job
  file-delimiter: "#"
  enable-dml-error-logging: true
  fallback-initial-delay-ms: 500      # Delay before individual fallback inserts
  lock-retry-max-attempts: 3          # Max retries for transient lock errors
  lock-retry-base-delay-ms: 200       # Exponential backoff base (ms)
  lock-retry-max-delay-ms: 2000       # Exponential backoff ceiling (ms)

πŸ—„οΈ Database Schema

Table: transaction_process

CREATE TABLE transaction_process (
    id NUMBER(19) PRIMARY KEY,
    customer_id VARCHAR2(50) NOT NULL,
    trans_num VARCHAR2(50) NOT NULL,
    transaction_id VARCHAR2(50) UNIQUE NOT NULL,
    transaction_date DATE NOT NULL,
    withdrawal_amount NUMBER(15, 2),
    deposit_amount NUMBER(15, 2),
    transaction_type VARCHAR2(20) NOT NULL,
    balance NUMBER(15, 2) NOT NULL,
    file_name VARCHAR2(255),
    processed_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

The DDL is in src/main/resources/schema.sql and must be applied manually before first run β€” initialize-schema: never is set intentionally.


🎯 Features

βœ… Automated Processing

  • Event-driven architecture with SQS
  • No manual job triggering required
  • Processes files immediately after upload

βœ… Memory Efficient

  • Streaming from S3 (no temp files)
  • Chunk-based processing
  • Minimal memory footprint

βœ… Idempotent Processing

  • DB-backed file log (transaction_file_log) prevents duplicate processing
  • UNIQUE constraint on object key with status machine (IN_PROGRESS β†’ COMPLETED | FAILED)
  • Failed files can be retried automatically on SQS redelivery

βœ… Error Handling

  • Late SQS acknowledgment β€” only on success; failures redeliver automatically
  • Visibility heartbeat keeps messages invisible during long-running jobs
  • Configurable skip policy (default: unlimited)
  • DML error logging scoped per file via ORA_ERR_TAG$
  • Fallback individual inserts with exponential backoff on lock errors
  • Job status verified before marking complete

βœ… Monitoring

  • Job execution statistics via TransactionJobListener
  • Read/Write/Skip counters
  • Processing time tracking
  • Rolling log files (50MB/file, 30-day history, 1GB cap)
  • AWS SDK log noise suppressed (WARN level)

βœ… Scalability

  • Horizontal scaling (multiple instances with DB-level idempotency)
  • Configurable chunk size
  • Java 21 Virtual Threads enabled globally
  • Database connection pooling

πŸ“Š Performance

Metric Value
Throughput 10,000-50,000 records/min
Memory Usage ~50-100MB base + chunks
Chunk Size 1000 (configurable)
Skip Limit Integer.MAX_VALUE (configurable)

πŸ”§ AWS Setup

Required AWS Resources

  1. S3 Bucket - for transaction file storage
  2. SQS Queue - for event notifications
  3. IAM User/Role - with S3 read and SQS permissions

Quick Setup Commands

# Create S3 bucket
aws s3 mb s3://your-transaction-bucket --region ap-south-1

# Create SQS queue
aws sqs create-queue --queue-name transaction-file-queue

# Configure S3 β†’ SQS notification
# (See detailed steps in AWS_SETUP_GUIDE.md)

πŸ‘‰ Complete guide: See AWS_SETUP_GUIDE.md


πŸ“š Documentation

Document Description
INDEX.md πŸ“– Complete project overview and index
QUICKSTART.md ⚑ Get running in 10 minutes
SETUP.md πŸ› οΈ Detailed setup and deployment guide
AWS_SETUP_GUIDE.md ☁️ Step-by-step AWS configuration
ARCHITECTURE.md πŸ—οΈ Technical architecture and design
PROJECT_SUMMARY.md πŸ“‹ Complete feature list and specs
JDBCTEMPLATE_IMPLEMENTATION.md πŸ”§ JdbcTemplate batch operations guide

πŸ§ͺ Testing

Run Unit Tests

mvn test

Manual Testing

# 1. Upload sample file
aws s3 cp sample-data/transactions.txt s3://your-bucket/

# 2. Watch logs for processing
Get-Content logs/transaction-batch.log -Tail 50 -Wait

# 3. Verify in database
sqlplus user/pass@host:1521/ORCL
SELECT COUNT(*) FROM transaction_process;

πŸ› Troubleshooting

Issue: Connection to Oracle fails

# Test connection
sqlplus username/password@host:1521/ORCL

Issue: No messages from SQS

  • Verify S3 event notification is configured
  • Check SQS queue policy allows S3
  • Test manually: aws sqs receive-message --queue-url YOUR_URL

Issue: Access Denied on S3

  • Verify IAM credentials have S3 read permissions
  • Test: aws s3 ls s3://your-bucket

πŸ‘‰ More solutions in SETUP.md troubleshooting section


πŸ“ˆ Monitoring

Application Logs

INFO - Received SQS message
INFO - Processing S3 event: bucket=my-bucket, key=transactions.txt
INFO - === Starting Transaction Processing Job ===
INFO - Batch write completed: 1000 successful, 0 skipped
INFO - === Transaction Processing Job Completed ===
INFO - Job Status: COMPLETED
INFO - Records Read: 10000
INFO - Records Written: 10000
INFO - Duration: 45 seconds

Key Metrics to Monitor

  • Job execution time
  • Records processed per minute
  • Skip/error rate
  • SQS message processing time
  • Database connection pool usage

πŸ” Security

Best Practices Implemented

βœ… No hardcoded credentials βœ… Environment variable support βœ… .gitignore for sensitive files βœ… Connection pooling with timeouts

Recommended for Production

  • Use AWS IAM roles (instead of access keys)
  • Store credentials in AWS Secrets Manager
  • Enable SSL/TLS for Oracle connections
  • Regular credential rotation
  • Enable CloudTrail for audit logging

πŸ“¦ Project Structure

transaction-batch-process/
β”œβ”€β”€ src/main/java/com/transaction/batch/
β”‚   β”œβ”€β”€ TransactionBatchProcessApplication.java    # Main app
β”‚   β”œβ”€β”€ config/           # Batch, AWS, app config + reader/processor/writer/listeners
β”‚   β”œβ”€β”€ model/            # Java records (TransactionRecord, TransactionProcess, S3EventNotification, ProcessingOutcome)
β”‚   └── service/          # SqsListenerService, S3Service, BatchJobService, FileProcessingLogService
β”œβ”€β”€ src/main/resources/
β”‚   β”œβ”€β”€ application.yml   # Configuration
β”‚   β”œβ”€β”€ schema.sql        # Database DDL (applied manually)
β”‚   └── logback-spring.xml # Rolling file appender + log levels
β”œβ”€β”€ sample-data/
β”‚   └── transactions.txt  # Sample file
└── docs/                 # Documentation files

πŸ› οΈ Technology Stack

  • Spring Boot 3.4.0 - Application framework
  • Spring Batch - Batch processing
  • JdbcTemplate - Database access (no JPA/Spring Data)
  • AWS SDK 2.29.0 - S3 and SQS integration
  • Oracle JDBC 23.5.0 - Database driver
  • HikariCP - Connection pooling
  • Lombok - Code simplification
  • Jackson - JSON processing

πŸš€ Deployment

Local Development

mvn spring-boot:run

Production JAR

mvn clean package -DskipTests
java -jar target/transaction-batch-process-1.0.0.jar

Docker (Optional)

docker build -t transaction-batch-process .
docker run -p 8080:8080 transaction-batch-process

Windows Service

See SETUP.md for systemd/Windows Service configuration


πŸŽ“ Next Steps

For Development

  1. βœ… Review code structure
  2. βœ… Test with sample data
  3. ⬜ Customize processor for business rules
  4. ⬜ Add additional validation
  5. ⬜ Implement custom monitoring

For Production

  1. ⬜ Configure production database
  2. ⬜ Set up production AWS resources
  3. ⬜ Use IAM roles for authentication
  4. ⬜ Configure CloudWatch monitoring
  5. ⬜ Set up log aggregation
  6. ⬜ Deploy as system service

πŸ“ž Support

For issues or questions:

  1. Check application logs
  2. Review documentation files
  3. Verify AWS and database connectivity
  4. Check docs/SETUP.md for troubleshooting

πŸ“„ License

[Your License Here]


πŸ™ Acknowledgments

Built with:

  • Spring Framework
  • AWS SDK for Java
  • Oracle Database
  • Maven

⭐ Quick Links

Ready to process transactions at scale! πŸš€

About

Spring batch processing in single process

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages