Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

One deployment of a service handles both interactive API traffic with a 100 ms p99 target and large nightly batch imports. The batch team wants Parallel GC and large thread pools, the API team wants low pauses. How do you resolve this?

The two workloads want opposite trade-offs: the batch import wants maximum throughput and tolerates long pauses, while the API needs short, predictable pauses for its 100 ms p99. One JVM configuration will serve one of them badly, so the best answer is to run them as separate deployments of the same code with different settings, or to move the batch into a separate job. If they must share a process, we isolate them with bulkheads, define and measure an SLO for each workload separately, and weigh the cost of an extra deployment against the cost of missed API latency.

Why this question is asked

This scenario is less about garbage collectors than about recognising a conflict of goals. Both teams are right about what their workload needs, and the mistake would be to pick a winner or a compromise setting that disappoints both. Interviewers use it to see whether we can turn a tuning argument into an architecture decision backed by numbers. In this answer, we will look at what each workload really wants, why a single configuration cannot satisfy both, then go through the options from cleanest to most constrained, and finish with how to make the call.

1What Each Workload Wants

The interactive API has a latency goal: 99 percent of requests must finish within 100 ms. Anything that stops request threads for tens of milliseconds eats directly into that budget. So the API team wants a collector with short pauses, such as G1 with a modest pause goal or generational ZGC, whose pauses are usually well under a millisecond, and moderate thread pools so the CPU is not oversubscribed.

The nightly batch import has a throughput goal: process millions of rows before morning. It does not care whether one transaction waits 300 ms for a GC pause as long as the total finishes on time. So the batch team wants Parallel GC, which stops the world for every collection but spends the least CPU overall on GC, and large thread pools to keep every core and the database busy.

2Why One Configuration Serves One Side Badly

Both requests are reasonable, but they pull in opposite directions. With Parallel GC, young and full collections stop all threads, and on a large heap a full collection can take hundreds of milliseconds or seconds. During a batch run that is fine, but every API request that arrives during a pause waits for it, so the API's p99 breaks.

The thread pools conflict too. A batch pool of 64 threads on an 8-core container saturates the CPU and the database connection pool. API requests then queue for CPU time and for connections, and latency rises even without any GC pause. Choosing G1 or ZGC for everyone protects the API but costs the batch some throughput, because low-pause collectors spend more CPU on concurrent work. And the batch's big pools still hurt the API whatever collector we pick.

Two workloads, two sets of needs
ConcernInteractive APINightly batch
Goalp99 under 100 msfinish N rows before 06:00
CollectorG1 or ZGC, short pausesParallel GC, best throughput
Threadsmoderate, bounded queueslarge pools, keep cores busy
Databaseshort queries, small poolbulk inserts, big batches
Tolerateslower peak throughputlong pauses
Every row pulls in a different direction, which is the sign that they should not share a JVM.

3Option 1: Separate Deployments of the Same Code

The cleanest solution keeps one codebase and one build, but runs two deployments with different configurations. In Kubernetes that means two Deployments from the same image: one receives API traffic, the other runs the import and receives no user traffic.

Properties
# api deployment
JAVA_TOOL_OPTIONS="-XX:+UseZGC -Xmx4g"
SPRING_PROFILES_ACTIVE=api # web endpoints on, import scheduler off
server.tomcat.threads.max=200
spring.datasource.hikari.maximum-pool-size=20
# batch deployment (same image)
JAVA_TOOL_OPTIONS="-XX:+UseParallelGC -Xmx12g"
SPRING_PROFILES_ACTIVE=batch # import job on, not behind the load balancer
import.worker-threads=48
spring.datasource.hikari.maximum-pool-size=40

Each team now tunes its own deployment without affecting the other. The API keeps its short pauses during the import, and the batch gets its throughput collector and big pools. Even better, the batch deployment can be scaled to zero during the day. The remaining shared resource is the database, so the batch pool size and write rate should be agreed with whoever owns the database, otherwise the import can still slow down API queries.

4Option 2: Move the Batch Into a Separate Job

If the import is genuinely a run-to-completion task, it fits a separate job better than a long-running service: a Kubernetes Job or CronJob, or a Spring Batch application started by a scheduler. The job starts with its own JVM settings, runs the import, records its result and exits. This makes resource use explicit, gives the import its own logs and retry policy, and keeps the API deployment free of batch code paths at runtime.

The price is a little more operational setup, such as a job definition, monitoring of job success and handling of partial failures, but most organisations already have this machinery.

5Option 3: Bulkheads Inside One Process

Sometimes splitting is not possible soon, for example because of a licence tied to the deployment or a shared in-memory state that would take months to untangle. Then we isolate the workloads inside the process, the way a ship's bulkheads keep one flooded compartment from sinking the whole ship. The batch gets its own small, bounded executor and its own connection pool, its rate is limited, and the collector is chosen for the API because the API's goal is the stricter one.

Java
@Bean ThreadPoolTaskExecutor importExecutor() {
var ex = new ThreadPoolTaskExecutor();
ex.setCorePoolSize(4); // capped well below the core count
ex.setMaxPoolSize(4);
ex.setQueueCapacity(1_000); // bounded: backpressure, not unbounded growth
return ex;
}
// separate HikariDataSource for import with maximumPoolSize = 5
// API keeps its own pool; GC: G1 or ZGC for the whole JVM

Bulkheads limit the damage but do not remove the conflict. The batch is slower than it would be on its own, and both still share heap, GC and CPU. So this is a mitigation while we plan the split, not the end state.

6Measuring Each Workload and Making the Call

Whatever we choose, we define an SLO for each workload and measure it independently. The API SLO is p99 latency under 100 ms, measured at the edge, with an alert when it is at risk. The batch SLO is completion time and throughput, for example 20 million rows finished by 06:00. With both visible, we can see whether a change helps one side at the other's expense.

Then we compare costs. A second deployment might cost a few hundred to a few thousand dollars a month in compute, much of which can be avoided by running the batch only at night. Missing the API latency target has a cost too: timeouts, retries that add load, lost conversions and support tickets. In most organisations the extra deployment is far cheaper, and it also removes a recurring argument between two teams.

Step throughResolving the conflict
  1. Write down each SLOAPI p99 100 ms, batch done by 06:00
  2. Can the batch run as its own deployment or job?
    YesSplit: same code, separate settingsNoUse bulkheads in one process
  3. Measure both SLOs independentlydashboards and alerts per workload
  4. Compare costsextra compute vs missed latency
  5. Revisitplan the split if bulkheads were a stopgap

5 steps in order. Play them, or step through them one at a time.

7Follow-up questions

Could we just schedule the batch when API traffic is lowest?

It helps, and it is worth doing anyway, but it rarely solves the problem. Many services have users in several time zones, and a long import that overruns into the morning peak causes exactly the incident we wanted to avoid. Scheduling reduces the overlap; separation removes it.

Would ZGC for both be a reasonable compromise?

If we must share one JVM, choosing a low-pause collector protects the stricter goal, and generational ZGC handles high allocation rates well. The batch loses some throughput to concurrent GC work, but that is usually a smaller loss than the API missing its target. The thread pool conflict still needs bulkheads.

How do you get the two teams to agree?

By moving the discussion from settings to goals. Once both SLOs are written down and measured, the data shows that one configuration fails one of them, and the separation argument becomes a cost comparison rather than a preference.

8Conclusion

In this answer, we saw that an interactive API with a 100 ms p99 target and a nightly batch import want opposite things: short pauses and bounded pools on one side, Parallel GC and big pools on the other, so one JVM configuration serves one of them badly. The clean solution is separate deployments of the same code or a separate job for the batch. If they must share a process, bulkheads such as separate executors and connection pools limit the damage. In every case we define and measure an SLO per workload and compare the cost of extra deployments with the cost of missed API latency.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by saying both teams are right about their own workload, and that is the problem. The API needs short, predictable pauses and bounded pools to hold a 100 ms p99, while the batch wants Parallel GC, which has the best throughput but long stop-the-world pauses, and big thread pools that saturate CPU and database connections.

Then, if they want more

Whatever single configuration we choose, one of them loses: Parallel GC pauses break the API's tail latency, and a low-pause collector costs the batch throughput, and the big batch pools hurt API latency either way.

So my first choice is to separate them: the same code and image, but two deployments with different JVM flags, Spring profiles and pool sizes, with the batch deployment not behind the load balancer and ideally scaled down outside the import window.

If the import is really a run-to-completion task, I would make it a Kubernetes Job or a Spring Batch job. If they truly must share a process for now, I would use bulkheads: a small bounded executor and a separate connection pool for the import, rate limiting, and a low-pause collector because the API has the stricter goal.

Either way, each workload gets its own SLO and its own dashboard, and I would compare the cost of the extra deployment, usually modest, with the cost of missing the API target.

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.
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 "One deployment of a service handles both interactive API traffic with a 100 ms p99...": https://scrivio-interview-library.netlify.app/java/java-performance/307e98ec17/