Storage and media
Object storage, uploads, and delivering video without paying for it twice.
Object storage versus databases and disks
beginnerObject storage holds immutable blobs addressed by key, with effectively unlimited capacity, eleven nines of durability in the major services, and a cost per gigabyte an order of magnitude below block storage. It is not a filesystem: there are no directories, only keys that contain slashes, and there is no partial update, only replacing an object wholesale. Putting files in a database instead inflates every backup, slows every replica, and spends expensive storage on bytes that no query will ever filter on. The standard shape is the file in object storage and its metadata in the database: key, size, owner, content type, checksum. That split keeps the database small enough to restore quickly, which is the property you care about on the day it matters.
Storage classes are where the money is. Hot storage for what is served, infrequent access for what is occasionally read, archival tiers for what is kept because someone must. The archival tiers are dramatically cheaper per gigabyte and charge for retrieval and for a minimum storage duration, so moving the wrong data there costs more than leaving it. Lifecycle rules automate the transition by age, and setting one up is usually the largest single saving on a storage bill.
The costs that surprise people are not storage at all. Egress is charged per gigabyte leaving the provider and is frequently the largest line, which is why a CDN in front of a bucket pays for itself twice over: it cuts latency and it cuts the number of times the same object leaves the origin. Request charges matter too when the objects are small: a million tiny objects costs more in requests than in bytes.
Consistency is no longer the trap it was. S3 has offered strong read-after-write consistency since December 2020, so an object is readable immediately after it is written, and the elaborate workarounds built for the old model can be deleted. Versioning is worth enabling deliberately, because it turns an accidental overwrite from a data loss incident into a lookup, and because it is what makes deletion recoverable.
The rule that survives all of it: store what you query in the database and what you serve in object storage. Blobs in Postgres make every operational task on that database slower forever, and the pain is paid at restore time, when it is least welcome.
Which line on an object storage bill most often surprises teams?
Evidence · 1 source
- 01AWS: Amazon S3 strong consistency
That S3 provides strong read-after-write consistency for all requests, delivered in December 2020.
Answers are generated and can be wrong. The topic above is the reviewed version.
Direct uploads with pre-signed URLs
intermediateRouting uploads through your API means large files consume your bandwidth, your memory, your request timeouts and your autoscaling budget, to nobody's benefit. A single 2GB upload can occupy a worker for minutes, and a handful of them at once will exhaust a service sized perfectly well for its actual work.
A pre-signed URL removes the problem rather than solving it. Your server authorises the upload and returns a time-limited URL; the client sends the bytes straight to object storage. The signature encodes what may be uploaded, to which key, until when, so the permission is narrow and expiring rather than a credential handed to a browser.
The constraints belong in the signature, not in a check afterwards. Sign a specific key so a client cannot choose where the object lands, set a content length range so nobody uploads a hundred gigabytes, pin the content type, and keep the expiry short, minutes rather than hours. Anything you fail to constrain is something the holder of that URL may do.
Completion has to be discovered rather than trusted. The client telling your API that it finished is a claim, and a malicious or merely buggy client can make it without uploading anything. The reliable signal is an event from the storage service itself, which is also what lets you verify size, type and checksum before treating the object as real.
Two more things worth building in. Multipart upload splits a large file into parts that upload in parallel and resume individually, which is what makes uploads survive a mobile connection; incomplete multipart uploads then linger and are billed, so a lifecycle rule to abort them after a few days belongs in the same change. And validate the content rather than the extension, because a file named image.png that contains something else is the oldest trick in the list.
The result is an API that stays small and fast because the large payloads never touch it. That is the general shape worth recognising: the best way to scale a piece of work is often to arrange for it not to arrive.
Which constraint must be inside the signature rather than checked afterwards?
Evidence · 1 source
- 01AWS: uploading objects with presigned URLs
That the signature encodes the key, expiry and conditions, so the permission is narrow and expiring rather than a credential handed to a browser.
Answers are generated and can be wrong. The topic above is the reviewed version.
Video: transcoding and adaptive bitrate
advancedAn uploaded video is transcoded into a ladder of resolutions and bitrates, then split into segments of a few seconds each, with a manifest listing what exists. The manifest is the whole protocol: the player reads it, decides which rendition to fetch next, and asks for one segment at a time over ordinary HTTP, which is why every CDN can serve video without knowing anything about video.
The player measures throughput and switches renditions between segments, so a connection that degrades produces lower quality rather than a stall. That is adaptive bitrate, and it is the reason streaming survives a train tunnel when a single progressive MP4 does not. HLS and DASH differ in details and agree on this design.
Transcoding is expensive and it is paid once per title against a saving on every playback, which is why it is worth doing carefully. A fixed ladder applied to every video is wrong in both directions at once: it wastes bits on an animation with flat colour and starves a grainy night scene. Per-title and per-shot encoding measure the content and choose the ladder for it, and Netflix has published savings in the region of 30 per cent at equal quality from exactly that.
The startup sequence is what users judge, and it is a specific engineering problem rather than a consequence of good encoding. Start on a low rendition so playback begins quickly, then climb once throughput is known. Keep the first segments short so the first frame arrives sooner. Preload the manifest and the first segment when intent is obvious. Time to first frame is the metric that correlates with abandonment, not average bitrate.
Live is a different problem wearing the same clothes. Segment duration sets the floor on latency, since a segment cannot be served until it exists, so ordinary HLS sits several seconds behind. Low-latency variants deliver partial segments to cut that, at the cost of more requests and more complexity in the packager, and the question to ask is whether the product needs seconds or needs to be honest that it does not. Then storage and rights. Every rendition of every title is another copy, so a ladder of six renditions is six times the storage before any language or subtitle variant. Digital rights management adds licence servers and encrypted segments, and it is a business requirement rather than a technical one, which is worth saying out loud because it is the part that most complicates an otherwise clean pipeline.
Which metric best predicts whether a viewer abandons before watching?
Evidence · 1 source
- 01Netflix TechBlog, Dynamic optimizer (2018)
The reported bitrate reductions at equal VMAF from measuring the content rather than applying a fixed ladder: 28.04 per cent for x264, 37.61 for libvpx VP9 and 33.51 for x265.
Answers are generated and can be wrong. The topic above is the reviewed version.