Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically extract user location from request #291

Open
kdembler opened this issue Jan 10, 2024 · 0 comments
Open

Automatically extract user location from request #291

kdembler opened this issue Jan 10, 2024 · 0 comments

Comments

@kdembler
Copy link
Member

kdembler commented Jan 10, 2024

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:

function getClientLoc(ctx: Context): Coordinates | undefined {
const clientLoc = ctx.req.headers['x-client-loc']
if (typeof clientLoc !== 'string') {
return
}
const [latStr, lonStr] = clientLoc.split(',')
const lat = parseFloat(latStr)
const lon = parseFloat(lonStr)
if (!isValidLat(lat) || !isValidLon(lon)) {
return
}
locationLogger.debug(`Client location resolved: ${JSON.stringify({ lat, lon })}`)
return { lat, lon }
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant