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:
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.
Next.js
(if you also want to build a Next.js
application; otherwise, you can just fork and clone this repository to test it out).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.
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).
The setup is simple: we have a Next.js
frontend, our server from DigitalOcean, and clients (us) accessing it.
To explain further:
Here’s a diagram to better understand the flow:
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.
Next.js
application on a DigitalOcean DropletThe 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.
In the next step, we will create a basic $12 droplet to host our application.
Once the Droplet is created, connect to it using the command ssh root@ipaddress
, and then run the following commands to get everything ready:
Next.js
application running on our Droplet, we need to configure Nginx, and that can be done using the commands below:If Nginx is configured correctly, when you run the sudo nginx -t
command, you will see the following output:
npm install -g pm2
, and then use the commands below to run the application with PM2: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.
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:
With this, you now have better traffic management, improved response times, SSL termination and health monitoring.
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.
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.
To benchmark, we will use the following metrics:
sysbench
).fio
).speedtest-cli
).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:
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.
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:
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.
speedtest-cli
)This tests upload/download speeds and latency for video streaming.
To do the network speed test, we run the following commands:
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.
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:
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.
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.
Our benchmarking results show the significant performance improvements when upgrading from a basic to a premium Droplet. The premium Droplet shows:
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.
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!