Tutorial

Scale a Video-on-Demand Platform Using DigitalOcean Droplets

Scale a Video-on-Demand Platform Using DigitalOcean Droplets

Introduction

What does your screen time usually consist of? Work hours, social media, and some binge-watching? Well, in this article, we will dive into the world of binge-watching, providing a comprehensive overview of how OTT (Over-the-Top) platforms function, and guide you through the process of building a video-on-demand application tailored to your needs. Moreover, we will explore how to scale your application using DigitalOcean Droplets, ensuring a seamless and efficient streaming experience for your users.

Building a video-on-demand platform can be a game-changer for content creators, educators, and businesses alike. It offers a unique opportunity to reach a wider audience, increase engagement, and monetize content in a more targeted and effective manner. However, as the demand for high-quality streaming services grows, so does the need for scalable and reliable infrastructure to support it. This is where DigitalOcean Droplets come into play, providing a flexible and cost-effective solution for deploying and managing video-on-demand applications.

By the end of this article, you will have a solid understanding of how to design, deploy, and scale a video-on-demand platform using DigitalOcean Droplets, enabling you to overcome common challenges such as:

  • Ensuring high-quality video streaming without buffering or lag
  • Handling a large volume of concurrent users without downtime
  • Managing storage and bandwidth requirements efficiently
  • Scaling your application to meet growing demand without breaking the bank

Whether you’re a developer looking to build a custom video-on-demand solution or a business owner seeking to expand your online presence, this article will provide you with the knowledge and tools necessary to succeed in the competitive world of online video streaming.

Prerequisites

Before we get started building, let’s understand how streaming platforms like Netflix work. First off, to deliver content to millions of users, they rely on powerful servers. We will also be spinning up our own server using DigitalOcean Droplets.

What are DigitalOcean droplets?

A DigitalOcean Droplet is a Linux-based virtual machine (VM) that runs on DigitalOcean’s cloud infrastructure. Think of it as your own virtual server in the cloud that you can use, either standalone or as part of a larger, cloud-based infrastructure.

Each Droplet is a fully functional server with its own CPU, RAM, and SSD storage. You can choose from various configurations (sizes) based on your needs, from basic 1GB RAM/1 vCPU setups to powerful 32GB RAM/16 vCPU machines. You can easily resize, back up, and manage droplets through DigitalOcean’s control panel or API (which we will see in the later part of the article).

Understanding how our Video-on-Demand application works

The setup is simple: we have a Next.js frontend, our server from DigitalOcean, and clients (us) accessing it.

To explain further:

  1. Users access the application through their browsers or mobile devices.
  2. All requests are handled by a single DigitalOcean droplet.
  3. The droplet runs:
    • A Next.js application serving the frontend and API
    • Video library for storing the uploaded content

Here’s a diagram to better understand the flow:

Architecture Daigram

This setup is simpler than Netflix’s infrastructure, which needs multiple servers across multiple regions to cater to millions of users. In the later sections we will discuss how we can upgrade our droplet to handle more concurrent users and process videos faster.

Deploying a Next.js application on a DigitalOcean Droplet

The video-on-demand platform in this example is built with Next.js and we will show you how you can clone it and host it on a Droplet.

  • Fork and clone the repo from GitHub, then go to Settings and under Deploy keys, add the SSH key that you generated using the command ssh-keygen.

    Image2

  • In the next step, we will create a basic $12 droplet to host our application.
    Image3

  • Once the Droplet is created, connect to it using the command ssh root@ipaddress, and then run the following commands to get everything ready:

# Update and install Node.js
sudo apt update && sudo apt upgrade -y
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs nginx

# Install PM2 for process management
sudo npm install -g pm2
  • Before we can get the Next.js application running on our Droplet, we need to configure Nginx, and that can be done using the commands below:
# Create Nginx config
sudo nano /etc/nginx/sites-available/video-on-demand
  • Add this configuration:
/etc/nginx/sites-available/video-on-demand
server {
    listen 80;
    server_name yourip;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
  • Enable the site:
sudo ln -s /etc/nginx/sites-available/video-on-demand /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl restart nginx

If Nginx is configured correctly, when you run the sudo nginx -t command, you will see the following output:

Image4

  • The next step is to clone the GitHub repository. We copy the SSH link as shown in the image below, and then run the following commands to get it up and running.

Image5

# Set up application
git clone git@github.com:Haimantika/video-on-demand.git
cd frontend
npm install
npm run build
  • The final step is to access the application using the IP address, and for that, we will use PM2. You can install it using the command npm install -g pm2, and then use the commands below to run the application with PM2:
# Start with PM2
cd /var/www/video-on-demand/frontend
pm2 start npm --name "video-on-demand" -- start
pm2 save
pm2 startup

To learn more about deploying Next.js applications on DigitalOcean Droplets, you can follow the tutorial on Deploying a Next.js Application on a DigitalOcean Droplet.

Now that we have our video-on-demand application running on a basic Droplet. Let’s understand how it performs and when you might need to upgrade. One great example of why server configuration is important can be the Mike Tyson vs. Jake Paul fight, where Netflix had issues such as buffering, freezing, and crashes. While uploaded content works differently than live streaming, server configuration is crucial, especially in handling a massive surge in viewership and preventing crashes and buffering issues.

Adding a load balancer

Usually the first step to scaling an application like this is by adding a load balancer. Since it distributes incoming traffic and provides a single entry point for the application, it is easier to scale. To add a load balancer to your droplet, follow the steps mentioned in the tutorial How to Create Regional Load Balancers.

When you have successfully added a load balancer to your Droplet, this is what you will see in your control panel:

Image6

With this, you now have better traffic management, improved response times, SSL termination and health monitoring.

Handling increased uploads with vertical scaling

While a load balancer is great at distributing traffic, you need vertical scaling to handle more uploads and video processing. Vertical scaling means upgrading your existing droplet to a larger size, similar to upgrading your computer’s hardware. This gives higher CPU power for processing uploads, more RAM for handling concurrent requests and faster disk I/O for video storage. Along with it, vertical scaling is better at handling large file uploads and has faster response times for library access.

Let us understand this with examples, and benchmarking our application with a basic droplet vs a premium droplet.

Benchmarking our video-on-demand Application

In this section, we will see how our application performs on different droplet sizes. We will be comparing the performance on two droplets: Regular Intel (1 vCPU/2 GB) price at $12/mo and Premium Intel (2 vCPUs/4 GB) priced at $32/mo.

Here’s what we had before vs what we upgraded to:

To learn how to resize a droplet, you can follow the tutorial on how to resize a droplet for vertical scaling.

Image7

Image8

To benchmark, we will use the following metrics:

  • CPU performance test (sysbench).
  • Disk performance test (fio).
  • Network speed test (speedtest-cli).
  • Concurrent user load test (Apache Benchmark).
  • Time to first byte (TTFB).

CPU performance test (sysbench)

This measures the server’s processing power and efficiency for handling computational tasks.

To test the CPU performance, of the Droplets, we will use the commands:

sudo apt update && sudo apt install -y sysbench
sysbench cpu run --threads=4 --time=30

When comparing both, this is what we got:

Metric Basic Intel ($12) Premium Intel ($32) Improvement
Events per second 413.50 958.68 2.32x
Total events (30s) 12,408 28,766 2.32x
Average latency 9.64ms 4.16ms ~57% faster response time
95th percentile latency 14.21ms 10.27ms 28% better sability
Max latency 22.63ms 33.53ms Higher peak, but avg is better
Thread fairness (stddev) 1.87 115.63 Premium droplet distributes work better

From this we can conclude that the premium droplet is ~2.3x faster in CPU performance, the average response time is 57% lower, which leads to faster performance and it has better stability under high load. Since a video-on-demand application usually handles high traffic and has CPU-intensive tasks (such as video processing), upgrading the Droplet significantly improves the performance.

Disk performance test (fio)

The evaluates storage read/write speeds and IOPS for video upload and storage.

To do a disk performance test, we will use the following commands:

sudo apt install -y fiofio --name=randrw --rw=randrw --bs=4k --size=1G --numjobs=4 --runtime=60s

Here’s how the basic intel and premium intel droplet compares:

Metric Basic Droplet (1 vCPU) Premium Droplet (2 vCPUs) Improvement
Read Speed 21.9 MiB/s (22.9 MB/s) 38.9 MiB/s (40.8 MB/s) ~77% Faster
Write Speed 21.9 MiB/s (22.9 MB/s) 39.0 MiB/s (40.9 MB/s) ~78% Faster
IOPS (Avg) 1414.82 2501.28 ~76.7% Higher
Latency (Avg μs) 9.64 ms 4.16 ms ~57% Lower (Better)
Disk Utilization 32.59% 61.01% More resource utilization in Premium

From the above table, it is clear that the premium intel droplet has better performance for fetching videos, faster at video upload and storage operations and can also handle i/o operations per second, which is ideal for a video-heavy application.

Image9

Image10

Network speed test (speedtest-cli)

This tests upload/download speeds and latency for video streaming.

To do the network speed test, we run the following commands:

sudo apt install -y speedtest-cli
speedtest-cli

When we ran it on a basic intel Droplet and a premium intel Droplet we got the following results:

Metric Basic intel Premium intel Improvement
Ping 3.398 ms 2.019 ms ~40.6% Lower (Better)
Download Speed 1449.83 Mbit/s 4976.82 Mbit/s ~3.4x Faster
Upload Speed 976.40 Mbit/s 1939.47 Mbit/s ~2x Faster

For an application such as video-on-demand, which requires faster content delivery, a premium intel Droplet leads to better results, as it has 3.4x faster download speed , 2x faster upload speed and lower latency.

Concurrent user load test (Apache Benchmark)

The concurrent load test simulates multiple users to measure server’s handling of simultaneous connections.

We did a load test of the application with 100 users, using the following command:

sudo apt install -y apache2-utils
ab -n 1000 -c 100 http://yourdomain.com/video.mp4

We got the below results:

Metric Basic Droplet ($12) Premium Droplet ($32) Improvement
Requests per second 8.06 [#/sec] 3716.82 [#/sec] Massively higher throughput
Time per request (mean) 12402.048 ms 26.905 ms Significantly reduced response time
Time per request (concurrent) 124.020 ms 0.269 ms Handles concurrent requests efficiently
Transfer rate 404.28 KB/sec 1622.48 KB/sec Much faster data delivery
Processing 333 / 11845 / 15185 6 / 14 / 36 Reduced processing time
Waiting 290 / 11706 / 15100 5 / 11 / 35 Minimal wait time for requests

This shows that the premium intel droplet is faster and can handle high loads efficiently, while the basic Intel droplet underperforms with concurrent traffic, making it unsuitable for scaling to more users.

Time to first byte (TTFB)

This is done to measure how quickly the server starts sending data to users.

To test the time to first byte, we will use the command: curl -o /dev/null -s -w "%{time_starttransfer}\\n" http://yourdomain.com/video.mp4.

The TTFB on a basic droplet is 3.5299s while on a premium droplet is 0.8217s. This means, the premium droplet is 4x faster in responding to initial requests.

Conclusion

Our benchmarking results show the significant performance improvements when upgrading from a basic to a premium Droplet. The premium Droplet shows:

  • 2.3x faster CPU performance for video processing.
  • 77% faster disk operations for video storage.
  • 3.4x faster download speeds for content delivery.
  • Better handling of concurrent users.
  • 4x faster initial response times.

These improvements translate to a much better user experience, especially when handling multiple video uploads or serving content to many users simultaneously.

Here are some resources that you can refer to learn more about droplets and video processing:

Continue building with DigitalOcean Gen AI Platform.

About the author(s)

Haimantika Mitra
Haimantika MitraEngineer & Writer
See author profile
Category:
Tutorial

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment
Leave a comment...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.