Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 4 of 6 · Concept · 15 min · revision 1

Blobs in object storage, metadata in a database

Decide which data belongs in object storage and which in a database, keep the two consistent with status rows and a reconciliation job, and choose storage classes, lifecycle rules and durability settings for each kind of file.

Contentsand lesson path

What you will learn

  • Decide which data belongs in object storage rather than a database, choosing storage class, lifecycle and durability settings while keeping queryable metadata in a database.

01. Why it matters

In lesson 1, delivery photos were 49 writes per second but 560 GB a day, about 99% of all the bytes of the parcel service, and almost never read. Files like these are blobs (binary large objects). Kept in a database, they slow backups, replicas and caches; kept on application servers, they disappear with the server. Why files do not belong on the API server's disk explains both problems, and the presigned URL lab builds the upload path.

This lesson makes the storage decisions around that path: what goes into object storage and what does not, how the database and the object store stay consistent, and which storage class, lifecycle rules and durability settings each kind of file needs.

02. What belongs in object storage, and what does not

Object storage (Amazon S3, Google Cloud Storage, Azure Blob Storage, or compatible servers you run yourself) keeps whole objects under keys. It suits data that is:

  • large, from tens of kilobytes to many gigabytes;
  • written once and replaced whole, rather than edited in small pieces;
  • read by key, without queries into its contents;
  • kept for a long time, often with a rule about when it moves to cheaper storage or is deleted.

A database suits the opposite: small records that change often, are updated in part, are found by queries on their fields, or must change together with other records. Most object stores, such as S3 general purpose buckets and Google Cloud Storage, replace a whole object on every write (a few products also allow appends), charge per request as well as per gigabyte, and cannot update several keys atomically. If two clients write the same key at the same time, the write with the later timestamp wins.

So each photo is split in two. The bytes go to object storage under a key such as photos/2026/11/17/p-1001.jpg. A metadata row goes to the database: parcel id, object key, size, checksum, content type, status, who took it and when. Every question the application asks, such as "photos for parcel P" or "photos still pending after an hour", is a query on that table. Listing keys by prefix is not a substitute: it cannot filter on fields, and it is slow on large buckets.

S3 has given strong read-after-write consistency since December 2020: after a successful write or delete, any read or list that starts afterwards sees the change. This holds in every AWS Region, but a copy replicated to another region still lags. Older advice to wait or retry before reading a new object no longer applies there. What it does not give you is a transaction that covers both the database row and the object.

03. The upload and download paths

The usual flow has the client send bytes straight to object storage with a presigned URL: a URL signed with the application's credentials that allows one operation on one key until it expires. The application never streams the file itself, but it records every step in the metadata row:

Sequence · photo upload and download
client                 API and database                      object storage
  | 1 POST /photos       |                                         |
  |--------------------->| insert row (status = pending)           |
  |<---------------------| presigned PUT URL, valid 15 minutes     |
  | 2 PUT the bytes ------------------------------------------------>|
  | 3 POST /photos/{id}/complete                                   |
  |--------------------->| HEAD the object: size and checksum ---->|
  |                      | update row (status = ready)             |
  | 4 GET /photos/{id}   |                                         |
  |--------------------->| check access, presign GET (5 minutes)   |
  |<---------------------| redirect to the URL                     |
  | 5 GET the bytes <------------------------------------------------|

A presigned URL is a bearer token: anyone who holds it can use it until it expires. Keep expiry short, check access before signing a download, and remember that the URL can never outlive the credentials that signed it. AWS documents a maximum of 7 days for Signature Version 4 URLs, and a URL signed with temporary role credentials stops working when those credentials expire.

04. Keeping the row and the object consistent

Because no transaction spans both stores, failures leave two kinds of mismatch. An orphan is an object with no row: storage you pay for that nobody can find. A dangling reference is a row that points at a missing object: a broken image for the user. Order the steps so that a failure leaves the harmless kind. Insert the row as pending before the upload, mark it ready only after the object is confirmed, and on delete, mark the row first and remove the bytes afterwards.

Then let a reconciliation job compare the two sides regularly and repair what failed. At scale it reads a daily inventory report of the bucket instead of listing millions of keys. Here is the logic on a small fixed example; save it as reconcile.py:

Python · reconcile.py
"""Compare metadata rows with an object listing and decide what to fix (Python 3.12)."""
from datetime import datetime, timedelta

NOW = datetime.fromisoformat("2026-11-17T08:00")
GRACE = timedelta(hours=24)  # uploads younger than this may still be in flight

# Export of the photos table: object key -> (status, row created at).
rows = {
    "photos/p-1001.jpg": ("ready", "2026-11-16T09:00"),
    "photos/p-1002.jpg": ("ready", "2026-11-16T09:02"),
    "photos/p-1003.jpg": ("pending", "2026-11-16T07:30"),
    "photos/p-1004.jpg": ("pending", "2026-11-17T07:55"),
    "photos/p-1005.jpg": ("pending", "2026-11-16T10:10"),
    "photos/p-1006.jpg": ("deleted", "2026-11-10T12:00"),
}
# Object listing (an inventory report or a LIST call): key -> last modified.
objects = {
    "photos/p-0999.jpg": "2026-11-15T18:20",
    "photos/p-1001.jpg": "2026-11-16T09:00",
    "photos/p-1005.jpg": "2026-11-16T10:11",
    "photos/p-1006.jpg": "2026-11-10T12:00",
    "photos/p-1007.jpg": "2026-11-17T07:58",
}


def age(stamp: str) -> timedelta:
    return NOW - datetime.fromisoformat(stamp)


print(f"{'object key':<19}{'row':<9}{'obj':<5}action")
for key in sorted(rows.keys() | objects.keys()):
    status, created = rows.get(key, (None, None))
    has_object = key in objects
    if status == "ready" and not has_object:
        action = "DANGLING: row points at nothing; hide it, alert"
    elif status == "pending" and has_object:
        action = "finish: verify size and checksum, mark ready"
    elif status == "pending" and age(created) > GRACE:
        action = "expire: upload abandoned, delete the row"
    elif status == "pending":
        action = "wait: the upload may still be running"
    elif status == "deleted" and has_object:
        action = "delete object: its row was deleted"
    elif status is None and age(objects[key]) > GRACE:
        action = "ORPHAN: no row after 24 h; delete the object"
    elif status is None:
        action = "wait: too new to judge, check on the next run"
    else:
        action = "ok"
    print(f"{key:<19}{status or '-':<9}{'yes' if has_object else 'no':<5}{action}")
Terminal
python3.12 reconcile.py
Expected output
object key         row      obj  action
photos/p-0999.jpg  -        yes  ORPHAN: no row after 24 h; delete the object
photos/p-1001.jpg  ready    yes  ok
photos/p-1002.jpg  ready    no   DANGLING: row points at nothing; hide it, alert
photos/p-1003.jpg  pending  no   expire: upload abandoned, delete the row
photos/p-1004.jpg  pending  no   wait: the upload may still be running
photos/p-1005.jpg  pending  yes  finish: verify size and checksum, mark ready
photos/p-1006.jpg  deleted  yes  delete object: its row was deleted
photos/p-1007.jpg  -        yes  wait: too new to judge, check on the next run

Each line is a different failure. The orphan is a leftover from a failed or abandoned flow, older than the grace period. The dangling row should not happen in normal operation with this ordering, so it raises an alert as well as hiding the photo. A pending row with its object only missed the completion call, so the job finishes it after verifying size and checksum. The grace period stops the job from deleting uploads that are still running.

05. Storage class, lifecycle and durability

A storage class sets price, retrieval speed and resilience for each object. The main S3 classes, as documented in November 2026:

Reference · S3 storage classes (check current pricing for your region)
S3 class              zones  minimum   minimum billed     first byte      fits
                             duration  object size
Standard              3+     none      none               milliseconds    active data
Standard-IA           3+     30 days   128 KB             milliseconds    rarely read
One Zone-IA           1      30 days   128 KB             milliseconds    re-creatable
Glacier Instant       3+     90 days   128 KB             milliseconds    about once
  Retrieval                                                               a quarter
Glacier Flexible      3+     90 days   +40 KB metadata    minutes-hours   archives
  Retrieval                            per object
Glacier Deep Archive  3+     180 days  +40 KB metadata    hours           rarely needed
                                       per object                         archives
Retrieval fees apply to the IA and Glacier classes. All are designed for 99.999999999%
durability; One Zone-IA does not survive the loss of its availability zone.

Three details catch people out. Infrequent-access and Glacier Instant Retrieval classes bill at least 128 KB per object and a minimum storage duration, so small or short-lived objects can cost more there than in Standard. By default, lifecycle rules do not move objects smaller than 128 KB at all, unless a size filter allows it; for the infrequent-access classes this was already so before September 2024, when the default was extended to the archive classes. And the archive classes need a restore, taking minutes to hours, before an object can be read.

Two more classes are worth knowing. S3 Intelligent-Tiering moves each object between access tiers by itself, for a small monitoring fee per object and no retrieval fees, which suits unknown or changing access; objects under 128 KB are not monitored and stay in its frequent tier. S3 Express One Zone keeps data in a single zone for the lowest latency.

A lifecycle configuration applies these choices automatically, to existing objects as well as new ones. For delivery photos, which are read for disputes for two years and then must be deleted for privacy, it can look like this:

XML · lifecycle.xml (S3 lifecycle configuration)
<LifecycleConfiguration>
  <Rule>
    <ID>delivery-photos</ID>
    <Filter>
      <Prefix>photos/</Prefix>
    </Filter>
    <Status>Enabled</Status>
    <Transition>
      <Days>30</Days>
      <StorageClass>STANDARD_IA</StorageClass>
    </Transition>
    <Transition>
      <Days>120</Days>
      <StorageClass>GLACIER_IR</StorageClass>
    </Transition>
    <Expiration>
      <Days>730</Days>
    </Expiration>
    <NoncurrentVersionExpiration>
      <NoncurrentDays>30</NoncurrentDays>
    </NoncurrentVersionExpiration>
  </Rule>
  <Rule>
    <ID>abandoned-multipart-uploads</ID>
    <Filter>
      <Prefix></Prefix>
    </Filter>
    <Status>Enabled</Status>
    <AbortIncompleteMultipartUpload>
      <DaysAfterInitiation>7</DaysAfterInitiation>
    </AbortIncompleteMultipartUpload>
  </Rule>
</LifecycleConfiguration>

The first rule moves photos down as reads drop and deletes them after 730 days. Because the bucket uses versioning, the expiry leaves a noncurrent version, which is removed 30 days later. The second rule removes the parts of multipart uploads that were never finished; without it they are billed until the upload is aborted, and they do not show up when you list objects.

Durability settings answer a different question. The designed durability of these classes describes losing stored objects to hardware failure. It says nothing about a bug or a person deleting or overwriting an object. Versioning keeps old versions so that you can recover from such mistakes, Object Lock prevents deletion or overwriting for a set period (write once, read many), and replication copies objects to a bucket in another region in case a whole region fails. One Zone classes are cheaper because they keep data in one availability zone, so AWS recommends them for data you can re-create.

06. Check your understanding

Practice check · 3 questions

Choosing where blobs live

Three new situations. Use the class and lifecycle rules above, not the parcel numbers.

Q1. A lifecycle rule moves the objects in a thumbnails bucket to S3 Standard-IA after 30 days. Two months later the thumbnails, about 20 KB each, are all still in S3 Standard. What explains this?
Q2. A video app stores each upload's original and six encoded renditions. Renditions can be rebuilt from the original in a few hours and are rarely watched after the first month. Which storage choice fits after that first month?
Q3. A shop keeps each shopper's cart as a 3 KB JSON object. It is read on every page view and changed about 20 times per session. Where should the carts live?
Practice only: not graded, not saved, not evidence.

07. Apply it

For the product images and chat images of your marketplace:

  1. Write the metadata table: columns, statuses, and the queries the app runs on it.
  2. Draw the upload and download flow with presigned URLs, and say what the job does for each mismatch it can find.
  3. Choose a storage class per age and a lifecycle configuration, checking minimum sizes and durations against your object sizes.
  4. Decide on versioning, Object Lock and cross-region replication, and justify each against what losing the images would cost.

08. Review prompt

Without looking back, answer in your own words:

  1. Which four properties make data a good fit for object storage, and what goes into the metadata row instead?
  2. What are orphans and dangling references, which ordering makes failures harmless, and what does the reconciliation job add?
  3. Why can a lifecycle rule leave small objects where they are, and why might moving them cost more?
  4. Why is designed durability not a backup, and which settings protect against your own mistakes?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check