Without Spot Instances, batch processing in the cloud costs 3–5 times more. Clients often overpay for on-demand resources that sit idle between tasks. As engineers, we have been using Spot and Preemptible Instances for over 5 years to reduce costs by 60–80% without compromising reliability. Below are specific methods, configurations, and proven solutions tested on dozens of projects.
Which tasks are most efficiently executed on Spot Instances?
Spot Instances are ideal for stateless batch tasks: CI/CD workers (each build isolated), image and video processing (transcoding, resizing), ML training with checkpoint-based approaches, parsing and ETL pipelines, rendering, antivirus scans, analytical queries. They are not suitable for stateful databases (risk of data loss), web servers without rapid replacement, or services with strict SLA lacking a DR strategy.
How does Spot Fleet reduce interruption probability?
The key to stability is a Spot Fleet with multiple instance types. If m5.xlarge is unavailable, the Fleet picks up m5a.xlarge or c4.xlarge. We use the capacityOptimized strategy — it selects pools with the greatest free capacity, lowering interruption probability. Example configuration:
{
"SpotFleetRequestConfig": {
"AllocationStrategy": "capacityOptimized",
"TargetCapacity": 10,
"LaunchTemplateConfigs": [
{
"LaunchTemplateSpecification": {"LaunchTemplateId": "lt-xxx", "Version": "1"},
"Overrides": [
{"InstanceType": "m5.xlarge", "WeightedCapacity": 1},
{"InstanceType": "m5a.xlarge", "WeightedCapacity": 1},
{"InstanceType": "m4.xlarge", "WeightedCapacity": 1},
{"InstanceType": "c5.xlarge", "WeightedCapacity": 1}
]
}
]
}
}
Why is checkpointing critical?
Spot Instances can be terminated at any moment. Without checkpointing, lost progress makes their cost savings meaningless. Implementing a state-saving mechanism allows tasks to restart from the last saved point, minimizing losses. In practice, this yields up to 95% effective runtime even under frequent interruptions.
How to properly handle the Spot Interruption Notice?
AWS sends a metadata event 2 minutes in advance (more in AWS documentation). The application should poll the endpoint and upon an interruption signal, save a checkpoint. The code below shows a Python implementation with graceful exit:
import requests
import signal
import sys
def check_spot_interruption():
"""Call every 5 seconds from the worker"""
try:
response = requests.get(
'http://169.254.169.254/latest/meta-data/spot/interruption-notice',
timeout=1
)
if response.status_code == 200:
return True # Interruption imminent
except requests.exceptions.RequestException:
pass
return False
class BatchWorker:
def process_task(self, task):
# Checkpoint every N items
for i, item in enumerate(task.items):
if i % 100 == 0 and check_spot_interruption():
self.save_checkpoint(task.id, i)
sys.exit(0) # Graceful exit, task will be restarted
self.process_item(item)
task.mark_complete()
Interruption handling steps:
- Poll the metadata endpoint every 5 seconds.
- Upon receiving the signal, save a checkpoint (e.g., in S3 or Redis).
- Graceful exit with code 0 so the queue (SQS) does not mark the task as failed.
You can also use AWS EventBridge for automation: event → Lambda → checkpoint saving, instance removal from pool, task return to queue.
What is Karpenter and how does it manage Spot nodes?
Karpenter (AWS) automatically selects the instance type (including Spot) and handles interruptions: upon receiving a notice, it cordons and drains the node, rescheduling pods. Example Provisioner:
apiVersion: karpenter.sh/v1alpha5
kind: Provisioner
metadata:
name: batch-workers
spec:
requirements:
- key: "karpenter.sh/capacity-type"
operator: In
values: ["spot", "on-demand"]
- key: "node.kubernetes.io/instance-type"
operator: In
values: ["m5.xlarge", "m5a.xlarge", "m4.xlarge", "c5.xlarge"]
taints:
- key: batch
effect: NoSchedule
consolidation:
enabled: true
Strategy comparison: Karpenter compared to manual Spot Fleet management reduces interruption reaction time by half due to automatic cordon and drain. Spot Fleet is simple but requires manual template management. Karpenter offers dynamic scaling and automatic recovery but is more complex to configure. Both provide 60–80% savings.
| Strategy | Management | Interruption Handling | Configuration Complexity |
|---|---|---|---|
| Spot Fleet | Manual (Launch Templates) | Manual (application) | Low |
| Karpenter | Automatic (Provisioner) | Automatic (cordon/drain) | Medium |
GCP Preemptible / Spot VMs: nuances
GCP Preemptible: max 24-hour lifetime, 30-second notice. Spot VMs — no 24-hour limit, only based on availability. Creation via gcloud:
gcloud compute instances create batch-worker \
--machine-type=n2-standard-4 \
--provisioning-model=SPOT \
--instance-termination-action=STOP \
--zone=us-central1-a
Checkpointing is also applied here, but with a shorter notice (30 seconds). Implementation is similar to AWS, but polling the GCP metadata server.
What's included in turnkey setup?
- Audit of current workloads and selection of suitable ones
- Design of Spot Fleet / Provisioner with multiple instance types
- Implementation of checkpointing and interruption handling (Python/Go/Java code)
- Integration with EventBridge, Lambda, queues (SQS, RabbitMQ)
- Monitoring setup (CloudWatch, Prometheus) and alerts
- Documentation and team training
- Testing with interruption simulation
- Post-launch support for 1 month
Estimated timelines
| Stage | Duration |
|---|---|
| Spot Fleet / Launch Template | 1–2 days |
| Interruption handling in application | 2–3 days |
| Kubernetes Karpenter | 2–3 days |
| Testing | 1 day |
| Total | 5–9 days |
Cost is calculated individually based on your volume and complexity. Request an estimate — simply write to us. We guarantee transparent pricing and scope fixation.
Real savings in numbers
Typical savings are 60–80% compared to on-demand. Overhead for interruptions and restarts is 5–15% of time. On one ML training project using p3.2xlarge, savings reached 70%. Our clients confirm: proper checkpointing implementation pays for itself in 1–2 months. Contact us to calculate the savings for your workload. Order an audit of your batch jobs — our engineers with 5+ years of experience and AWS/GCP certifications will help reduce your cloud bill without performance loss.







