惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
有赞技术团队
有赞技术团队
G
Google Developers Blog
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
罗磊的独立博客
T
Tailwind CSS Blog
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
博客园 - Franky
B
Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building Distributed Data Processing with Spring Batch 6 ...
Praveen Yadav · 2026-06-25 · via DEV Community

Praveen Yadav

When people first use Spring Batch, they usually start with a simple single-threaded job. That works for small datasets, but once data volume grows, throughput becomes the bottleneck.

In this sample project, I implemented a partitioned, multi-threaded Spring Batch pipeline to process sales records in parallel using a master/worker step model.

👉 Code repo: github.com/ykpraveen/spring-batch-sample

Spring Batch

At its core, Spring Batch is built around a few key abstractions:

  • Job: a complete batch workflow
  • Step: one phase of a job
  • ItemReader / ItemProcessor / ItemWriter: read-transform-write pipeline
  • Chunk processing: process N items in one transaction (chunkSize) ### Why chunking matters

In chunk-oriented steps, Spring Batch reads and processes items until the chunk size is reached, then writes and commits in one transaction.

So with chunk(500):

  • 500 items are read/processed/written
  • one commit happens per chunk
  • failures can be retried at chunk boundaries

This gives a good balance between:

  • too-small chunks (high transaction overhead)
  • too-large chunks (long transactions, higher rollback cost)

How Spring Batch scales

Spring Batch offers multiple scaling patterns:

  1. Multi-threaded Step: one step, concurrent chunk processing
  2. Partitioning: split input domain into partitions, each handled by a worker step
  3. Remote Chunking / Remote Partitioning: distribute work across processes/nodes

This project uses partitioning + thread pool execution (local distributed-style parallelism).

How this project applies those concepts

Repository: spring-batch-sample

The architecture is:

  • A master step creates partitions (data ranges)
  • A worker step executes each partition
  • A ThreadPoolTaskExecutor runs workers concurrently

Key classes (see src/main/java in repo):

  • BatchConfiguration → job/step orchestration
  • SalesDataPartitioner → partition boundary logic
  • SalesDataProcessor → business transformation logic

Code area: src/main/java

Performance tuning used here

The sample uses:

  • gridSize: 8 (number of partitions)
  • Thread pool: corePoolSize=4, maxPoolSize=8
  • chunk size: 500
  • Sample input: 5000 records

Interpretation

  • gridSize controls parallel work units.
  • Thread pool size controls actual concurrent execution.
  • Effective throughput depends on DB I/O, CPU, and item processing complexity.
  • Increasing partitions beyond available threads can still help load balancing, but with diminishing returns.

Database + metadata angle

Spring Batch is not just a processing framework; it is also a stateful execution framework.

It tracks job/step execution state in metadata, enabling:

  • restartability
  • execution history
  • failure diagnostics

In this sample, PostgreSQL stores both:

  • domain tables (sales_data, processed_data, processing_statistics)
  • batch execution context/metadata managed by Spring Batch

That combination is what makes batch jobs operationally reliable in real systems.


Run locally

1) Start PostgreSQL

docker compose up -d

2) Build and run the app

mvn clean install
mvn spring-boot:run

3) Trigger the batch job

curl -X POST http://localhost:8080/api/batch/start

4) Stop PostgreSQL

docker compose down


Why this pattern is useful in real projects

This design is a strong baseline for:

  • ETL and data migration
  • order/payment reconciliation
  • large-volume reporting prep
  • scheduled backend data shaping

You get:

  • clear separation of orchestration vs business logic
  • predictable transactional boundaries
  • scalable parallel execution
  • operational observability through batch metadata

Next extensions

If you want to evolve this sample toward production-grade scale:

  1. Add retry/skip policies for fault tolerance.
  2. Export job metrics (Micrometer + Prometheus/Grafana).
  3. Make partition strategy adaptive to dataset size.
  4. Move to remote partitioning for multi-node execution.

If you’re learning Spring Batch or designing high-throughput processing pipelines, this pattern is a solid starting point: simple enough to understand, realistic enough to extend.