Case study demo

Object storage (S3)

Store objects as metadata plus replicated data chunks.

An interactive demo of how this system behaves. It runs in your browser.

Case study · Live model

How an object store keeps data safe

An object store keeps files, here called objects, on 12 data nodes: servers full of disks. Each object is on several nodes, as full copies or as pieces, so that a failed node does not lose it. Fail one node, then two, then three, and watch which objects survive.

Try it

Lab time 3.0 s
where?piecesrebuildClients, 10 reads a secondClients10 reads a seconduploads: 1 a secondAPI servers, place each objectAPI serversplace each object0 reads openMetadata, where each piece isMetadatawhere each piece is205 objects listedData nodes, 12 of 12 upData nodes12 of 12 up36.9 GB storedRepair job, nothing to rebuild, IDLERepair jobnothing to rebuild0 rebuiltIDLE
  • Clients — 10 reads a second — healthy — uploads: 1 a second
  • API servers — place each object — healthy — 0 reads open
  • Metadata — where each piece is — healthy — 205 objects listed
  • Data nodes — 12 of 12 up — healthy — 36.9 GB stored
  • Repair job — nothing to rebuild — IDLE — 0 rebuilt
  • A read
  • An upload
  • Find the pieces, then fetch them
  • The object
  • The repair job rebuilds a piece
  • A read of a lost object
Disk used
3.0 ×
36.9 GB for 12.3 GB of objects
Whole
205/ 205
objects with all 3 copies
At risk
0
0 could not lose one more
Lost
0
objects that cannot be rebuilt
Slow reads
0
had to rebuild a missing piece first
Safe again after
–
from the last failure to every piece rebuilt

Numbers add up:205 objects = 205 whole + 0 at risk + 0 lost · 41 reads = 41 normal + 0 slow + 0 failed + 0 in progressThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

How an object is kept
Kept as

The whole object is written to 3 nodes. Any one copy is enough to read it. A new choice starts the model again.

Failures and repair
600 MB a second

How much the repair job can read each second. Rebuilding one coded piece means reading 4 others.

A failed node loses everything on it. An empty node takes its place after 3 s.

Traffic
10 a second
1 a second

Objects

StateObjectsWhat it means
Whole205Every copy is on a node that is up.
At risk0Something is missing, but enough is left to read the object and to rebuild the rest.
One from loss0Counted in "At risk" too: these have exactly the 1 they need, and no spare.
Lost0Fewer than 1 left. Nothing can bring the object back.

Node by node

NodeStateCopies heldStored
Node 1up412.5 GB
Node 2up503.0 GB
Node 3up382.3 GB
Node 4up472.8 GB
Node 5up492.9 GB
Node 6up623.7 GB
Node 7up613.7 GB
Node 8up472.8 GB
Node 9up643.8 GB
Node 10up573.4 GB
Node 11up422.5 GB
Node 12up573.4 GB
Objects at risk, and objects lost
At riskLost
00.30.50.811s2s3s
Show data table
TimeAt riskLost
1s00
1s00
2s00
2s00
3s00
3s00

What just happened

Nothing yet. Start traffic or run an experiment.

What this model simplifies
  • Every object is 60 MB, and the store starts with 200 of them on 12 nodes. A real store holds billions of objects of every size on thousands of nodes.
  • A whole node fails at once and loses all its data. Real failures are more often one disk, or a node that is cut off for a while and comes back with its data.
  • The nodes are not grouped. Real stores spread the pieces of an object over racks and data centres, so that one power cut cannot take several pieces.
  • A normal read takes 40 ms and a read that must rebuild a piece 160 ms. Real numbers depend on the size of the object.
  • Three nodes that fail in the same moment cost 1 object in 200 here with copies, and about 20 with pieces. An object in 6 pieces has more nodes to lose. Real stores have far more nodes and repair fast, which makes three losses at once very rare.
  • One repair job rebuilds one piece at a time. Real stores run many repairs side by side, and slow them down when clients are busy.
  • The metadata is one box that never fails. In a real store it is a database of its own, with its own copies.

Design walkthrough: Object storage (S3)

Object storage keeps files of any size under a key, such as photos/cat.jpg, and almost never loses one. You cannot edit part of a file. You replace the whole object.

Requirements

What it must do

  • Put an object under a bucket and a key.
  • Get it back by the same key.
  • List the keys in a bucket that start with a prefix.

How well it must do it

  • Durability first: a saved object must survive the loss of a disk, a server or a data centre.
  • Scale to billions of objects.
  • A new object can be read as soon as its upload succeeds.

Rough numbers

  • 1 billion objects at 1 MB on average is 1 PB of data.
  • Three full copies need 3 PB of disk.
  • Erasure coding with 6 data parts and 3 extra parts needs 1.5 PB, and survives the loss of any 3 parts.
  • The metadata is tiny next to that: 1 billion rows at 200 bytes is 200 GB.

How a request flows

Write pathUpload an object

  1. Client
  2. API servers
  3. Data node A
  4. Data nodes B and C
  5. Metadata DB
  1. Client to API servers

    The client sends PUT photos/cat.jpg. The API checks that the caller may write to this bucket.

  2. API servers to Data node A

    The API picks data nodes with free space and streams the bytes to the first one.

  3. Data node A to Data nodes B and C

    That node copies the bytes to nodes in two other zones. Each node checks the data against a checksum.

  4. API servers to Metadata DB

    Only after the copies are safe does the API save a row: bucket, key, size, checksum and where the bytes are.

  5. API servers to Client

    It answers success. The object exists from the moment its metadata row is saved.

Read pathDownload an object

  1. Client
  2. API servers
  3. Metadata DB
  4. Data node A
  1. Client to API servers

    The client sends GET photos/cat.jpg.

  2. API servers to Metadata DB

    The API looks up where the bytes are.

  3. API servers to Data node A

    It reads from any healthy copy and checks the checksum.

  4. API servers to Client

    It streams the bytes back. If a copy is damaged, it reads another copy and repairs the bad one.

Scaling it

  • Partition the metadata by bucket and key. Listing a prefix then reads one sorted range.
  • Pack many small objects into one large file on disk, so a billion tiny files do not exhaust the file system.
  • Move objects that are rarely read to cheaper, slower disks, with no manual step.

What breaks, and what happens then

  • A disk or a data node dies

    What users see
    One copy of many objects is gone.
    What the design does
    A repair job notices. It copies each object from a healthy node to a new one until three copies exist again.
  • A disk returns wrong bytes without an error

    What users see
    A read could return a damaged file.
    What the design does
    Every read checks the checksum. A background scan also reads old data again to catch damage early.
  • An upload fails half way

    What users see
    Bytes are on data nodes, but no metadata row exists.
    What the design does
    The object is not visible, because the row is written last. A cleaner deletes the leftover bytes later.

Trade-offs

  • Three full copies, or erasure coding
    A good default
    Erasure coding for large, rarely read data: half the disk for the same safety.
    What it costs
    Reads and repairs need more CPU and more network calls.
  • Write the metadata before the bytes, or after
    A good default
    After. A failed upload leaves no visible, broken object.
    What it costs
    Leftover bytes must be cleaned up.

Common mistakes

  • Treating object storage like a file system and editing files in place.
  • Putting the object bytes in the metadata database.

Questions an interviewer might ask

How does a 5 GB upload survive a bad network?

Use a multipart upload. Each part is sent and confirmed on its own, and only failed parts are sent again.

How do you list a billion keys?

Keep the keys sorted in the metadata store. Return pages of 1,000, each with a marker for the next page.

What does eleven nines of durability mean?

Store 10 million objects, and you would expect to lose one about every 10,000 years.