Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What is stored in the Spring Batch job repository, and what problems do you see if you run batch jobs with an in-memory or resourceless repository in production?

The job repository stores job instances, job executions with their identifying parameters, step executions with their counts, and the execution contexts of both, in tables such as BATCH_JOB_INSTANCE, BATCH_JOB_EXECUTION, BATCH_JOB_EXECUTION_PARAMS, BATCH_STEP_EXECUTION and the two context tables. That metadata is what makes restart possible, stops a completed instance from running twice and keeps a history, so with an in-memory or resourceless repository, a process that ends takes all of it away. Spring Batch 5 removed the old map-based repository, 5.2 added a ResourcelessJobRepository for jobs that need no restart or history, Batch 6 changed the defaults, and in Boot the schema is created according to spring.batch.jdbc.initialize-schema.

Why this question is asked

The job repository is easy to ignore, because Spring Boot sets it up for us and it rarely appears in our code. But it is the part of Spring Batch that remembers: which days were processed, which runs failed, and where a failed step stopped. Teams that run batch jobs without a persistent repository, often to avoid creating tables, usually find out what it was doing on the first night a job fails or runs twice. Interviewers ask this to check that we understand what the metadata is for. In this answer, we will look at what each table holds, follow how the data is used for restart and for preventing duplicate runs, see what goes wrong without it, and go through the version history and schema settings.

1What the Job Repository Is

The JobRepository is the Spring Batch component that saves and loads the state of jobs. When a job is launched, it creates the records for the run; while the job runs, it updates them at every chunk commit; and when we launch or restart a job, it reads them to decide what to do. In production it is normally backed by a relational database, using a set of tables whose scripts ship with Spring Batch for each supported database.

2The Tables and What They Hold

The schema has six main tables, plus sequences or identity columns for ids.

Job repository tables
TableOne row perHolds
BATCH_JOB_INSTANCEjob name + identifying parametersjob name, a key hashed from the parameters
BATCH_JOB_EXECUTIONattempt at an instancestatus, exit code, start, end, last updated
BATCH_JOB_EXECUTION_PARAMSparameter of an executionname, type, value, identifying or not
BATCH_JOB_EXECUTION_CONTEXTjob executionserialised job ExecutionContext
BATCH_STEP_EXECUTIONstep attemptstatus, read, write, filter, skip, commit, rollback counts
BATCH_STEP_EXECUTION_CONTEXTstep executionserialised step ExecutionContext, e.g. reader position

Notice the key in BATCH_JOB_INSTANCE. Spring Batch computes it from the identifying parameters, and the table has a unique constraint on the job name and that key. That constraint is what guarantees that import-transactions for date=2026-11-03 exists only once, even if two launchers try to create it at the same moment.

3How the Metadata Is Used

The tables serve three purposes. The first is restart. When a step fails, its last committed ExecutionContext, for example a reader's line count, is in BATCH_STEP_EXECUTION_CONTEXT. A restart creates a new job execution of the same instance, skips steps whose last execution is COMPLETED, and opens the failed step's reader with the saved context so it resumes after the last committed chunk.

The second is protection against duplicate runs. Before launching, Spring Batch looks up the instance for the given parameters. If its last execution completed, it throws JobInstanceAlreadyCompleteException; if one is still running, it throws JobExecutionAlreadyRunningException. The third is history: operators and auditors can see every run, how long it took, how many items it read and wrote, and why it failed.

SQL
SELECT i.job_name, e.job_execution_id, e.status, s.step_name, s.read_count, s.write_count
FROM batch_job_instance i
JOIN batch_job_execution e ON e.job_instance_id = i.job_instance_id
JOIN batch_step_execution s ON s.job_execution_id = e.job_execution_id
WHERE i.job_name = 'importJob'
ORDER BY e.job_execution_id;
-- importJob | 501 | FAILED | loadStep | 600000 | 600000
-- importJob | 502 | COMPLETED | loadStep | 400000 | 400000 (resumed at 600,001)

4What Goes Wrong Without a Persistent Repository

An in-memory repository, such as one on an embedded H2 database, or a resourceless one, keeps the metadata only while the process lives. For a long-running service that is barely a problem, but batch jobs usually run as short-lived processes, a pod or a scheduled command that exits when the job ends. So every launch starts with an empty repository.

Persistent versus in-memory repository
SituationPersistent databaseIn-memory or resourceless
Job fails at row 600,000, then relaunchedresumes at 600,001starts again at row 1
Same date launched twice by mistakerefused: already completeruns again: duplicates
Two pods launch the same job at onceunique key stops the secondboth run
Auditor asks for last month's runsfull historynothing
Operator checks why a run failedstatus, counts, exit messageonly the logs, if kept

The second row is the most dangerous one. Without the repository, nothing remembers that the date was processed, so a scheduler retry or an operator's re-launch silently processes the same data again. For a job that posts payments, that is a serious incident. So an in-memory or resourceless repository is only acceptable for jobs that are naturally idempotent, need no restart, and have no audit requirement, such as a cleanup of temporary files.

5Version History and Schema Settings

The repository options have changed across versions, so it helps to know the history. Spring Batch 4 had a map-based repository that held everything in Java maps; it was deprecated and then removed in Spring Batch 5, which recommended an embedded database such as H2 for in-memory use. Spring Batch 5.2 added a ResourcelessJobRepository, which stores nothing at all, for jobs that genuinely need no metadata. Spring Batch 6 changed the defaults again, making it more explicit whether a JDBC repository is configured, so check your version's documentation for what you get when you do not configure one.

With Spring Boot and a JDBC repository, the schema is created according to spring.batch.jdbc.initialize-schema. The default, embedded, creates it only for embedded databases such as H2; always creates it for any database at startup; never leaves it to us. In production, the usual practice is never, with the Spring Batch schema script applied through the same migration tool as the rest of the database, such as Flyway or Liquibase, so it is versioned and reviewed.

Properties
# development with H2: tables created automatically
spring.batch.jdbc.initialize-schema=embedded
# production: tables created by Flyway from schema-postgresql.sql
spring.batch.jdbc.initialize-schema=never

6Follow-up questions

Can the job repository live in the same database as the business data?

Yes, and it is often a good idea. When the repository and the business tables share a database and transaction manager, the chunk's writes and the saved step state commit in the same transaction, so the restart position always matches the data. A separate repository database works too, but then the two commits are separate and a crash between them can leave them out of step.

Why is the ExecutionContext stored in separate tables?

Because it can be larger than the other columns and is serialised, usually as JSON or another format depending on the configured serializer. Keeping it in its own tables with a short and a long column keeps the execution tables narrow. The rule of thumb is to keep contexts small: positions and counts, not data.

Does the repository need maintenance?

Yes. The tables grow with every run, and for frequent jobs they can reach millions of rows. Indexes on the foreign keys and a retention process that archives and purges old executions keep launches fast.

7Conclusion

In this answer, we saw that the job repository stores job instances, job executions and their parameters, step executions with their counts, and the execution contexts that hold restart state. That metadata enables restart, prevents duplicate runs of completed instances, and records history, so an in-memory or resourceless repository loses all three when the process ends. Spring Batch 5 removed the map-based repository, 5.2 added a ResourcelessJobRepository for jobs that need no metadata, Batch 6 changed the defaults, and Boot creates the schema according to spring.batch.jdbc.initialize-schema.

What to say in the interviewAbout 90 seconds aloud

Open with

The job repository is where Spring Batch keeps its memory. BATCH_JOB_INSTANCE has one row per job name and identifying parameters, with a unique key, so each logical run exists once.

Then, if they want more

BATCH_JOB_EXECUTION has one row per attempt with status, exit code and times, and BATCH_JOB_EXECUTION_PARAMS holds the parameters. BATCH_STEP_EXECUTION has the per-step counts, like read, write, skip and commit counts, and the two context tables hold the serialised ExecutionContexts, which include things like a reader's position. This data does three jobs.

It enables restart, because a failed step resumes from its saved context. It prevents duplicate runs, because launching a completed instance throws JobInstanceAlreadyCompleteException, and a running one is detected too. And it gives operators and auditors a history.

If you run with an in-memory or resourceless repository, and batch processes are usually short-lived, every launch starts empty: a failed job restarts from the beginning, the same date can be processed twice, and there is no history. That is only acceptable for idempotent jobs that need no restart or audit.

On versions, the map-based repository was removed in Spring Batch 5, 5.2 added the ResourcelessJobRepository, and Batch 6 changed the defaults, so I check the version. In Boot the schema is controlled by spring.batch.jdbc.initialize-schema, and in production I set it to never and apply the schema through Flyway.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Batch reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is stored in the Spring Batch job repository, and what problems do you see if you...": https://scrivio-interview-library.netlify.app/spring-boot/spring-batch/19c657e79e/