Skip to content
tezvyn:

Resilient stateful batch on Spot Instances

Source: interviewHardHow cards are made

Summary

fault tolerance on interruptible compute.

Key points

externalize state and checkpoint to durable storage, react to interruption and rebalance notices to drain gracefully, diversify instance pools.

What's really being asked

This probes whether you can engineer resilience around compute that can disappear with little warning, turning a cheap but volatile resource into a dependable platform for stateful work.

The full answer

The core principle is to externalize state so no instance is irreplaceable. Periodically checkpoint progress, such as the last processed offset or intermediate results, to durable storage like S3 or a managed database, so a replacement instance resumes from the checkpoint instead of restarting from zero. React to lifecycle signals: AWS emits a Spot interruption notice roughly two minutes before reclamation and a rebalance recommendation earlier when risk rises, so a handler should catch these, flush a final checkpoint, deregister from any load balancer or queue, and exit cleanly. Diversify the capacity pool across many instance types, sizes, and Availability Zones so a shortage in one pool does not reclaim everything at once, and run a baseline on On-Demand or reservations so the job always makes progress. Design each unit of work to be idempotent and chunked, so reprocessing after an interruption produces no duplicates or corruption. Use a managed orchestrator like Spot Fleet, EC2 Auto Scaling with capacity-optimized allocation, or AWS Batch to automate replacement.

The mistakes people make

Storing working state only in instance memory or local disk, which is lost on reclamation. Ignoring the interruption and rebalance notifications and letting work die mid-chunk. Picking a single instance type, concentrating interruption risk. Assuming the two-minute window is enough to finish a long task rather than just to checkpoint.

What usually comes next

How small should checkpoints be. How do you guarantee exactly-once effects. How do you fall back when Spot capacity is unavailable.

A concrete example

A genomics pipeline splits work into idempotent chunks, writes each completed chunk and a progress marker to S3, and runs on a diversified Spot Fleet. An interruption handler flushes the current chunk's checkpoint within the two-minute notice, and a replacement instance picks up from the last marker, so cost drops sharply with no lost results.

Interview question

What is the primary purpose of handling the Spot interruption notice in a stateful batch job?

  • a.To checkpoint progress and drain before the instance is reclaimedCorrect
  • b.To prevent the instance from ever being interrupted
  • c.To convert the instance to On-Demand automatically
  • d.To request a longer runtime from AWS
Why?

The roughly two-minute notice lets the job flush a final checkpoint and exit gracefully so a replacement can resume. It cannot extend runtime, convert the instance, or stop the reclamation from happening.

Just read this? Test yourself on what you have been reading.

Read the original → docs.aws.amazon.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on cloud — each one lists the topics its interview covers.

See open roles