https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:08 PM
    one thing i had in mind was sending ppl to "local" servers; i.e. near their closest cf-POP. i hope this will be possible with snippets πŸ˜„
  • d

    dave

    05/24/2023, 5:28 PM
    Is your API HTTP already?
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:31 PM
    yea
  • d

    dave

    05/24/2023, 5:35 PM
    you can already do multiple fetches in parallel and just race to the first one that completes.
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:35 PM
    hmm... doesn't seem like an elegant solution.
  • d

    dave

    05/24/2023, 5:35 PM
    sure it is πŸ˜›
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:36 PM
    if i have lets say 5 servers then i get 5x the traffic with this method
  • s

    Skye

    05/24/2023, 5:36 PM
    One thing to note is that snippets can only make 1 subrequest, as Kian said
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:37 PM
    yea, basically just "forwarding" the request somewhere, right?
  • s

    Skye

    05/24/2023, 5:37 PM
    Correct
  • d

    dave

    05/24/2023, 5:37 PM
    Sure, but you can cache the result too if it's problem.
  • s

    Skye

    05/24/2023, 5:37 PM
    You could use
    request.cf.country
    or
    request.cf.colo
    to try and work out where the nearest server is - and fetch that, but if one is offline, there's not much you can do
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:38 PM
    depends on what one wants to accomplish.
  • d

    dave

    05/24/2023, 5:38 PM
    It's really nice since you can do "advanced" ish load balancing too if want. e.g. can see the round-trip latency by doing:
    Copy code
    curl -s "https://untrusted.files.ai.moda/api/v1.0.0-alpha/ping" | jq
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:39 PM
    if i, lets say want to build some kind of "low-latency" storage for small files, that is kinda guaranteed to have sub <50-60 ms latency, i could make that with less (or no) js on the user side, while still being able to serve the data quickly.
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:40 PM
    what do you mean with that?
  • d

    dave

    05/24/2023, 5:40 PM
    Copy code
    https://untrusted.files.ai.moda/api/v1.0.0-alpha/url/generate_one_time
    ^ we have a similar ish use-case, and made this to return the endpoint with the estimated lowest latency for the user.
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:41 PM
    ahhh πŸ™‚
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:41 PM
    basically just a request to where the client should then upload to. so same thing accomplished, just not intransparent to the user
  • d

    dave

    05/24/2023, 5:41 PM
    sure it can be
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:42 PM
    uh, nearest datacenter hit is london?
  • d

    dave

    05/24/2023, 5:43 PM
    that sounds right, since that uses an S3 backend with buckets in Frankfurt, Ireland, London, Montreal, San Jose, and Virginia.
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:43 PM
    well, then from austria it should have hit frankfurt πŸ˜› πŸ˜‰
  • d

    dave

    05/24/2023, 5:44 PM
    if it's <100MB, you can just accept the request data body directly in the Worker and POST it to an endpoint elsewhere without needing to make the client wait.
  • d

    dave

    05/24/2023, 5:45 PM
    ah so this crappy S3 provider has terrible uptime, and their Frankfurt server has crazy reliability issues (hours of downtime per month). That's why this Worker is really nice, because it actually checks if the S3 endpoint is working or not.
  • d

    dave

    05/24/2023, 5:46 PM
    (off-topic but are only using this unreliable S3 provider temporarily mainly because of the lack of per-bucket API tokens for R2.)
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:47 PM
    ahhh πŸ™‚ thanks for the insight, always interresting to hear what others are building.
  • d

    dave

    05/24/2023, 5:47 PM
    Will your users be using a browser, or is this going to be used by another backend?
  • u

    𝓣𝓸𝓫𝓲

    05/24/2023, 5:49 PM
    mainly browser.
  • d

    dave

    05/24/2023, 5:51 PM
    we do a lot of preloading on our website. e.g. we have this at the bottom of our head tags:
    Copy code
    html
    <link fetchpriority="low" rel="preload" href="/geolocation.json" as="fetch" crossorigin="anonymous" />
    That way when we fetch
    /geolocation.json
    later, it's already loaded.
1...249124922493...2509Latest