DEV Community

codegabru
codegabru

Posted on

How do big companies effectively store and serve video (over a CDN) - I don't get the math

I am building a course hosting website - I want my users to be able to upload videos which their students will stream. This is how I plan to do it but I don't get the math behind this. I'm surely missing something.

  1. How do I store the video? - AFAIK rn I can use the cheapest object storage anything like S3, GCP etc. = $0.005/GB being the cheapest option.
  2. How do I serve those videos? AFAIK rn I can use a CDN that will cache the videos on the edge and serve it to the students = ~ 0.05/GB being the cheapest option.

Now let's suppose a teacher uploads a 30 min 1080p video that 10000 students will watch.

Size of vid ~ 1.5GB
Object storage cost = 0.0075

As 10k students will watch it - then data that will go through the CDN = 15000GB

At that 0.05/GB the CDN pricing will be - 15000GB x 0.05/GB = $750

This is unaffordable, obviously, for anyone hosting and serving the video.

There is definitely something that I'm missing here (almost ready to feel dumb after this is solved). Or is this how much it actually costs?

UPDATE: Cloudflare Stream seems to cut the price to $350 for our case. Still pretty expensive.

Top comments (9)

Collapse
 
harveyhalwin profile image
Heinek Halwin

I'm guessing that when you're handling huge data. It would be better if you set up your own data center or servers, that way you're not paying for storing the video. You could then use cloudfront network to cache the content at different edge locations as more and more people use it. So content will load up faster for the next users.

Collapse
 
codegabru profile image
codegabru

Storage cost is negligible - $0.0075 for the video. It's the egress/outbound traffic charges of the CDN that blow up the numbers. πŸ€”

Collapse
 
harveyhalwin profile image
Heinek Halwin

really ? I'm using aws too. But i'm being charged almost nothing. I believe, the first 1 TB is free or something right ?

Thread Thread
 
codegabru profile image
codegabru

On the free tier they give 5GB S3 storage and 50GB data out on the CloudFront CDN. Then CloudFront pricing spirals out of control for our case at almost ~ 0.05/GB data out. We are def missing something - this might not even be the right way to do it. πŸ˜…

Thread Thread
 
harveyhalwin profile image
Heinek Halwin

I looked into how Netflix manages their content delivery and found this article linked down below. In short, they built their own CDN to lower down the costs. That's what we were missing.

medium.com/refraction-tech-everyth...

Thread Thread
 
codegabru profile image
codegabru

πŸ‘πŸ»πŸ‘πŸ» OpenConnect CDN. So turns out that it actually costs this high to serve video using CDN - unless you build one yourself. πŸ˜›

Collapse
 
ben profile image
Ben Halpern

I imagine there are "enterprise contracts" for such things which don't reflect any pricing you can see publicly, but also.... they lose money.

YouTube lost SO MUCH MONEY early on, and this was a big part of needing to sell to a company capable of losing money for a while. And then they develop the in-house scale to figure it out.

Collapse
 
codegabru profile image
codegabru

Right. Maybe the β€˜economics of scale’ comes into play eventually.

Collapse
 
drbearhands profile image
DrBearhands

That's not exactly what is going on there.

Many companies operate at a loss in hopes of becoming a monopoly, then they start finding ways of extorting money out of people when there's no more competition.

On a more practical note, have you tried downsizing and re-encoding?