EC2 Essentials

Difficulty: Beginner

Question

What are the EC2 pricing models, how do instance types differ, and how would you pick the right combination for a workload?

Answer

EC2 offers four main ways to pay: On-Demand (pay per second, no commitment), Savings Plans or Reserved Instances (commit to 1 or 3 years for a large discount), Spot Instances (spare capacity at up to 90% off that AWS can reclaim with a 2-minute warning), and Dedicated Hosts/Instances (hardware not shared with other customers, for licensing or compliance). Most production setups mix them: commitments for the steady baseline, On-Demand for peaks, and Spot for interruptible work.

The pricing models compared

ModelDiscount vs On-DemandCommitmentBest for
On-DemandNoneNoneSpiky, unknown or short-lived workloads
Compute Savings PlanUp to about 66%$/hour for 1 or 3 yearsSteady usage across EC2, Fargate and Lambda, any family or Region
EC2 Instance Savings Plan / Standard RIUp to about 72%1 or 3 years, fixed family and RegionVery predictable fleets
SpotUp to 90%None, but can be interruptedBatch jobs, CI runners, stateless workers, ML training with checkpoints
Dedicated HostVariesOptionalPer-socket or per-core software licences, strict isolation

Linux On-Demand instances are billed per second with a 60-second minimum. Savings Plans are now the default recommendation over Reserved Instances because they apply automatically and are more flexible. On-Demand Capacity Reservations are separate: they guarantee capacity in an AZ but give no discount on their own.

Reading an instance type name

Take m7g.xlarge:

  • m is the family: general purpose.
  • 7 is the generation; newer is usually cheaper per unit of performance.
  • g is an attribute: AWS Graviton (ARM). Others include i (Intel), a (AMD), d (local NVMe), n (enhanced networking).
  • xlarge is the size; each step up roughly doubles vCPU and memory.

Main families: T (burstable, CPU credits), M (balanced), C (compute heavy), R/X (memory heavy, caches and in-memory databases), I/D (local storage), P/G/Inf/Trn (GPUs and AI accelerators).

Picking the right mix

  1. Right-size first using CloudWatch metrics or AWS Compute Optimizer; a discount on an oversized instance is still waste.
  2. Try Graviton for interpreted or JVM workloads; it typically gives better price-performance if your dependencies support ARM.
  3. Cover the always-on baseline (say the 6 API servers that run all night) with a Savings Plan.
  4. Let Auto Scaling handle peaks with On-Demand, for example Swiggy's lunch and dinner spikes.
  5. Push fault-tolerant work to Spot with a mixed-instances Auto Scaling group spread over several instance types and AZs.

Spot gotchas

  • AWS sends a 2-minute interruption notice through instance metadata and EventBridge; your app must checkpoint or drain.
  • Diversify across many instance types and use the price-capacity-optimized allocation strategy to reduce interruptions.
  • Never run a single-instance database on Spot.
  • T-family instances can be throttled when CPU credits run out; unlimited mode avoids throttling but bills extra credits.
Layering pricing models over a daily traffic curve. Commit for the floor, pay on demand for the peaks, and use Spot for anything that can be interrupted.
  1. Spot: batch and async workers: Cheapest, but can be reclaimed with 2 minutes notice.
  2. On-Demand: daily peaks: Auto Scaling adds capacity only when traffic rises.
  3. Savings Plan: steady baseline: The capacity you run 24x7, committed for 1 or 3 years.
  4. Dedicated Hosts: licensed software: Only when licences or compliance demand it.

Code examples

Check recent Spot prices for a Graviton instance in Mumbai

aws ec2 describe-spot-price-history \
  --region ap-south-1 \
  --instance-types m7g.large \
  --product-descriptions "Linux/UNIX" \
  --start-time $(date -u +%Y-%m-%dT%H:%M:%S) \
  --query "SpotPriceHistory[].{AZ:AvailabilityZone,Price:SpotPrice}" \
  --output table

Spot prices differ by AZ and change slowly based on supply and demand; compare them with the On-Demand price before deciding.

Mixed On-Demand and Spot Auto Scaling policy

{
  "LaunchTemplate": {
    "LaunchTemplateSpecification": { "LaunchTemplateName": "worker-lt", "Version": "$Latest" },
    "Overrides": [
      { "InstanceType": "m7g.large" },
      { "InstanceType": "m6g.large" },
      { "InstanceType": "c7g.large" }
    ]
  },
  "InstancesDistribution": {
    "OnDemandBaseCapacity": 2,
    "OnDemandPercentageAboveBaseCapacity": 20,
    "SpotAllocationStrategy": "price-capacity-optimized"
  }
}

This MixedInstancesPolicy keeps 2 On-Demand instances always, then fills 80% of extra capacity with Spot across three instance types to lower interruption risk.

Key points

  • On-Demand: no commitment, per-second billing for Linux with a 60-second minimum.
  • Savings Plans (up to about 66-72% off) are the modern replacement for most Reserved Instance use.
  • Spot: up to 90% off with a 2-minute interruption notice; only for fault-tolerant work.
  • Instance name = family + generation + attributes + size, e.g. m7g.xlarge.
  • Right-size before you commit; discounts on idle capacity are still waste.

Common follow-up questions

  • What happens to a Spot Instance when it is interrupted, and how do you handle it?
  • How is a Compute Savings Plan different from an EC2 Instance Savings Plan?
  • When would you choose a burstable T instance, and what are CPU credits?
  • How would you reduce the EC2 bill of a startup by 40% without hurting reliability?

Interview tips

  • Give the blended strategy (baseline commitment, On-Demand peaks, Spot for batch) rather than just listing models.
  • Quote discounts as "up to" figures; exact percentages depend on term, payment option and instance.
  • Mentioning Graviton and Compute Optimizer shows you think about cost beyond pricing models.

Concepts covered

On-Demand, Savings Plans, Spot Instances, Reserved Instances, Instance families, Graviton

More AWS & Cloud Fundamentals questions