Design a Block Storage Service like EBS
Understanding the Problem
💽 What is a block storage service? A block storage service gives a virtual machine a disk that lives on the network instead of inside the host. The VM sees an ordinary block device and reads and writes fixed-size blocks at byte offsets, while the bytes are actually stored, replicated, on a fleet of storage servers. The disk outlives the VM: you can detach it, attach it to another machine and snapshot it. Amazon EBS, Google Persistent Disk, Azure Managed Disks and Ceph RBD all work this way.
Compared with an object store, the interface is lower level and the latency budget is far tighter. An operating system and a database sit directly on top of this disk, issue tens of thousands of small random writes a second and expect each one to finish in well under a millisecond. They also expect the semantics of a real disk: when a write returns, a later read returns that data, even after a crash.
Functional Requirements
Core Requirements
- Users should be able to create a volume on demand with a chosen size (1 GB to 16 TB) and performance level (IOPS and throughput), empty or from a snapshot.
- Users should be able to attach a volume to one VM in the same availability zone, read and write blocks, detach it and attach it elsewhere.
- Users should be able to take point-in-time snapshots of a volume, stored durably outside the zone, and create new volumes from them.
- Users should be able to grow a volume or change its performance level without detaching it.
Below the line (out of scope)
- Attaching one volume to several VMs at once (multi-attach). It needs a cluster file system on top, and we'll leave it out.
- Encryption key management, billing and cross-region snapshot copies.
- The file system on the volume. We store blocks; the guest OS decides what they mean.
Non-Functional Requirements
Core Requirements
- The system should give low latency: p50 under 0.5 ms and p99 under 2 ms for 4 KB reads and writes, with each volume delivering up to 64k IOPS and 1 GB/s.
- The system must not lose acknowledged writes, and must survive the loss of any single disk, server or rack without the volume becoming unavailable for more than a few seconds.
- The system must be strongly consistent per volume: a read always returns the last acknowledged write to that block.
- The system should scale to about 1 million volumes per availability zone, averaging 100 GB each, about 100 PB provisioned.
- One volume's heavy I/O shouldn't hurt another's (performance isolation).
Below the line (out of scope)
- Synchronous replication across availability zones. We'll explain why not, and use snapshots for zone-level protection.
The latency numbers drive the whole design, so work them through. A 4 KB write to a local NVMe SSD with power-loss protection takes on the order of 20-50 µs. A round trip between servers in the same data center is on the order of 50-100 µs. A round trip between availability zones is on the order of a millisecond.
So a replicated write can afford roughly one or two network round trips inside the zone, and none across zones. That's why replicas of a volume live in the same zone on different racks, and why cross-zone durability comes from snapshots instead. It also means the I/O path can't touch a central metadata database or wait for a consensus round on every write: the data path has to be a direct line from the host to a small set of storage servers.
Capacity is the other half. 100 PB provisioned, three replicas, is up to 300 PB of SSD if every volume were full. They aren't: volumes are typically far from full, so we allocate space only when a block is first written (thin provisioning), and the real footprint is much smaller. That makes placement, overcommit and fragmentation a central concern.
Lead with the latency budget. Once you've said "a cross-zone round trip costs as much as the whole write budget," your interviewer will see why the replicas are local and snapshots go to object storage.