Identity image storage: MariaDB first, S3 as an operator opt-in
- Deciders: Julian Bäume
- Date: 2026-09-14
Status
Accepted
Context
Booking page appearance (issue #8) lets a page owner show an image: either a snapshot of their App Suite contact picture, or a logo they upload for a separate identity. Before this, the service stored no binary data at all. Its persistence is MariaDB through plain SQL (ADR-0004), and @open-xchange/fastify-sdk offers no object-storage plugin.
The images are small. The editor rasterises and downscales in the browser to a longest edge of 1024px and the service caps an upload at 512 KiB, so a fully branded deployment with ten thousand pages holds around 5 GB at the theoretical maximum and far less in practice.
Three things about the environment shaped the decision:
There is no house S3 client. ui-service uses the minio package, glam uses @aws-sdk/client-s3 with a presigner, and the middleware uses the AWS Java SDK. There is a house pattern for credentials: ui-service's chart takes s3.{endpoint,bucketName,createBucket,auth.{existingSecret,userSecretKey,passwordSecretKey}}, and every S3 consumer in the dev, e2e and preview clusters is fed by Garage through a GarageBucket plus a GarageKey secret. Booking's own preview chart already stands one up.
There is a direct precedent for the shape, in cop. The Cloud Onboarding Portal takes customer-uploaded brand images, puts them in S3, serves them through a separate nginx, and skips the upload with a warning when the bucket variables are unset. That is the opt-in behaviour an operator would expect here too.
The middleware itself keeps contact pictures in the database, in prg_contacts_image, rather than in the context filestore. The thing we are copying is already stored the way we are proposing to store it.
Against that, an object store is the conventional answer for user-uploaded binaries, and some operators will want one: their database backups are not sized for blobs, or they already run S3 and would rather have one place for files.
Decision
Store the bytes in MariaDB now, behind an interface, with the backend recorded per row.
identity_image.datais aMEDIUMBLOBin its own table, not a column onappointment_type. Every column of that row is selected on list, slot derivation and booking create; a blob there would ride along on all of them.src/services/image-store.tsdefinesImageStorewithput,readandremove, in terms of a key and bytes. It knows nothing about appointment types, identities or branding, so it can move to the SDK the day a second service needs it.dbImageStoreis the only implementation.Writes pick the backend from config (
identityImageStorage, defaultdb); reads pick it from the row's ownstoragecolumn. This is the load-bearing part. An operator who later switches to S3 changes only what happens next: every image written before the switch keeps being served from where it actually is. There is no flag day, no backfill blocking a release, and a backfill becomes an optional maintenance job.The S3 backend, when it lands, uses
@aws-sdk/client-s3and theui-servicechart values shape, includingauth.existingSecretwithuserSecretKey/passwordSecretKey. The object key is the appointment type id, which the 1:1 ownership rule makes unique without inventing an identifier.
Of those four, the credential convention and the per-row backend are the commitments worth holding to. The client library is the weakest: minio is considered deprecated here and @aws-sdk/client-s3 matches the most recent choice in the organisation, but nothing in the seam depends on it.
Consequences
Booking gains user-uploaded binaries without gaining infrastructure. A deployment that does nothing gets working branding; a deployment that wants object storage gets it in an additive MR, chart values included.
Database size grows with branded pages. The retention answer is structural rather than operational: identity_image has a unique foreign key to appointment_type with ON DELETE CASCADE, so an image cannot exist without its page and cannot outlive it. There is no orphan sweep and no age-based expiry to get wrong, and deleting an account takes its images with it.
Serving bytes out of MariaDB puts the database on the path of an unauthenticated public request. The route answers with an ETag and a five-minute Cache-Control with a long stale-while-revalidate window, and the ?v= cache buster changes with the checksum, so a popular page is served from caches rather than from the pool. If that ever stops being true, it is an argument for turning the S3 switch on, which is what the switch is for.
Booking is the first web-foundation Fastify service to store user uploads, so the upload route, the header validation and the serving route are its own code for now. Moving image-store.ts into @open-xchange/fastify-sdk is the right call once a second service needs it, and the interface was kept domain-free so that move is a move rather than a rewrite.
Alternatives considered
S3 from the start. Correct destination, wrong order. It would have added a bucket, credentials, chart wiring and a client dependency to a feature that works without any of them, and it would have made issue #8 wait on infrastructure it does not need.
The middleware filestore. It is the platform's answer for user files, and the middleware already uses it for Drive and attachments. But reaching it means acting on a user's behalf, and there is no impersonation path available to this service; the filestore is also context-bound and quota-accounted in ways a service-owned asset is not.
A blob column on appointment_type. Simplest schema, worst hot path. Rejected on the mapAppointmentType argument above.
An images table keyed by owner, referenced by pages. This was the first draft. It needed ON DELETE SET NULL, a reference count or an orphan sweep, and an answer to "when does a former owner's photograph leave the database". Reversing the pointer so the image belongs to exactly one page deleted all four questions at once.

