Scrivio Interview library
ScenarioAdvanced6 min read · updated 13 November 2026

A document-conversion service runs on 20 autoscaled pods. Each pod accepts jobs over HTTP and keeps job progress in memory while converting files for up to 10 minutes. After autoscaling was enabled, about 3 percent of jobs vanish and users wait forever.

Why are jobs lost, and how would you redesign the service so pods can come and go freely?

Jobs vanish because autoscaling, deploys and node maintenance terminate pods while conversions run, and the job and its progress exist only in that pod's memory. The redesign makes the job durable: the API writes a job record and a queue message and returns a job id, workers pull jobs and acknowledge only after the result is stored, conversions are idempotent and checkpoint large files to object storage, and pods shut down gracefully while autoscaling follows queue depth.

Why this question is asked

Autoscaling changes an assumption that many services rely on without saying so: that a pod lives as long as the work it started. Once pods come and go every few minutes, any work held only in memory is at risk. Interviewers ask this because the fix is a classic pattern, a durable job queue with idempotent workers, and because the details, such as when to acknowledge and what to scale on, decide whether it really works. In this answer, we will explain why 3 percent of jobs disappear, then redesign the service step by step: durable job records, pull-based workers, idempotency and checkpoints, graceful shutdown, and the right autoscaling signal.

1Why Jobs Disappear

Today a pod accepts a job over HTTP, starts converting, and keeps the job's progress in a map in its memory. The client later asks the same service for the status. That works as long as the pod lives for the whole conversion, up to 10 minutes.

With autoscaling, pods are terminated for many reasons: scale-in when load drops, rolling deploys, node upgrades and spot instance reclaims. Kubernetes sends SIGTERM and, after the termination grace period, 30 seconds by default, SIGKILL. A 10-minute conversion cannot finish in 30 seconds, so the pod dies mid-job, and with it the only record that the job existed. The client polls for a status that no pod knows about and waits forever. About 3 percent of jobs happen to be running on a pod at the moment it is removed.

2The Redesign at a Glance

The core change is to separate accepting a job from doing it, and to put the job into durable storage in between. The API only validates the request, stores the input file in object storage such as S3, writes a job record to PostgreSQL with status QUEUED, publishes a message to a durable queue such as SQS, RabbitMQ or Kafka, and returns 202 Accepted with a job id. Workers pull from the queue, convert, store the output, update the record, and only then acknowledge the message.

Step throughDurable job pipeline
  1. API podsvalidate, store input in S3, insert job row, enqueue, return job id
  2. Job store (PostgreSQL)status, attempts, checkpoint, output location
  3. Durable queueone message per job, redelivered if not acknowledged
  4. Worker podspull, convert, checkpoint, store output, then acknowledge
  5. Object storage (S3)inputs, intermediate chunks, results

5 layers, from the top down. Step through them one at a time.

Notice that no pod owns a job any more. The job record and the queue message outlive every pod, so a pod can disappear at any moment without the job being lost.

3Acknowledge Only After the Result Is Stored

The order of the last steps decides whether a job can still be lost. If a worker acknowledges the message when it starts, and then dies, the queue thinks the job is done. So the worker acknowledges only after the output is in object storage and the job row says DONE. If the worker dies before that, the message becomes visible again after its timeout (the visibility timeout in SQS, an unacknowledged delivery in RabbitMQ) and another worker picks it up.

For a 10-minute job, the visibility timeout must be longer than the job, or the worker must extend it while working, otherwise a slow but healthy job is handed to a second worker.

Java
void handle(JobMessage m) {
Job job = jobs.find(m.jobId());
if (job.status() == DONE) { ack(m); return; } // redelivered after success: nothing to do
jobs.markRunning(job.id(), workerId);
Path out = converter.convert(job, checkpoints); // resumes from the last checkpoint if any
String key = "results/" + job.id(); // same key on every attempt
s3.put(key, out);
jobs.markDone(job.id(), key);
ack(m); // only now is the job safe to forget
}

4Idempotency and Checkpoints

Redelivery means a job may run twice: for example, the worker stored the result but died before acknowledging. The conversion must therefore be idempotent, meaning running it again gives the same outcome with no harm. Writing the output to a key derived from the job id, and checking the job status first, makes a rerun either a no-op or a harmless overwrite of the same file.

Restarting a 10-minute conversion from zero after every pod loss is wasteful. Long jobs should checkpoint: after each page range or segment, the worker writes the finished piece to object storage and records the checkpoint in the job row. A new worker reads the checkpoint and continues from there, so a pod loss costs a minute of work instead of ten.

5Graceful Shutdown and Scaling on Queue Depth

Workers should stop cleanly when told to. On SIGTERM, a worker stops pulling new messages, lets a job that is nearly done finish, and for a long job writes a checkpoint and releases the message (or simply stops extending its visibility) so another worker resumes it. In Spring Boot, server.shutdown=graceful plus a lifecycle timeout covers the HTTP side, and the worker loop needs its own stop flag. We set terminationGracePeriodSeconds long enough for a checkpoint, perhaps 60 to 120 seconds, rather than for a full job.

Finally, CPU is a poor signal for autoscaling here. When the queue is long, every worker is busy, and CPU looks the same whether 5 or 500 jobs are waiting. Scaling on queue depth, or better on estimated wait time, with a tool such as KEDA, adds workers when work piles up and removes them only when the queue is short.

Step throughA pod is removed mid-job
KubernetesWorker AQueueWorker B
SIGTERM
stop pulling, write checkpoint at page 400
release message, not acknowledged
pod removed after grace period
pull
same job message
resume from page 400, store result
acknowledge

8 messages in order. Play them, or step through them one at a time.

6Telling Clients What Happened

Clients no longer depend on reaching the pod that started their job. They poll GET /jobs/{id}, which any API pod answers from the job table, or they receive a webhook or a server-sent event when the job finishes. The job row also gives operations visibility: how many jobs are queued, running, failed, and how often each job was attempted.

7Follow-up questions

How do you stop a poison file from being retried forever?

Count attempts. The job row and the queue both track deliveries, and after a limit such as three attempts the message goes to a dead-letter queue and the job is marked FAILED with the error, so the user sees a clear failure instead of waiting. We alert on the dead-letter queue, keep the input for analysis, and give each conversion a hard time limit and resource limits so a file that hangs the converter or uses all memory is killed rather than taking the worker with it.

Why not just increase the termination grace period to 10 minutes?

It would help with scale-in, but not with node failures, out-of-memory kills or spot reclaims, which give no grace at all. It also slows deploys and node maintenance badly. Durable jobs handle every kind of pod loss, and the grace period only needs to cover writing a checkpoint.

Should the API pods also be the workers?

They can share an image, but separating them is usually better: API pods scale on request rate and stay small, while workers scale on queue depth and get the CPU and memory conversion needs. A long conversion then never competes with a status request for the same pod.

8Conclusion

In this answer, we saw that jobs vanished because autoscaling and other pod terminations removed the only copy of each job's state. Redesigning around a durable job record, a queue with acknowledgement after the result is stored, idempotent and checkpointed conversions in object storage, graceful shutdown and scaling on queue depth lets pods come and go freely without losing work.

What to say in the interviewAbout 80 seconds aloud

Open with

The jobs are lost because pods are now terminated during work: scale-in, deploys and node maintenance send SIGTERM, the default grace period is 30 seconds, and a 10-minute conversion that keeps its progress only in memory dies with the pod, so the client polls for a job nobody remembers.

Then, if they want more

I would separate accepting a job from doing it. The API stores the input in S3, writes a job row with status QUEUED, publishes a message to a durable queue and returns a job id that clients poll or get a webhook for.

Workers pull messages, convert, store the result under a key derived from the job id, mark the job done, and only then acknowledge, so if a worker dies the message is redelivered. Because of that, the conversion must be idempotent, and long jobs write checkpoints to object storage so another worker resumes rather than restarts.

On SIGTERM a worker stops pulling and checkpoints. I would scale workers on queue depth with something like KEDA instead of CPU, and send jobs that fail three times to a dead-letter queue so a poison file is not retried forever.

About this answer

Last updated
13 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 official documentation for the version you use. 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 "Why are jobs lost, and how would you redesign the service so pods can come and go freely?": https://scrivio-interview-library.netlify.app/architecture/sd-fundamentals/1229e56b34/