Both mechanisms are valid. In fact, we tried both of them in our two products. Each of them has its pros and cons.
It is supposed: the main server serves the web interface. Allows you to have two servers named main.com and remote.com .
Key factors to consider:
Resource Sharing ( CORS ) . The easiest way to check is the big problem, do you need to support IE <= 9. Legacy IE does not support XHR2, so downloading an AJAX file is not possible. Popular backups exist (e.g. iframe transport), but each one has its own problems.
Bandwidth If the file is uploaded to main.com first and then to remote.com , then the required bandwidth is doubled. Depending on whether your servers are behind load balancers, the requirement will be different. Downloading directly to remote.com uses bandwidth efficiently.
API response time . If your API does not perform an optimistic update, it needs to wait until the file completely reboots to remote.com before it can respond reliably. In addition, it depends on the RTT between main.com and remote.com .
The number of API domains . It's not a big problem. The web client should indicate which domain to use for which API. However, this relates to the CORS problem above.
Performance . If the web server handles file uploads, it might have a performance problem if the server handles large files (or a large number of files). This may affect other users.
The mechanisms
1. The client boots up to main.com . main.com into remote.com
- CORS: No problem
- Bandwidth: Dual
- Response Time: Double (round trip); normal (optimistic)
- API Domain: One
- Performance: May affect web services.
2. The client boots up to remote.com . remote.com sends information to main.com
- CORS: You have a problem.
- Bandwidth: effective
- Response Time: Effective
- API Domain: Two
- Performance: no problem
3. [EXTRA] Client downloads to main.com . main.com transfers the file to remote.com . remote.com sends the file information back.
- CORS: No problem
- Bandwidth: Dual
- Response time: less than two (streaming).
- API Domain: One
- Performance: Better than Method 1 to improve his memory.
Conclusion
Depending on your use case, you need to use a different mechanism. In our case, we use method 2 (direct download) for our outdated product, because we need to support outdated browsers (IE 7, FF 3). Problems with cross domains constantly pound us in many different cases (for example, when clients are behind proxy servers, etc.).
We use method 1 for our new product. Bandwidth and response time problems are still suitable for normal cases, but when the web server and the remote server are deployed at the continental level, performance is lower. We made many optimizations to make it acceptable, but it is still worse than method 2.
Method 3 is used by me in a side project. It is included here because I consider it a good candidate.
Edit
The difference between streaming (method 3) and reloading (method 1) is basically how the file is stored in main.com . This affects the allocation of resources.
To main.com , the downloaded 2GB file is first saved to main.com and then reloaded to remote.com . main.com should allocate resources for temporary storage of the file (disk space, memory, processor for input-output). In addition, as a sequential process, the total time required to complete the download on remote.com is doubled (it is assumed that the time to download to main.com is equal to the time to download to remote.com ).
For streaming, a file uploaded to main.com is simultaneously uploaded to remote.com . Since main.com uploads a piece of the file to remote.com as soon as it receives the piece, the download processes are blocked, which leads to a reduction in download time (less than two times). In other words, if there is no processing in main.com , then main.com actually a proxy server for remote.com . In addition, since the file is not generally stored on main.com (pieces are usually stored in memory), it does not consume as many resources as it reloads. However, if main.com needs to process the file as a whole, streaming will not bring big benefits.