Block, file and object storage

Reading · 5 min · Module 3, lesson 2 of 310 min left in this module

Module 3 · StorageLesson 2 of 3

Goal: Pick block, file or object storage for a given piece of data, and say why.

Key idea

The three kinds of persistent storage differ in what you ask them for. Block storage hands one server a raw disk. File storage shares a folder between servers. Object storage keeps whole files by name and serves them over HTTP to anything that asks.

Block: a disk of your own

Block storage looks to your server like a plugged-in disk. The operating system formats it and puts a filesystem on it, and your app reads and writes files there as if it were local. Because the server reads and writes in small pieces, called blocks, it's fast, even for tiny changes in the middle of a big file.

The catch: a block volume is usually attached to one server at a time. It's the natural home for a database's own data files, or a single app that keeps files on disk.

File: a folder several servers share

File storage is a folder on another machine, shared over the network. Several servers mount it at a path such as /shared, and they all see the same files. It suits content that many copies of an app read, like shared documents.

Every read and write crosses the network, so it's slower than a local disk. Two servers writing the same file at once also need care.

Object: files by key, over HTTP

Object storage keeps files, called objects, in a container called a bucket. Each object has a key, a name like uploads/cat.jpg, and you fetch or store it with HTTP requests. Slashes in a key look like folders but are just part of the name.

Objects are written whole: to change one byte, you upload the file again. In return, any number of servers can reach the same files, and a bucket can hold a nearly unlimited number of them, usually for less per GB than disks.

Picking one

DataPickWhy
A database's data filesBlockFast small writes, one server
User uploads on a site with several copiesObjectEvery copy can reach it, and it grows without limit
Nightly backupsObjectCheap, durable, stored whole
Documents several servers read and editFileA shared folder at a path

Most web apps need little more than a database for records and object storage for files.

Check yourself

Your site runs on three servers and users upload profile photos. Where do the photos go?
You run your own database on a rented virtual machine. Where do its data files belong?

In the docs