ADR-005: Store book images in Blob Storage and persist only the URN
Image bytes live in Blob Storage; the database keeps a stable URN and fresh access URLs are resolved on read.
1. Context & Problem
BookEntityv1.0.0BookCanonical sellable title in the product catalog, encapsulating descriptive metadata, pricing, stock availability, taxono...Ownercatalog-experience-teamOpen docs cover images are large binary files with very different storage and delivery needs than structured catalog details like titles, prices, and descriptions. Storing image files directly inside the product database would bloat storage, slow down backups and restores, and tie transactional product operations to heavy file transfers.
At the same time, direct download links used by storefronts are intentionally time-limited for security reasons. Because those links expire, the database cannot rely on saving a temporary web address as a permanent identifier for a book’s cover image. Catalog needs a durable asset reference that survives link expiration while keeping media files outside the core database.
2. Business Value
- Leaner, faster core database: Keeping heavy image bytes out of the product database keeps catalog queries focused and reduces backup and replication size and duration.
- Independent scaling for media assets: Dedicated object storage holds and serves cover images independently of relational product queries.
- Safer image delivery: Storefronts receive short-lived, read-only access links generated on demand rather than exposing long-lived or permanent credentials.
- Durable catalog links: Each book record holds a permanent asset reference that remains valid even as temporary access links expire and rotate.
3. How It Works
When a BookEntityv1.0.0BookCanonical sellable title in the product catalog, encapsulating descriptive metadata, pricing, stock availability, taxono...Ownercatalog-experience-teamOpen docs cover image is uploaded through Catalog APIServicev1.0.0Catalog APIInternal HTTP and gRPC service for Catalog product management, hybrid discovery, and authoritative book metadata. PublishesBookUpdatedRatingFailedIntegrationEventSubscribesCreatePublisher, UpdatePublisher +24APIsOpenAPI, AsyncAPIOwnercatalog-experience-teamDiagramRepositoryOpen docs, the image file is saved to Catalog Blob StorageContainerv1.0.0Catalog Blob StorageAuthoritative Azure Blob Storage container owned by the Catalog bounded context for binary book cover images and media a...Ownercatalog-experience-teamDiagramOpen docs under a unique generated name while preserving its file type. Instead of storing the image content in Catalog DatabaseContainerv1.0.0Catalog DatabaseAuthoritative PostgreSQL system of record owned by the Catalog bounded context for books, authors, categories, publisher...Ownercatalog-experience-teamDiagramOpen docs, the book record stores only a permanent asset reference identifying where the file lives.
Whenever a client or storefront requests book details, Catalog API checks that the saved asset reference matches the active storage location and generates a fresh, read-only, time-limited access link for viewing the image. These temporary links are never written back to the database. When an image is explicitly removed—or when the book itself is deleted—Catalog API deletes both the stored image file and any saved snapshots from object storage.
Alternatives considered
- Store images directly on the book record: Keeping image files in the same database row would combine everything in one system, but it would enlarge catalog tables, slow down backup and restore operations, and mix large binary payloads into transactional product updates.
- Store images in a separate table within the product database: Separating image bytes into another relational table still traps media assets inside the database’s backup and storage footprint rather than giving object storage clean ownership of files.
- Save long-lived signed links in the database: Persisting pre-signed access links would avoid generating links on each read, but it would turn an expiring security credential into permanent product data, increasing stale-link risk and complicating security management.
4. Trade-offs & Lessons Learned
- Non-atomic updates and orphan risk: The product database and object storage do not share a single all-or-nothing transaction. If an image upload succeeds before a book update fails, an unreferenced file can remain in object storage; operational reconciliation must account for cleaning up orphaned files or repairing broken links.
- On-demand link resolution: Reading a book requires generating a fresh access link, and client applications must handle time-limited links by fetching a current book representation rather than caching image links indefinitely.
- Operational recovery rules: An expired image link does not mean the cover image is missing—fetching the book again resolves a fresh link. When moving or restoring records, teams must preserve the asset reference and restore the image under the exact same name in the configured storage location. If an image cannot be recovered, replace or remove it through Catalog APIServicev1.0.0Catalog APIInternal HTTP and gRPC service for Catalog product management, hybrid discovery, and authoritative book metadata. PublishesBookUpdatedRatingFailedIntegrationEventSubscribesCreatePublisher, UpdatePublisher +24APIsOpenAPI, AsyncAPIOwnercatalog-experience-teamDiagramRepositoryOpen docs rather than hand-editing database records.
- Storage-target coupling: Because the asset reference encodes the storage account and container, moving images between storage targets requires coordinated updates across both object storage and catalog references.
5. Technical Reference
-
Related decision: ADR-001: Use PostgreSQL as the Catalog system of recordDecision Recordv1.0.0ADR-001: Use PostgreSQL as the Catalog system of recordCatalog Database (PostgreSQL) is the single authoritative store for books, authors, categories, and publishers; cache an...Ownercatalog-experience-teamOpen docs
-
Asset identity and URN contract:
- Uploaded blobs receive a unique
UUIDv7-basedblobNameand retain their uploaded content type. - The stable reference persisted on the book record has the format
urn:{account}:{container}:{blobName}.
- Uploaded blobs receive a unique
-
Read-time SAS URL resolution:
- On book reads,
catalog-apivalidates the URN’s account and container against the configured storage target and resolves a fresh, read-only, time-limited SAS URL. - URL lifetime is controlled by
SasExpiryHours. - Generated SAS URLs are never persisted in PostgreSQL.
- On book reads,
-
Deletion behavior: Explicit image removal and book deletion remove the referenced blob and its snapshots from Azure Blob Storage.
-
Recovery rules: Preserve the URN when restoring records, restore the object under the same
blobNamein the configured account and container, or replace/remove the asset via Catalog APIServicev1.0.0Catalog APIInternal HTTP and gRPC service for Catalog product management, hybrid discovery, and authoritative book metadata. PublishesBookUpdatedRatingFailedIntegrationEventSubscribesCreatePublisher, UpdatePublisher +24APIsOpenAPI, AsyncAPIOwnercatalog-experience-teamDiagramRepositoryOpen docs rather than manually editing PostgreSQL.