On-demand builders request lifecycle with Edge handler and rewrite rules

Hey everybody,

After reading trough the announcement blogpost and the RFC discussion about On-demand builders i understand it’s mechanics and the reasoning behind it.
Where i struggle is it’s position in Netlify’s request lifecycle, more specically if i have a _redirect file and an egde handler plus an on-demand builder function, all acting at the same url, then what is the order of the execution each of these components?

A good example might be:
I have a bookstore website with multiple language support, and edge handler can take care of serving the german content to a browser visiting from Germany, but then I have also books wich are less popular, so i can have an on-demand builder to build those book pages only when they are visited. On top of that i have a _redirects file in which redirects from an old book url to this new url, where i have the geolocation using edge handlers, and certain book urls are generated on-demand?

Is this the order of execution, when user visits an old book link?

  1. _redirect rule gets triggered, user gets navigated from the old url to the new book url
  2. edge handler gets triggered user gets navigates to the german version of the site, still on new book url
  3. On-demand builder gets triggered, since this is as rarely visited book, the page gets generated on demand
  4. User sees the book page, in german.

Also if anybody can point me the right direction about Netlify request flow (request comes in response gets out), i was hoping to have a clear overview on what is actually happens during request processing. I was going trough the docs but nothing seemed to explain this.

Hey @zltnvrs! I’ll answer based on prior knowledge however, if this doesn’t align with your expectations or observations, I’ll be more than happy to seek a bit more knowledge from the wider team. And, you’re right – from a “how is a request handled” standpoint, our docs don’t cover it. It could make for an interesting blog post, mind you. Definitely something for me to consider!

So, long and short – your proposed order of execution aligns perfectly with what I depict… under one condition.

Once our infrastructure sees a request, we’ll parse your redirects file (we do this for every asset or page, on every request) for a matching rule. We read this file top to bottom, too. Then, if we find a matching rule, we’ll read the file again as we’re making a new request, like this.

Basically – you’ll want to make sure that redirects are above edge handlers in your file, if you want redirects to be executed before edge handlers.

So, we’ve: made a request and redirected, then made a subsequent request and executed an edge handler; at this point, we’ll respond with the page, asset, function, builder, et cetera.

Hopefully this helps!

1 Like