What are the main EC2 instance types and their use cases?
Learn the main Amazon EC2 instance families — general purpose, compute, memory, storage, and GPU — and how to match each to your workload for cost and speed.
Expected Interview Answer
Amazon EC2 groups instances into families optimized for different resource profiles: general purpose (T, M), compute optimized (C), memory optimized (R, X), storage optimized (I, D), and accelerated computing (P, G, Inf) for GPUs and ML.
Each family balances vCPU, memory, storage, and network differently so you match the instance to the workload's bottleneck. General purpose suits web servers and small databases; compute optimized fits batch processing and gaming servers; memory optimized handles in-memory caches and large databases; storage optimized serves high-IOPS data stores; accelerated computing powers training, inference, and rendering. Burstable T instances accumulate CPU credits for spiky, low-average workloads.
- Right-sizing controls cost by avoiding over-provisioning
- Workload-specific families remove resource bottlenecks
- Burstable credits suit spiky, low-utilization apps
- GPU families accelerate ML and rendering
- Flexible scaling across dozens of size options
AI Mentor Explanation
Choosing an EC2 family is like picking players for a specific match role: an opener who anchors the innings, a fast bowler built for pace, a spinner for turning pitches, a big-hitting finisher. Each is optimized for one job, and fielding the wrong specialist for the situation wastes the slot just as a mismatched instance wastes money.
Step-by-Step Explanation
Step 1
Profile the workload
Measure whether the app is CPU-bound, memory-bound, storage-bound, or needs GPU acceleration.
Step 2
Pick the family
Map the bottleneck to a family: C for compute, R/X for memory, I/D for storage, P/G for GPUs, M/T for balanced.
Step 3
Choose the size
Select a size (large, xlarge, etc.) that provides enough vCPU and memory with headroom for peaks.
Step 4
Consider burstable vs fixed
Use T-family burstable instances for spiky low-average loads; fixed-performance families for steady demand.
Step 5
Validate and right-size
Run under load, review CloudWatch metrics, and adjust the family or size to cut cost or relieve bottlenecks.
What Interviewer Expects
- Names the core families and their optimization
- Maps a workload to the correct family
- Understands burstable T-instance CPU credits
- Knows GPU families serve ML and rendering
- Connects instance choice to cost control
Common Mistakes
- Defaulting to general purpose for every workload
- Confusing instance family with instance size
- Ignoring burstable credit exhaustion under sustained load
- Over-provisioning memory-optimized instances for CPU-bound apps
- Forgetting to right-size using CloudWatch metrics
Best Answer (HR Friendly)
“EC2 offers different instance families that are each tuned for a particular need — some for raw computing power, some for lots of memory, some for fast storage, and some with GPUs for machine learning. You pick the family that matches what your application needs most so you get good performance without paying for resources you won't use.”
Code Example
aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--instance-type c7g.xlarge \
--key-name my-key \
--security-group-ids sg-0123456789abcdef0 \
--subnet-id subnet-0123456789abcdef0 \
--count 1
# Describe available instance types filtered by family
aws ec2 describe-instance-types \
--filters "Name=instance-type,Values=r7g.*" \
--query "InstanceTypes[].{Type:InstanceType,VCPU:VCpuInfo.DefaultVCpus,MemMiB:MemoryInfo.SizeInMiB}"Follow-up Questions
- How do burstable T-instance CPU credits accumulate and get spent?
- When would you choose Graviton (ARM) instances over x86?
- How do Spot, Reserved, and On-Demand pricing affect instance selection?
- What metrics guide right-sizing an over-provisioned instance?
MCQ Practice
1. Which EC2 family is best suited for an in-memory database like Redis with a large working set?
The R family (memory optimized) provides a high memory-to-vCPU ratio, ideal for in-memory caches and large databases.
2. What is the defining behavior of T-family burstable instances?
Burstable instances earn CPU credits while idle and consume them to burst above baseline, suiting spiky low-average workloads.
3. Which family should you choose to accelerate deep learning training?
P-family instances include high-end GPUs designed for ML training and other massively parallel workloads.
Flash Cards
Which family is compute optimized? — The C family — high vCPU-to-memory ratio for batch processing, gaming servers, and high-performance computing.
What does a burstable T instance do? — Accumulates CPU credits while idle and spends them to burst above baseline CPU, ideal for spiky low-average workloads.
Best family for GPU workloads? — Accelerated computing families like P (training), G (inference/graphics), and Inf (Inferentia inference).
How do you avoid over-provisioning? — Right-size by profiling the workload and reviewing CloudWatch CPU and memory metrics, then adjusting family and size.