Ace Cloud Interviews

AWS Compute

EC2

Resizable virtual machines with full OS control and flexible pricing models

Amazon Elastic Compute Cloud (EC2) is the foundational compute service of AWS - it provides resizable virtual machines in the cloud. You choose the hardware profile (CPU, RAM, network), the operating system, storage, and networking. EC2 underpins almost every AWS architecture and is one of the most tested services in cloud interviews.

Instance Families and Types

EC2 instances are grouped into families optimized for different workloads. The instance name format is: Family + Generation + Attributes + Size (e.g., m7g.2xlarge).

FamilyOptimized ForExamplesUse Cases
T (Burstable)Variable CPU workloadst3.micro, t4g.smallDev/test, small web apps, CI runners
M (General Purpose)Balanced CPU/RAMm7i.large, m6g.xlargeWeb servers, app servers, code repos
C (Compute)High CPU performancec7g.4xlarge, c6i.8xlargeHPC, scientific modeling, batch processing
R (Memory)High RAM-to-CPU ratior7g.16xlarge, r6i.2xlargeIn-memory DBs, Hadoop, SAP HANA
X (Extra Memory)Extreme memoryx2gd.16xlargeSAP HANA, in-memory analytics
I (Storage)NVMe SSD throughputi4i.4xlargeNoSQL DBs, data warehousing
D (Dense Storage)HDD throughputd3.8xlargeDistributed file systems, Hadoop
G / P / TrnGPU / MLg5.48xlarge, p4d.24xlargeML training, inference, video rendering
InfML Inferenceinf2.48xlargeLow-latency inference with AWS Inferentia
💡

Graviton (g suffix, e.g., m7g) instances use AWS-designed ARM chips and typically offer 20-40% better price/performance than equivalent x86 types. Prefer Graviton when your workload is ARM-compatible.

Purchasing Options

Choosing the right pricing model can reduce EC2 costs by 60-90%. This is a common interview topic.

ModelDiscount vs On-DemandCommitmentBest For
On-Demand0% (baseline)NoneUnpredictable workloads, testing, spiky traffic
Reserved Instances (1yr)Up to 40%1 yearSteady-state workloads with known instance type/region
Reserved Instances (3yr)Up to 72%3 yearsLong-running databases, always-on services
Savings Plans (Compute)Up to 66%1-3 yearsFlexible - covers EC2, Lambda, Fargate across regions
Savings Plans (EC2)Up to 72%1-3 yearsFixed instance family in one region, more flexible than RIs
Spot InstancesUp to 90%NoneFault-tolerant, batch jobs, ML training, stateless workloads
Dedicated HostsVariesOn-demand or 1-3yrBring-your-own-license (BYOL), compliance, hardware isolation
Dedicated InstancesHigher priceOn-demandSingle-tenant hardware without full host control
⚠️

Spot instances can be interrupted with a 2-minute warning. Never use Spot for workloads that cannot tolerate interruption (e.g., primary databases, synchronous payment processing).

A common architecture for cost optimization: use Reserved/Savings Plans for the baseline load, On-Demand for predictable spikes, and Spot for batch/background jobs.

Storage: EBS Volumes

EBS (Elastic Block Store) volumes are network-attached block storage for EC2. They persist independently of the instance lifecycle and can be snapshotted to S3.

Volume TypeMax IOPSMax ThroughputBest For
gp3 (General Purpose SSD)16,0001,000 MB/sMost workloads - default choice. IOPS independent of size.
gp2 (General Purpose SSD)16,000250 MB/sLegacy - gp3 is better in every way. Migrate to gp3.
io2 Block Express (Provisioned IOPS)256,0004,000 MB/sMission-critical DBs, Oracle RAC, sub-millisecond latency
io1 (Provisioned IOPS)64,0001,000 MB/sI/O intensive databases requiring consistent performance
st1 (Throughput HDD)500500 MB/sBig data, Kafka, log processing - sequential reads
sc1 (Cold HDD)250250 MB/sInfrequently accessed data, lowest cost HDD option
💡

Only gp2, gp3, io1, and io2 can be used as boot volumes. st1 and sc1 are data volumes only.

  • EBS Multi-Attach allows io1/io2 volumes to be attached to up to 16 instances in the same AZ simultaneously
  • EBS snapshots are incremental and stored in S3 - you pay only for changed blocks
  • Snapshots can be copied across regions for disaster recovery
  • EBS Encryption uses KMS and is transparent to the OS - zero performance impact on Nitro instances

Networking and Security

EC2 networking is built around VPCs, subnets, security groups, and network ACLs. Understanding the difference between security groups and NACLs is a must for interviews.

FeatureSecurity GroupsNetwork ACLs
LevelInstance (ENI)Subnet
StatefulnessStateful - return traffic allowed automaticallyStateless - must explicitly allow both directions
RulesAllow rules onlyAllow and deny rules
EvaluationAll rules evaluated togetherRules evaluated in order (lowest number first)
DefaultDeny all inbound, allow all outboundAllow all inbound and outbound
  • Elastic IPs - static IPv4 addresses that can be remapped between instances for failover
  • Enhanced Networking (ENA) - up to 100 Gbps, lower latency, fewer CPU cycles for network processing
  • Placement Groups: Cluster (low latency, same AZ), Spread (max 7 per AZ, hardware fault isolation), Partition (up to 7 per AZ, used by Hadoop/Cassandra/Kafka)
  • Instance Metadata Service (IMDS) at 169.254.169.254 - provides instance ID, IAM role credentials, AMI ID. IMDSv2 uses session tokens and is more secure.

Auto Scaling and High Availability

EC2 Auto Scaling Groups (ASGs) maintain a fleet of instances to handle varying load. They replace unhealthy instances automatically and scale based on policies.

  • Scaling policies: Target Tracking (maintain a metric like 70% CPU), Step Scaling (specific thresholds trigger step changes), Scheduled Scaling (known traffic patterns)
  • Cooldown period prevents rapid scale-in/out oscillation - default 300 seconds
  • Launch Templates define instance configuration (AMI, type, security groups, user data) - preferred over older Launch Configurations
  • Instance refresh performs rolling replacement to update the fleet to a new AMI without downtime
  • Lifecycle hooks pause instance launch/termination to run custom actions (e.g., drain connections, copy logs)
  • Warm pools pre-launch and pre-configure instances in a stopped state so they can join the fleet faster
💡

For a highly available architecture, always spread ASG instances across at least 3 Availability Zones behind a load balancer. An AZ failure should not impact the application.

Amazon Machine Images (AMIs)

An AMI is a template containing the OS, application software, and configuration needed to launch an EC2 instance. It is the "blueprint" for instances in an ASG.

  • AMIs are region-specific - copy them to other regions for multi-region deployments
  • AMI types: EBS-backed (persistent, can be stopped/started) vs Instance Store-backed (ephemeral, data lost on stop)
  • Custom AMIs ("baked AMIs" or "golden AMIs") pre-install software to reduce boot time vs installing via user data
  • AWS Systems Manager Parameter Store can track the latest AMI ID for automation
  • Sharing: AMIs can be private (default), shared with specific AWS accounts, or made public
🎯

Interview Focus Points

  • 1Difference between Spot, Reserved, On-Demand, and Savings Plans - when to use each
  • 2Security Groups vs Network ACLs - statefulness, level, rule types
  • 3Placement group types and when to choose each
  • 4EBS volume types - gp3 vs io2 vs st1, and when to use each
  • 5How IMDSv2 improves security over IMDSv1
  • 6How Auto Scaling lifecycle hooks work and why you need them
  • 7Graviton instances - benefits and workload compatibility
  • 8How EBS Multi-Attach works and its limitations