Healthtech AI Image Generation App Storage: Private Originals, Variants, and Cleanup
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Short answer: treat originals, thumbnails, variants, and export files as governed records with different owners, keep the bucket private, and make signed links the final authorization step rather than the storage model. For a healthtech application that stores AI-generated product images, the most expensive storage mistake is usually a governance mistake: a thumbnail is treated as the source, a tenant can retain an export after access is revoked, or a cleanup rule deletes bytes before the product knows what they mean.
简短回答:将原始文件、缩略图、变体和导出文件视为由不同所有者管理的受控记录,保持存储桶私有,并使签名链接成为最终的授权步骤,而不是依赖存储模型本身。对于存储 AI 生成产品图像的医疗科技应用而言,最昂贵的存储错误通常是治理错误:例如将缩略图视为源文件、租户在访问权限被撤销后仍保留导出文件,或者清理规则在产品识别出数据含义之前就删除了字节。
Large-file throughput matters, but it only matters after the system can prove which bytes belong to which tenant and which state transition authorized them. This runbook uses reliability and migration as the decision axis. It is aimed at a platform team that has to own the SLO, the on-call burden, and the evidence trail when a customer asks where an image came from. The exact object-store product can vary; the contracts below should not.
大文件吞吐量固然重要,但只有在系统能够证明哪些字节属于哪个租户,以及哪些状态转换授权了这些字节后,它才有意义。本手册以可靠性和迁移作为决策轴。它旨在帮助平台团队承担 SLO(服务等级目标)、值班负担,并在客户询问图像来源时提供证据链。具体的对象存储产品可以更换,但下述契约不应改变。
Start with an asset ledger, not a bucket layout. Every durable image needs a database record before it becomes visible to a user. At minimum, the record should carry tenant ID, asset ID, object key, content type, byte count, dimensions, generation state, checksum, and retention class. Store prompt, model, catalog status, and creator as searchable metadata in the database. Object listing is not a query index.
从资产分类账开始,而不是从存储桶布局开始。每张持久化图像在对用户可见之前,都需要一条数据库记录。记录至少应包含租户 ID、资产 ID、对象键、内容类型、字节数、尺寸、生成状态、校验和以及保留类别。将提示词、模型、目录状态和创建者作为可搜索的元数据存储在数据库中。对象列表并非查询索引。
Use distinct object classes even if they share one private bucket: Class | Example key | What it means | Retention owner Original | originals/tenant-17/asset-8c1/source.png | The source that may be needed for regeneration | Asset and recovery policy Approved variant | variants/tenant-17/asset-8c1/2048.webp | A durable presentation or export form | Asset state Thumbnail | thumbnails/tenant-17/asset-8c1/256.webp | A replaceable derivative | Derivative policy Work file | work/tenant-17/job-52/part-0007 | An intermediate attempt | Job expiry policy
即使共享同一个私有存储桶,也要使用不同的对象类别: 类别 | 示例键 | 含义 | 保留所有者 原始文件 | originals/tenant-17/asset-8c1/source.png | 可能需要用于重新生成的源文件 | 资产与恢复策略 已批准变体 | variants/tenant-17/asset-8c1/2048.webp | 持久化的展示或导出形式 | 资产状态 缩略图 | thumbnails/tenant-17/asset-8c1/256.webp | 可替换的衍生品 | 衍生品策略 工作文件 | work/tenant-17/job-52/part-0007 | 中间尝试文件 | 作业过期策略
An object key is a locator, not a permission. Authorization still belongs in the application, where the tenant relationship and asset state can be tested. A signed URL should identify one object or one completed export, never an arbitrary prefix. The browser should receive it only after the application has checked tenant membership, asset visibility, and link expiry policy.
对象键只是一个定位符,而非权限。授权应始终保留在应用程序中,以便测试租户关系和资产状态。签名 URL 应标识单个对象或单个已完成的导出,绝不能指向任意前缀。只有在应用程序检查了租户成员资格、资产可见性和链接过期策略后,浏览器才能接收该 URL。
Keep the state transitions explicit: uploaded, generated, approved, withdrawn, exporting, complete, and expired are examples of states, not a license to let a lifecycle rule infer meaning from age. A thumbnail can be regenerated. An original may be the only input for a later model run. A work file belongs to an attempt. Those are different operational obligations.
保持状态转换明确:已上传、已生成、已批准、已撤回、导出中、已完成和已过期是状态的示例,而不是让生命周期规则根据时间推断含义的许可。缩略图可以重新生成。原始文件可能是后续模型运行的唯一输入。工作文件属于某次尝试。这些是不同的运营义务。
What should an image generation app verify before moving originals, thumbnails, and variants? Migration is where a tidy storage pattern meets real data. Before changing prefixes, bucket settings, or retention rules, build a report-only reconciler that compares the asset ledger with object inventory. It should count missing objects, unowned objects, objects in the wrong class, duplicate checksums, and exports whose snapshot points at an asset that is now withdrawn.
图像生成应用在移动原始文件、缩略图和变体之前应该验证什么?迁移是将整洁的存储模式与真实数据结合的过程。在更改前缀、存储桶设置或保留规则之前,构建一个仅报告的对账工具,用于比较资产分类账与对象清单。它应统计缺失的对象、无主对象、类别错误的对象、重复的校验和,以及快照指向已撤回资产的导出文件。
In a real cutover, the dangerous record is not the obvious missing file; it is the apparently healthy object that has the wrong tenant in its ledger row, because a copy job can preserve bytes and still widen access. A second trap is a thumbnail regenerated between inventory and migration: if the worker uses a mutable “latest” reference, the new ledger can point to bytes that were never part of the original asset state.
在实际切换中,危险的记录不是显而易见的缺失文件,而是分类账行中租户归属错误的“健康”对象,因为复制作业可能会保留字节但扩大了访问权限。第二个陷阱是在清单生成和迁移之间重新生成的缩略图:如果工作进程使用可变的“最新”引用,新的分类账可能会指向从未属于原始资产状态的字节。
Freeze the source reference, copy by stable asset ID, and make the verification record carry the source checksum, destination checksum, and state version. That gives the on-call engineer something stronger than “the copy returned success” when a customer asks which image was exported. Do not make deletion the first migration write. Require every candidate action to include tenant ID, object class, age, checksum when available, database reference, export reference, and the reason it is eligible.
冻结源引用,按稳定的资产 ID 进行复制,并确保验证记录包含源校验和、目标校验和以及状态版本。当客户询问导出了哪张图像时,这能为值班工程师提供比“复制成功”更有力的证据。不要将删除作为迁移的第一个写入操作。要求每个候选操作都包含租户 ID、对象类别、存续时间、可用时的校验和、数据库引用、导出引用以及符合操作条件的理由。
An unexplained ownership mismatch is a stop signal. This report is also useful during an incident because it separates a missing byte from a missing database relationship. Pause here. A safe migration has a narrow write path: copy one object, verify its checksum and metadata, write the new ledger reference, then mark the old object as a candidate for later removal. The application should read from the new reference only after the verification record exists.
无法解释的所有权不匹配是停止信号。此报告在事故期间也很有用,因为它能区分缺失的字节和缺失的数据库关系。在此暂停。安全的迁移具有狭窄的写入路径:复制一个对象,验证其校验和与元数据,写入新的分类账引用,然后将旧对象标记为稍后删除的候选对象。应用程序应仅在验证记录存在后才从新引用中读取数据。
If the copy is interrupted, retry by stable asset ID; do not create a second customer-visible asset because a worker restarted. Here is the core boundary in Go. The storage adapter owns streaming and checksum verification; the caller owns the already-authorized migration plan. The adapter must still validate every reference, because a caller-side filter is not a tenant isolation control.
如果复制中断,请按稳定的资产 ID 重试;不要因为工作进程重启而创建第二个对客户可见的资产。以下是 Go 语言中的核心边界。存储适配器负责流式传输和校验和验证;调用者负责已授权的迁移计划。适配器仍必须验证每个引用,因为调用者端的过滤器不能作为租户隔离控制。
package main
import (
"context"
"fmt"
"io"
)
type ObjectRef struct {
TenantID string
Key string
}
type ObjectStore interface {
Open(ctx context.Context, tenantID, key string) (io.ReadCloser, error)
}
type ObjectWriter interface {
Put(ctx context.Context, tenantID, key string, src io.Reader) error
}
func migrateObject(ctx context.Context, store ObjectStore, writer ObjectWriter, ref ObjectRef) error {
if ref.TenantID == "" || ref.Key == "" {
return fmt.Errorf("invalid object reference")
}
body, err := store.Open(ctx, ref.TenantID, ref.Key)
if err != nil {
return fmt.Errorf("open %s: %w", ref.Key, err)
}
defer body.Close()
if err := writer.Put(ctx, ref.TenantID, ref.Key, body); err != nil {
return fmt.Errorf("write %s: %w", ref.Key, err)
}
return nil
}
In production, Put should write to a migration-specific destination and return verified size and checksum metadata. The example leaves that provider detail behind the interface on purpose. The ledger update must be idempotent, and a second attempt must converge on the same destination rather than append another variant. Signed links are a delivery con
在生产环境中,Put 应写入迁移特定的目标,并返回已验证的大小和校验和元数据。示例特意将这些提供程序细节隐藏在接口之后。分类账更新必须是幂等的,第二次尝试必须收敛到同一个目标,而不是追加另一个变体。签名链接是一种交付手段。