๐Ÿ’พ AWS Block Storage ยท Module 03

Amazon EBS
Theory Notes

Elastic Block Store โ€” persistent virtual hard drives for EC2 instances. Complete beginner-friendly guide with real company scenarios.

๐Ÿ’พ

Block Storage THIS MODULE

VM's virtual hard drive. Attached directly to EC2.

AWS: Amazon EBS
๐Ÿ—‚๏ธ

Object Storage

Files stored via URL. Any type of data.

AWS: Amazon S3 โ†’ Module 04
๐Ÿ“

File Storage

Shared NFS drive for multiple EC2s.

AWS: Amazon EFS โ†’ in S3 notes
Topics Covered
1

What is Amazon EBS?

When you launch an EC2 instance, it needs storage โ€” just like your laptop needs a hard drive. Amazon EBS (Elastic Block Store) provides that storage. It is a network-attached, persistent block storage volume that you attach to EC2 instances.

Persistent means the data survives even if the EC2 instance is stopped or restarted โ€” just like your laptop's hard drive keeps files even when you shut it down.

๐Ÿ’ฟ Analogy โ€” External Hard Drive

Think of EBS like an external USB hard drive.

You plug it into your laptop (EC2) and use it. If you shut down the laptop โ€” the hard drive and its data are safe. You can unplug it and plug it into a different laptop (different EC2 instance). You can make a copy (snapshot) for backup. The key difference: EBS volumes are attached over the network, not a physical cable.

๐Ÿ”—

Attached to EC2

One EBS volume attached to one EC2 at a time (except io1/io2 Multi-Attach for clusters).

๐Ÿ“

Same Availability Zone

EBS volume and EC2 must be in the same AZ. Mumbai AZ-a volume โ†’ Mumbai AZ-a EC2 only.

๐Ÿ’พ

Persistent Storage

Data survives stop/start. Only deleted when you explicitly delete the volume.

๐Ÿ“

Scalable Size

Start with any size. Increase without stopping the EC2 instance โ€” zero downtime.

๐Ÿข Real Company Scenarios

Flipkart runs its product catalog MySQL database on EC2 instances. Each EC2 has a gp3 EBS volume of 500 GB as the data disk. The database stores millions of product records, prices, and inventory. Because EBS is persistent, even when Flipkart's EC2 is stopped at 3 AM for maintenance, all product data remains safe on the EBS volume. When the EC2 restarts at 6 AM, it re-attaches the same EBS volume with all data intact.

Zerodha (India's largest stockbroker) runs its trading engine on EC2 + io2 EBS. During IPO subscriptions like LIC's โ‚น21,000 crore IPO, millions of orders hit the system. EBS provides the low-latency, high-IOPS storage the trading database needs to handle 100,000+ orders per second without losing a single transaction.

2

EBS vs Instance Store

EC2 instances can have two types of storage. It is critical to know the difference โ€” choosing the wrong one means losing all your data.

FeatureEBS VolumeInstance Store
TypeNetwork-attached block storagePhysically attached to the host hardware
Persistenceโœ… Data persists on stop/restart/failureโŒ Data LOST on stop, terminate, or hardware failure
Use forOS, databases, application dataTemp caches, scratch space, buffers only
Snapshotโœ… Backup to S3 anytimeโŒ No backup support at all
SpeedVery fast (gp3: up to 16,000 IOPS)Fastest (direct physical NVMe)
CostBilled per GB provisionedIncluded in instance price (free)
Move to another EC2โœ… Detach and attach to another EC2โŒ Cannot be moved โ€” tied to one physical host
Critical Warning โ€” Never Use Instance Store for Real Data
Never store databases, user uploads, or application data on Instance Store. If the EC2 stops (even for a scheduled maintenance), is terminated, or the underlying hardware fails โ€” all data is permanently, irreversibly lost. No recovery possible.
๐Ÿข Real Incident โ€” Why This Matters

A startup in Bangalore (real incident reported on AWS forums) launched a MongoDB database on an EC2 instance and stored all data on the Instance Store (they thought it was faster โ€” which it is). AWS performed scheduled maintenance on the underlying host and stopped the EC2. When the EC2 restarted, the Instance Store was wiped clean. All 3 months of customer data was gone permanently. There was no backup. The startup had to contact customers to re-enter their data.

Lesson: Always use EBS for any data you want to keep. Instance Store = scratch pad only. Use it only for temporary caches, sort operations, or data you can easily recreate.

3

EBS Volume Types

EBS comes in 6 types โ€” two categories: SSD-backed (low latency, random access) and HDD-backed (high throughput, sequential reads). Key term: IOPS = Input/Output Operations Per Second โ€” how many read/write operations per second the disk can handle.

SSD-Backed Volumes

gp3 โ€” General Purpose SSD

Best for most workloads

1 GB โ€“ 16 TB ยท Up to 16,000 IOPS ยท 1,000 MB/s

Latest generation. IOPS and throughput independently configurable. Cheaper than gp2. Default choice for all new volumes.

โœ… OS disks, web servers, small/medium databases, dev/test
gp2 โ€” General Purpose SSD (older)

Previous generation

1 GB โ€“ 16 TB ยท 3 IOPS/GB, max 16,000

IOPS tied to size (bigger = more IOPS). Still works but gp3 is cheaper and better. Use gp3 for all new volumes.

โœ… Same as gp3 โ€” prefer gp3 for new deployments
io2 โ€” Provisioned IOPS SSD

Mission-critical databases

4 GB โ€“ 64 TB ยท Up to 64,000 IOPS (Block Express: 256,000)

Guaranteed, consistent high IOPS. io2 Block Express is the highest performance EBS volume available.

โœ… Oracle DB, SAP HANA, large MySQL, trading platforms
io1 โ€” Provisioned IOPS SSD (older)

Previous high-performance

4 GB โ€“ 16 TB ยท Up to 64,000 IOPS

Older version of io2. Supports Multi-Attach (same volume โ†’ up to 16 EC2 instances). Use io2 for new deployments.

โœ… Critical DBs, clustered applications (Multi-Attach)

HDD-Backed Volumes

st1 โ€” Throughput Optimized HDD

Large sequential reads

125 GB โ€“ 16 TB ยท Up to 500 MB/s throughput

For big files read sequentially (not random access). Cannot be a boot volume. Optimized for reading large files end-to-end.

โœ… Hadoop big data, log processing, data warehouses, Kafka
sc1 โ€” Cold HDD

Cheapest EBS option

125 GB โ€“ 16 TB ยท Up to 250 MB/s throughput

Lowest cost per GB. For infrequently accessed large files. Cannot be a boot volume.

โœ… Archival storage, compliance data, infrequently accessed backups
Quick Decision Guide
New web server or OS volume โ†’ gp3  |  High-performance DB โ†’ io2  |  Big data / log files โ†’ st1  |  Cheapest archive โ†’ sc1  |  Free tier lab โ†’ gp2/gp3 up to 30 GB
๐Ÿข Real Company Scenarios โ€” Volume Type Choice

Amazon India runs its main e-commerce website on thousands of EC2 instances, each with a gp3 OS disk (running Amazon Linux). For the product database, they use io2 Block Express volumes on RDS instances โ€” during Big Billion Day / Great Indian Festival sale, the database handles millions of queries per second. io2's guaranteed 256,000 IOPS ensures no slowdown even at peak.

Swiggy's data engineering team processes 50 GB of order logs daily using Apache Spark on EC2. They use st1 (Throughput Optimized HDD) for storing raw log files โ€” these are read sequentially (not randomly) by Spark jobs. st1 is 60% cheaper than gp3 for this sequential workload, saving Swiggy โ‚น2+ lakhs per month in storage costs.

IRCTC stores historical train booking records (7+ years, compliance requirement) on sc1 Cold HDD. These records are almost never accessed โ€” only during rare audits. sc1 is the cheapest EBS option at โ‚น0.015/GB/month vs gp3 at โ‚น0.096/GB/month โ€” 85% cheaper for rarely-accessed compliance data.

4

EBS Snapshots โ€” Backup to S3

A Snapshot is a backup of your EBS volume saved to Amazon S3. You can use it to restore a volume, copy data to another region, or create a new volume anywhere in AWS.

๐Ÿ“ธ Analogy โ€” Phone Backup

Snapshot = backup of your phone to Google Drive / iCloud.

Your phone (EC2) keeps working normally. At any time you take a backup (snapshot) of its storage (EBS) to S3. If your phone breaks (EC2 crashes), restore from backup and get everything back. You can also restore onto a different phone (different EC2 in a different region).

๐Ÿ’พ

EBS Volume

Running data

โ†’
๐Ÿ“ธ

Snapshot

Stored in S3

โ†’
๐Ÿ”„

Restore

New EBS volume

โ†’
๐ŸŒ

Copy to Region

Disaster recovery

๐Ÿ“ฆ

Incremental Snapshots

First snapshot = full backup. Every subsequent snapshot = only changed blocks. Saves cost.

๐ŸŒ

Cross-Region Copy

Copy snapshot to any AWS region. If Mumbai region fails, restore in Singapore or US.

๐Ÿ–ผ๏ธ

Create AMI from Snapshot

Turn snapshot into an AMI (machine image). Launch identical EC2s anywhere in AWS.

๐Ÿ”„

Snapshot Recycle Bin

Accidentally deleted? AWS keeps it in Recycle Bin for up to 365 days before permanent deletion.

๐Ÿข Real Company Scenarios โ€” Snapshots

Freshworks (Indian SaaS company, listed on Nasdaq) runs CRM software for global clients. Before every production deployment, their DevOps team takes an EBS snapshot of all production volumes. If the new deployment causes a bug, they restore from the snapshot in under 10 minutes โ€” bringing the system back to its pre-deployment state. This "pre-deploy snapshot โ†’ deploy โ†’ monitor โ†’ rollback if needed" pattern is used by every serious company.

BookMyShow has a disaster recovery strategy using cross-region snapshots. Every night, EBS snapshots of the booking database in Mumbai (ap-south-1) are automatically copied to Singapore (ap-southeast-1). If a natural disaster or prolonged AWS Mumbai outage occurs, BookMyShow can restore their database in Singapore and redirect traffic there โ€” achieving their 4-hour Recovery Time Objective (RTO).

Ola uses the Amazon Data Lifecycle Manager (DLM) to automate EBS snapshots: every day at 2 AM, snapshots are taken automatically for all production volumes. Old snapshots older than 30 days are automatically deleted. This costs them โ‚น15,000/month for peace of mind on 500+ production volumes โ€” instead of hiring someone to do it manually.

5

EBS Encryption

EBS encryption protects your data at rest (stored on disk) and in transit (moving between EBS and EC2). It uses AES-256 encryption and AWS manages the keys automatically via AWS KMS (Key Management Service).

What Gets Encrypted?Details
Data at rest on the volumeAll data written to EBS is encrypted with AES-256
Data in transitData moving between EC2 and EBS is encrypted (SSL/TLS)
Snapshots of encrypted volumesAutomatically encrypted โ€” no extra steps
Volumes from encrypted snapshotsAny new volume created from an encrypted snapshot is automatically encrypted
Zero Performance Impact โ€” Always Encrypt
EBS encryption has no measurable performance overhead. It runs transparently in the hardware. There is no reason NOT to encrypt. Always enable encryption for any volume storing user data, passwords, or financial records. In production, enable "Encryption by default" at the account level.
๐Ÿข Real Company Scenarios โ€” Encryption

Paytm stores KYC data (Aadhaar numbers, PAN cards, bank account details) of 350 million users. RBI regulations mandate encryption of financial customer data. Paytm uses EBS encryption with customer-managed KMS keys โ€” meaning even AWS employees cannot read the data. Encryption keys are rotated every year automatically. This satisfies RBI's data security guidelines without any application-level code changes.

Apollo Pharmacy stores patient prescription history and medical records on encrypted EBS volumes. Healthcare data falls under the PDPB (Personal Data Protection Bill) in India and HIPAA internationally. Using EBS with encryption-by-default means every new volume is automatically encrypted โ€” zero chance of accidentally creating an unencrypted volume with sensitive health data.

6

Modifying Volumes โ€” No Downtime

One of EBS's most powerful features: increase volume size, change volume type, or adjust IOPS while the EC2 instance is running. No restart needed โ€” zero downtime.

๐Ÿ“ˆ

Increase Size

Expand 20 GB โ†’ 200 GB while EC2 runs. Then extend the file system (OS command) to use new space.

โšก

Change Type

Switch gp2 โ†’ gp3 for better performance and lower cost โ€” live, no downtime required.

๐ŸŽš๏ธ

Adjust IOPS / Throughput

Increase IOPS on io2 volumes when DB needs more performance during sale/peak time.

One-Way Rule โ€” Can Only Grow, Never Shrink
You can increase an EBS volume size but cannot decrease it. If you need a smaller volume, create a new smaller one and copy data over. Plan your initial size carefully โ€” you can always grow later, but never shrink.
7

Attach, Detach, and Move Volumes

EBS volumes are like USB hard drives โ€” you can attach and detach them from EC2 instances, as long as they stay in the same Availability Zone.

OperationRequirementNotes
AttachSame AZ as EC2Root volume attached at launch. Data volumes can be attached anytime.
DetachVolume must be unmounted firstSafely detach data volumes. Root volume: must stop EC2 first.
Move to another AZSnapshot โ†’ New volume in new AZDirect AZ-to-AZ move is not possible. Use snapshot as intermediary.
Move to another RegionCopy snapshot to new region โ†’ new volumeSnapshots cross regions; raw volumes cannot.
Multi-Attach โ€” One Volume, Multiple EC2s
io1/io2 volumes support Multi-Attach โ€” the same volume can be attached to up to 16 EC2 instances in the same AZ simultaneously. Used for clustered applications (Oracle RAC, Microsoft SQL Server Always On, etc.) that need shared block storage.
8

Root Volume vs Data Volume

๐Ÿฅพ

Root Volume (OS Disk)

Contains OS (Linux/Windows). Created automatically when you launch EC2. Deleted by default when EC2 is terminated โ€” change "Delete on Termination" to No if you want to keep it.

๐Ÿ“

Data Volume

Additional volumes you attach manually. For storing databases, app files, user uploads. NOT deleted on EC2 termination by default. Can be detached and re-attached to any EC2 in the same AZ.

Protect Your Root Volume
By default, root volume is deleted when EC2 is terminated. To prevent accidental loss: when launching EC2, set "Delete on Termination" to No for the root volume. This keeps the volume even after termination โ€” you can attach it to a new EC2 and recover everything.
9

AWS EBS vs Azure Managed Disks

ConceptAWS EBSAzure Managed Disk
Service NameElastic Block Store (EBS)Azure Managed Disks
General Purpose SSDgp3 / gp2Standard SSD (E-series)
High Performance SSDio2 / io1Premium SSD (P-series) / Ultra Disk
HDD Storagest1 / sc1Standard HDD (S-series)
Backup MechanismEBS Snapshot (stored in S3)Azure Snapshot / Azure Backup
EncryptionAWS KMS, AES-256SSE (Server-Side Encryption) โ€” on by default
ScopeSingle Availability ZoneSingle region (ZRS option available)
Max volume size16 TB (gp3) / 64 TB (io2)32 TB
Multi-attachio1/io2 only (up to 16 EC2)Shared Disk feature (Premium/Ultra)
Key DifferenceVolume must be in same AZ as EC2Disks auto-manage placement
10

Key Summary

EBS = persistent disk Same AZ rule gp3 = default choice io2 = high-performance DB Snapshot = S3 backup Always encrypt Can grow, can't shrink Instance Store = temporary only
AWS Official Docs

Official Documentation โ€” EBS

Topic AWS Docs URL
EBS OverviewEC2/AmazonEBS.html
EBS Volume Typesebs-volume-types.html
EBS SnapshotsEBSSnapshots.html
EBS EncryptionEBSEncryption.html
Modify EBS Volumeebs-modify-volume.html
Instance Store vs EBSInstanceStorage.html