EFS vs. EBS

Difficulty: Intermediate

Question

What is the difference between Amazon EBS and Amazon EFS, and when would you use each (or S3 instead)?

Answer

Amazon EBS is block storage: a virtual disk attached to a single EC2 instance in one Availability Zone, with low latency and the instance's own file system on top. Amazon EFS is a managed NFS file system: many EC2 instances, containers, and Lambda functions across multiple AZs can mount it at the same time, and it grows and shrinks automatically. Use EBS for boot volumes and databases on one machine, EFS when several compute nodes need to share the same files, and S3 when you just need to store and serve objects over HTTP.

How they differ

AspectEBSEFS
Storage typeBlock device (you format it: ext4, xfs, NTFS)Managed file system over NFSv4
AttachmentOne instance (Multi-Attach only for io1/io2 within one AZ)Thousands of clients concurrently
ScopeSingle AZRegional (multi-AZ) or One Zone
CapacityProvisioned size, you resize manuallyElastic, pay for what you store
LatencyLowest (sub-millisecond on SSD)Low milliseconds, higher than EBS
Operating systemsLinux and WindowsLinux (Windows shares use FSx for Windows)
ClientsEC2EC2, ECS, EKS, Lambda, on-premises via VPN or Direct Connect
Price per GBLowerHigher, reduced with Infrequent Access and Archive classes

When to choose EBS

  • Root/boot volumes for EC2.
  • A self-managed database (PostgreSQL, MongoDB) on one instance, where you want the lowest latency and predictable IOPS.
  • Any workload where only one machine writes to the disk.

When to choose EFS

  • A fleet of web servers behind a load balancer that all need the same uploaded files or a shared CMS directory (for example WordPress wp-content).
  • Containers on ECS or EKS that need persistent shared storage that survives task restarts and works across AZs.
  • Lambda functions that need large reference files (ML models, dictionaries) larger than the deployment package allows.
  • Home directories or shared build caches for a team.

EFS lifecycle management moves files not accessed for a set time into Infrequent Access or Archive storage classes, which cuts costs for data that is written once and rarely read.

Where S3 fits

S3 is object storage accessed through an API, not a mounted file system. It is cheaper still and effectively unlimited, and it is the right answer for user uploads, static assets, backups, and data lakes. If an application can talk to S3 directly, that is usually better than putting files on EFS. Use EFS when software expects a POSIX file system path and shared access.

Gotchas

  • EBS Multi-Attach does not give you a shared file system. Mounting ext4 on two instances at once corrupts data; you need a cluster-aware file system.
  • EFS performance depends on the throughput mode. Elastic (the default for new file systems) scales automatically and is billed by usage; Provisioned fixes throughput; Bursting ties it to stored size.
  • EFS mount targets live in subnets with Security Groups; NFS port 2049 must be allowed from the clients.

Code examples

Mounting EFS on two EC2 instances

# On each instance (Amazon Linux)
sudo dnf install -y amazon-efs-utils
sudo mkdir -p /mnt/shared

# Mount with TLS using the EFS mount helper
sudo mount -t efs -o tls fs-0123456789abcdef0:/ /mnt/shared

# Persist across reboots
echo "fs-0123456789abcdef0:/ /mnt/shared efs _netdev,tls 0 0" | sudo tee -a /etc/fstab

# A file written on instance A is immediately visible on instance B
echo "hello" | sudo tee /mnt/shared/test.txt

Both instances see the same files because they mount the same EFS file system; an EBS volume could only be attached to one of them.

Key points

  • EBS: block storage, one instance, one AZ, lowest latency
  • EFS: managed NFS, many clients across AZs, elastic capacity, Linux only
  • S3: object storage via API, cheapest, for uploads, backups, and data lakes
  • EBS Multi-Attach (io1/io2) is not a shared file system
  • EFS throughput modes: Elastic (default), Provisioned, Bursting

Common follow-up questions

  • How would you share files between EC2 instances in different Availability Zones?
  • Why not just use S3 instead of EFS?
  • What happens to an EBS volume when its instance is terminated?
  • What would you use for a shared Windows file system on AWS?

Interview tips

  • Start with block vs file vs object; it frames the whole answer
  • Give a concrete shared-storage use case like web servers sharing uploads or ECS tasks needing persistent data
  • Mention S3 as often the better choice for files, which shows practical judgement

Concepts covered

Amazon EFS, Amazon EBS, Block vs File Storage, NFS, Multi-AZ Storage

More AWS & Cloud Fundamentals questions