Menu
Dev.to #architecture·November 28, 2026

Designing Object Storage for Avatar Management with Strong Data Retention and Compliance

This article discusses the architectural considerations for managing user avatars and other tenant-specific assets using object storage, focusing on robust data retention, deletion, and export processes. It emphasizes the need for application-owned metadata to control the lifecycle of objects, ensuring compliance and data integrity over simple bucket-based rules. The core principle advocates for treating the original asset as authoritative and derived assets as disposable, with all state transitions recorded in a database.

Read original on Dev.to #architecture

When choosing between a managed image service and raw object storage for application assets like user avatars, the primary architectural driver should be lifecycle control and data retention requirements, not just cost. For applications requiring strong compliance, tenant data exports, and auditable deletion processes, an application-centric approach to object management using object storage is crucial. This contrasts with simpler scenarios where transformations are the main concern and provider-managed lifecycles suffice.

Application-Owned Metadata as the Source of Truth

The article strongly advocates for the application database to be the authoritative source for object metadata and state transitions. While object stores handle the payload, the application must manage retention, deletion, and export policies. Key invariants include:

  • No thumbnail may exist without an original asset record.
  • An export manifest is a frozen list of asset IDs and checksums, not a live prefix listing.

This approach ensures that operations like tenant exports or deletions are consistent and auditable, preventing silent data omissions or untracked derived objects. It acknowledges that an object store cannot provide database transactions across objects, rows, and jobs, hence the need for application-level coordination.

Designing for Idempotent Operations

Achieving exactly-once effect for uploads, thumbnail generation, exports, and deletions is vital in distributed systems. This requires robust application logic, as exactly-once delivery is often not guaranteed across clients, databases, and object services. For uploads, clients should receive an upload intent ID, bound to a tenant and expected checksum, rejecting reuse with different bytes to ensure a second logical asset isn't created on retry. Thumbnail generation should consume outbox events with a compare-and-swap update pattern, ensuring consistent results even if events are processed multiple times.

💡

Idempotency for Deletion

Deletion operations should be designed to be idempotent. This means recording a `CommandID` in the database before issuing object deletes. A deletion worker should load keys from the asset record, delete derived variants before the original, and record an outcome. Repeated commands should resume unfinished entries or return recorded results, ensuring the externally visible effect is a single logical deletion.

Retention as a State Machine

Instead of relying solely on age-based bucket lifecycle rules, applications should implement an explicit state machine for object retention (e.g., `active`, `delete_requested`, `held`, `deleted`). This allows the system to track user-authorized deletions, derived object relationships, legal holds, and specific policy identifiers with effective dates. This granularity is essential for compliance and resolving complex scenarios, such as when an export request conflicts with a deletion request, ensuring the application explicitly defines and records the policy decision.

go
package assets

import (
	"context"
	"io"
)

type ObjectStore interface {
	Put(ctx context.Context, key string, body io.Reader, checksum string) error
	Get(ctx context.Context, key string) (io.ReadCloser, error)
	Delete(ctx context.Context, key string) error
}

type Asset struct {
	TenantID string
	AssetID string
	OriginalKey string
	ThumbnailKeys []string
	Checksum string
	RetentionClass string
}

type DeleteCommand struct {
	CommandID string
	TenantID string
	AssetID string
	Reason string
}

This Go interface example demonstrates a simplified contract for an `ObjectStore` adapter and associated data structures for `Asset` and `DeleteCommand`. The `ObjectStore` interface exposes basic `Put`, `Get`, and `Delete` operations, abstracting away vendor-specific details. The `Asset` struct captures metadata like `TenantID`, `AssetID`, `Checksum`, and `RetentionClass`, highlighting the application's role in managing these attributes. The `DeleteCommand` includes a `CommandID`, underscoring the idempotency requirement for deletion requests.

object storagedata retentionidempotencydata lifecyclecomplianceavatarsasset managementmicroservices

Comments

Loading comments...