Avatar Upload Storage: Database vs. Object Storage

Resumen

Pixel’s announcement compares database storage with private object storage for original receipt uploads in a US or EU property-management app. It recommends storing file bytes in object storage and keeping the object key, checksum, property details, and retention dates in the database, with deletion handled as a recorded workflow.

DEV Community

User Avatar Upload Backend: Database Storage or Local Disk for US/EU Receipt Retention

Short answer: for a user avatar upload backend, keep the original property receipt in private object storage, keep its key and audit metadata in the database, and make deletion a recorded workflow rather than an incidental file operation. For a small US or EU property-management app, that arrangement usually gives the cleanest boundary between transactional data and retained evidence. The important word is original. A thumbnail is a useful interface asset; it is not the file that proves what was submitted. The upload path should preserve the source bytes, identify the tenant or property record, and make the retention decision explicit before anyone adds image processing or a second region. This is a storage decision, but it is also a records decision. I build RAG and agent features in Python, so I want an eval harness around this workflow early. I don't want a prompt to summarize a receipt and quietly become the only place where the original exists. Should a small app keep user avatar uploads in backend storage or a database? Start with two records: a database row describing the receipt and an object containing the original bytes. The row can carry property_id, submitted_by, object_key, content_type, byte_count, sha256, region, retention_until, and timestamps. The object key should be opaque enough that a user cannot choose another user's path. The database is the index and policy record; the object store is the file cabinet. That division makes a later audit answerable. Which property owns this receipt? Who submitted it? Which exact bytes were retained? When is deletion allowed, and did it happen? A checksum helps detect an accidental content change, while a retention date gives a scheduled worker something concrete to evaluate. Boundary Useful when Main cost Private object storage Multiple app processes must read the same originals A separate access, backup, and recovery policy Database blob A tiny file set must commit with its business row Larger database backups and more database I/O Local disk A one-host prototype is temporary Replacement or scale-out can separate the file from the row The table is a decision aid, not a ranking. Retention and recovery decide the boundary before monthly price does. Database blobs are still valid in a narrow case: the file set is genuinely tiny, the database backup and restore plan includes the bytes, and the receipt must be committed or deleted in the same transaction as its business row. The trade-off is that binary data now shares database I/O, backup volume, and restore time with ordinary application records. Local disk is simpler for a one-process prototype. It becomes a poor source of truth after a second process, a replacement host, or a restore enters the picture. A disk path in a database does not make the disk shared. That distinction has caused more upload bugs than the choice of object-store brand. How should receipt uploads handle retention, audit, and deletion? Use a write-then-record sequence. Validate the request, calculate the digest while reading the stream, write the original under a new key, and commit the metadata row only after the write succeeds. If the database commit fails, a retryable reconciliation job can find the orphaned object. If the object write fails, no row should claim that a receipt exists. Replacement needs the same discipline. Write the new object first, commit the new key, and delete the old object only after the new row is durable. Never reuse a key for a different receipt. This leaves a clear recovery boundary when a worker stops between steps, and it avoids confusing a cached or downloaded old file with the current record. Here is the small part I would put behind an application-specific object-storage adapter. It deliberately does not pretend that a generic example can define a provider's upload protocol. The adapter owns that detail; the retention state machine does not. from dataclasses import dataclass
from datetime import datetime, timezon...
Avatar Upload Storage: Database vs. Object Storage
Powered by Readybot.io

Lo último de Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …