Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,111 members, 7,818,316 topics. Date: Sunday, 05 May 2024 at 12:28 PM

What's Your Take On CDN? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / What's Your Take On CDN? (760 Views)

(2) (3) (4)

(1) (Reply) (Go Down)

What's Your Take On CDN? by Kelvin30286063(m): 9:02am On Apr 29, 2020
I own a social media website called Zealnut.

As my website grows and more users come in with contents like videos and images, I suddenly finds myself dealing with a lagging website. Not that it's very slow at an unbearable rate but I feel its slower than before and from experience I know it will only get worse the more users I get.

Now the issue is I tried to patch my content through a content delivery network (specifically cloudflare) and I got a better result but its undeniable that cloudflare sometimes goes offline then it renders your website offline too.

I'm thinking of the best way to optimize heavy images and videos without using a CDN. I have tried compression a few times but there is a limit to how hard you can compress a file if you don't want to break it.

Gurus in the house, please come to my aid, how can I best optimize my website media contents?

I'm also open to other suggestions aside CDN
Re: What's Your Take On CDN? by Karleb(m): 10:44am On Apr 29, 2020
Do you store these media files on the database or on a local file?
Re: What's Your Take On CDN? by Kelvin30286063(m): 12:04pm On Apr 29, 2020
Karleb:
Do you store these media files on the database or on a local file?
They are stored directly in the database and called from the database on request. I use cache to reduce the process but cache is only doing little from what's happening
Re: What's Your Take On CDN? by Karleb(m): 12:36pm On Apr 29, 2020
Kelvin30286063:

They are stored directly in the database and called from the database on request. I use cache to reduce the process but cache is only doing little from what's happening

Media files no matter how small the size are not meant for the database. Create a separate local or cloud storage for it. Store only the media file path in the database.

I strongly believe this is responsible for the slowness.

1 Like

Re: What's Your Take On CDN? by olarid01: 2:30pm On Apr 29, 2020
Karleb:


Media files no matter how small the size are not meant for the database. Create a separate local or cloud storage for it. Store only the media file path in the database.

I strongly believe this is responsible for the slowness.

This is definitely true. It is a very bad approach to store media files on database directly.
Re: What's Your Take On CDN? by Presh900(m): 7:18pm On Apr 29, 2020
Kelvin30286063:

They are stored directly in the database and called from the database on request. I use cache to reduce the process but cache is only doing little from what's happening
How can you store media files in database??
Re: What's Your Take On CDN? by Kelvin30286063(m): 7:23pm On Apr 29, 2020
Presh900:

How can you store media files in database??
I'm fixing that now, thank you
Re: What's Your Take On CDN? by Presh900(m): 7:25pm On Apr 29, 2020
Kelvin30286063:

I'm fixing that now, thank you
Good. Media files shouldn't ever be stored on database due to many factors,unreliability, lag,etc
Re: What's Your Take On CDN? by LSarcastic: 8:20pm On Apr 29, 2020
Kelvin30286063:
I own a social media website called Zealnut.

As my website grows and more users come in with contents like videos and images, I suddenly finds myself dealing with a lagging website. Not that it's very slow at an unbearable rate but I feel its slower than before and from experience I know it will only get worse the more users I get.

Now the issue is I tried to patch my content through a content delivery network (specifically cloudflare) and I got a better result but its undeniable that cloudflare sometimes goes offline then it renders your website offline too.

I'm thinking of the best way to optimize heavy images and videos without using a CDN. I have tried compression a few times but there is a limit to how hard you can compress a file if you don't want to break it.

Gurus in the house, please come to my aid, how can I best optimize my website media contents?

I'm also open to other suggestions aside CDN

For the record, media files aren't actually stored on the database. The only thing being stored is the path to the files. Whether you use a CDN or not, a file can never be stored on a database only its path. A database only contains text and nothing else. Google this for more clarification.

There are two ways web developers work with storage of media files:
1. On host: You write your code that ensures that whenever a file is uploaded, it is being stored within your code directory. It might be a URL path like so: "/media/<filename>". This way, if your host gives you an allocation of 20 GB, for each file you upload, it eats out of your storage space. The advantages to this is that you don't have to spend money on a CDN. The disadvantages are much in that, it quickly consumes your bandwidth and your website becomes slower with each upload. That's why you see websites being very slow after staying a few months. It is also not cost effective in the long run. Because you would have to upgrade your web hosting plans to get more space to store your files.

2. Using a CDN: This is the most preferred way of storing files since it reduces your chances of you having to upscale your hosting plans. It works this way: you buy storage plans from a CDN platform and then follow their guide to configure your code so that whenever you upload files, it's being stored on their server rather than that of your host. This way, your files will have a path like so: https://<your website name>.<CDN website>.com/<filename>. If you use cloudflare, you'll have something like this: https://zealnut.cloudflare.com/cup.jpg. CDN makes your website load faster and you almost never have to worry about up scaling your hosting plans. For those of you that uses traditional PHP hosts, you get to have your high storage from your host and additional storage from the CDN. The only thing you store on your hosts is just your source code which shouldn't be up to 10 MB for a pretty optimised website.


Personally, I'll advise you use Amazon S3. I've never had outage issues since I've been using it and it is so cheap, you'll probably credit my bank account after trying it out. For a bit more understanding, check out my website https://www.bonychicken.com. Check out the source code. See the paths of the media files.

I built it with Django, hosted it on PythonAnywhere and used Amazon S3 as a CDN. I only hosted the media file there. My static files are on the host, to ensure that I can work faster whenever I git pull stuff.

In addition, looking at my website, you'll see something I'll advice you ton take seriously: Lazy loading. If you want, I'll share you the code for implementing the lazy loading. It ensures that images are not loaded until you scroll to the position where it is located. This means if you have a page where many pictures are, the page won't take years to load since the browser will only pull the source code and ignore images. This saves tens of seconds.

I hope this helped smiley

2 Likes

Re: What's Your Take On CDN? by LSarcastic: 8:22pm On Apr 29, 2020
Presh900:

How can you store media files in database??
It's impossible, check my answer above
Re: What's Your Take On CDN? by codekobo: 10:43pm On Apr 29, 2020
LSarcastic:

It's impossible, check my answer above
No it's not, you store the contents of the file as a blob.

You can check https://stackoverflow.com/questions/1636877/how-can-i-store-and-retrieve-images-from-a-mysql-database-using-php
But like others have said this should never be done on any serious application

2 Likes

Re: What's Your Take On CDN? by LSarcastic: 3:11am On Apr 30, 2020
codekobo:

No it's not, you store the contents of the file as a blob.

You can check https://stackoverflow.com/questions/1636877/how-can-i-store-and-retrieve-images-from-a-mysql-database-using-php
But like others have said this should never be done on any serious application

Yeah, you're right. But that would be plain silly.
Re: What's Your Take On CDN? by ClintonNzedimma(m): 6:53pm On Apr 30, 2020
storing static files in database?, I advise you, re engineer your system
Re: What's Your Take On CDN? by Kelvin30286063(m): 5:13am On May 01, 2020
ClintonNzedimma:
storing static files in database?, I advise you, re engineer your system
They are not stored in database. They are stored in folders in an external media storage now

(1) (Reply)

What Job Were You Able To Get With The IT Skill You Have Acquired? / PROLEARN (online Learning Management System) / Nairalanders Pls Help..i Just Finished Creating An App Buh..(pics)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 37
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.