Joystream / orion

Atlas backend
GNU General Public License v3.0
7 stars 15 forks source link

Automatically extract user location from request #291

Open kdembler opened 8 months ago

kdembler commented 8 months ago

Orion currently returns sorted asset URLs whenever user requests data object info. That sorting is done based on geographical distance between the user and the target distribution node. This is done to ensure that the closest node is used and the user gets the best performing node for them possible.

However, this currently requires the user to explicitly provide their coordinates via x-client-loc header: https://github.com/Joystream/orion/blob/05fb302f6e0560dee10e52a77b071603109ff07c/src/server-extension/resolvers/AssetsResolver/index.ts#L178-L191

That in turn requires Atlas to fetch that location from a service and forward it to Orion. I don't think that makes much sense. Instead, Orion could just use user's IP that it knows anyway from their request and extract location from that. There are few ways that can be done, either using local DB or an external service (for example the same Cloudflare Worker that Atlas currently uses).

The upside is that Orion will always have location data, even if user didn't provide it. With the current approach I guess it may be possible that some initial requests to Orion from Atlas will not include location data because it was not fetched yet. This is important for people being sent a link to a specific video for example.

One downside that I guess comes from that is that the user doesn't have an option to override that location, but I'm almost 100% sure that nobody used that feature in Atlas anyway so I don't think it hurts to lost that option.

One potential complication: if the location comes from the user, it's resolved only once and then kept cached in their local storage so it's not needed to resolve it every time users requests an asset. If we move that to Orion, we should most likely introduce some cache based on IP or user session