0

I've got a peculiar problem.

Server 1A is a server with witch the users interact. Servers 2B, 2C and 2D store video content.

On a website, a html video tag is placed

<video src="server1adomain.com/videos?video=Gy12C899">

Whenever this content is fetched, a backend script on server 1A determines on which server (2B,2C or 2D) the video is stored and fetches it. Lets say it is on 2B. I do not want to wait for the whole video to be fetched from 2B and stored in 1A server, and only after all that time be send to the user. Instead, I'd like a continuous stream to be flowing from 2B to 1A and to the user simultaneously. That way the user gets the first frames of the video with minimal delay.

What is the standard solution for this problem? cURL seems to be synchronous in terms of first fetching the file 100% and than sending it forwards.

Take a look at this diagram to see what I mean:

enter image description here

sanjihan
  • 5,592
  • 11
  • 54
  • 119
  • 1
    Once 1A determined the location of the video, why don't you render the html so video src=server2bdomain.com/... ? Do not try to stream it through multiple hops. – marekful Jun 28 '18 at 17:50
  • Sure, but the less the user know about internals, the better. I am possibly overreacting here. Also all youtube videos are, from the end user perspective , hosted on the same domain, so this must be possible. This is how video src looks on youtube `src="blob:https://www.youtube.com/a6240956-1cb5-4429-b569-309bad7a13da"` – sanjihan Jun 28 '18 at 17:52
  • You are wrong assuming Youtube pulls all videos from youtube.com. They employ a technique that is used by many other streaming platforms. Check the network tab in developer tools when a vid is playing. The content is fetched in chunks at intervals and the domain the chunks are fetched from is not youtube.com but e.g. `https://r3---sn-aigl6n7d.googlevideo.com/videoplayback?c=WEB&requiressl=ye...`. This clearly uses a CDN and this is what you should do as well unless you want to implement your own CDN . – marekful Jun 28 '18 at 20:02
  • Oh, you are correct. Sorry about that. I'd still like to hide the location of the storage. Any way to stream it though 1 hop? I found this q&a https://stackoverflow.com/questions/38417350/php-curl-realtime-proxy-stream-file#answer-38418060. It does download the video. But unfortunately I cannot use this file.php as `src` attribute in the html video tag. – sanjihan Jun 28 '18 at 20:18
  • Your concern is that a user should not be able to fetch the content by examining the video src. The technique to pull content in chunks is rather complicated but the point that is important for you is that the requests are signed so they cannot be replayed. The same request with the same signature won't work for a repeated attempt. This likely includes current timestamp in the generation of the signature. – marekful Jun 28 '18 at 20:24
  • Thanks for taking your time. What you mentioned is a whole new fascinating topic, that I'd like to explore someday. About my current issues.. I do not mind users fetching video. I'd only like to obscure how my backend is created. Namely, hide the machines I use for "CDN". – sanjihan Jun 28 '18 at 21:33

1 Answers1

0

This is mostly comment but space is limited in the comments section.

but the less the user know about internals, the better.

Why? If you can't articulate your requirements (when they seem very unusual) then its rather hard to recommend a solution.

all youtube videos are, ... hosted on the same domain, so this must be possible

Of course its possible but I am quite confident that youtube do not achieve this using the architecture you describe. And even if they served all the content from the URLs with the same vhost, it would not be implemented as you describe. The (obvious) solution to supporting such a service would be a reverse proxy fronting asymmetric hosts acting as an HTTP router.

cURL seems to be synchronous in terms of first fetching the file 100%

Only if you use the default settings. Leaving aside the possibility of carrying out multiple RANGE requests using Curl, If you specify the CURLOPT_READFUNCTION option you can read a chunk at a time from the backend and send it to the client.

symcbean
  • 47,736
  • 6
  • 59
  • 94